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