2 package IkiWiki::Plugin::recentchanges;
9 hook(type => "refresh", id => "recentchanges",
11 hook(type => "preprocess", id => "recentchanges",
12 call => \&preprocess);
13 hook(type => "htmlize", id => "_change",
17 sub refresh ($) { #{{{
18 my @changes=IkiWiki::rcs_recentchanges(100);
19 updatechanges("*", "recentchanges", \@changes);
22 sub preprocess (@) { #{{{
30 # Pages with extension _change have plain html markup, pass through.
31 sub htmlize (@) { #{{{
33 return $params{content};
40 my $page="$subdir/change_".IkiWiki::titlepage($change->{rev});
42 # Optimisation to avoid re-writing pages. Assumes commits never
43 # change (or that any changes are not important).
44 return if exists $pagesources{$page} && ! $config{rebuild};
46 # Limit pages to first 10, and add links to the changed pages.
47 my $is_excess = exists $change->{pages}[10];
48 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
51 if (length $config{url}) {
52 $_->{link} = "<a href=\"$config{url}/".
53 urlto($_->{page},"")."\">".
54 IkiWiki::pagetitle($_->{page})."</a>";
57 $_->{link} = IkiWiki::pagetitle($_->{page});
62 push @{$change->{pages}}, { link => '...' } if $is_excess;
64 # See if the committer is an openid.
65 my $oiduser=IkiWiki::openiduser($change->{user});
66 if (defined $oiduser) {
67 $change->{authorurl}=$change->{user};
68 $change->{user}=$oiduser;
70 elsif (length $config{url}) {
71 $change->{authorurl}="$config{url}/".
72 (length $config{userdir} ? "$config{userdir}/" : "").
76 # escape wikilinks and preprocessor stuff in commit messages
77 if (ref $change->{message}) {
78 foreach my $field (@{$change->{message}}) {
79 if (exists $field->{line}) {
80 $field->{line} =~ s/(?<!\\)\[\[/\\\[\[/g;
85 # Fill out a template with the change info.
86 my $template=template("change.tmpl", blind_cache => 1);
89 commitdate => displaytime($change->{when}, "%X %x"),
90 wikiname => $config{wikiname},
92 $template->param(baseurl => "$config{url}/") if length $config{url};
93 IkiWiki::run_hooks(pagetemplate => sub {
94 shift->(page => $page, destpage => $page, template => $template);
97 my $file=$page."._change";
98 writefile($file, $config{srcdir}, $template->output);
99 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";
102 sub updatechanges ($$) { #{{{
105 my @changes=@{shift()};
107 foreach my $change (@changes) {
108 store($change, $subdir);