2 package IkiWiki::Plugin::recentchanges;
9 hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
10 hook(type => "refresh", id => "recentchanges", call => \&refresh);
11 hook(type => "htmlize", id => "_change", call => \&htmlize);
14 sub checkconfig () { #{{{
15 $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
16 $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
19 sub refresh ($) { #{{{
23 foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
24 $seen{store($change, $config{recentchangespage})}=1;
27 # delete old and excess changes
28 foreach my $page (keys %pagesources) {
29 if ($page=~/^\Q$config{recentchangespage}\E\/change_/ && ! $seen{$page}) {
30 unlink($config{srcdir}.'/'.$pagesources{$page});
35 # Pages with extension _change have plain html markup, pass through.
36 sub htmlize (@) { #{{{
38 return $params{content};
41 sub store ($$$) { #{{{
44 my $page="$config{recentchangespage}/change_".IkiWiki::titlepage($change->{rev});
46 # Optimisation to avoid re-writing pages. Assumes commits never
47 # change (or that any changes are not important).
48 return $page if exists $pagesources{$page} && ! $config{rebuild};
50 # Limit pages to first 10, and add links to the changed pages.
51 my $is_excess = exists $change->{pages}[10];
52 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
55 if (length $config{url}) {
56 $_->{link} = "<a href=\"$config{url}/".
57 urlto($_->{page},"")."\">".
58 IkiWiki::pagetitle($_->{page})."</a>";
61 $_->{link} = IkiWiki::pagetitle($_->{page});
63 $_->{baseurl}="$config{url}/" if length $config{url};
68 push @{$change->{pages}}, { link => '...' } if $is_excess;
70 # See if the committer is an openid.
71 $change->{author}=$change->{user};
72 my $oiduser=IkiWiki::openiduser($change->{user});
73 if (defined $oiduser) {
74 $change->{authorurl}=$change->{user};
75 $change->{user}=$oiduser;
77 elsif (length $config{url}) {
78 $change->{authorurl}="$config{url}/".
79 (length $config{userdir} ? "$config{userdir}/" : "").
83 # escape wikilinks and preprocessor stuff in commit messages
84 if (ref $change->{message}) {
85 foreach my $field (@{$change->{message}}) {
86 if (exists $field->{line}) {
87 $field->{line} =~ s/(?<!\\)\[\[/\\\[\[/g;
92 # Fill out a template with the change info.
93 my $template=template("change.tmpl", blind_cache => 1);
96 commitdate => displaytime($change->{when}, "%X %x"),
97 wikiname => $config{wikiname},
99 IkiWiki::run_hooks(pagetemplate => sub {
100 shift->(page => $page, destpage => $page, template => $template);
103 my $file=$page."._change";
104 writefile($file, $config{srcdir}, $template->output);
105 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";
110 sub updatechanges ($$) { #{{{
112 my @changes=@{shift()};