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});
66 push @{$change->{pages}}, { link => '...' } if $is_excess;
68 # See if the committer is an openid.
69 $change->{author}=$change->{user};
70 my $oiduser=IkiWiki::openiduser($change->{user});
71 if (defined $oiduser) {
72 $change->{authorurl}=$change->{user};
73 $change->{user}=$oiduser;
75 elsif (length $config{url}) {
76 $change->{authorurl}="$config{url}/".
77 (length $config{userdir} ? "$config{userdir}/" : "").
81 # escape wikilinks and preprocessor stuff in commit messages
82 if (ref $change->{message}) {
83 foreach my $field (@{$change->{message}}) {
84 if (exists $field->{line}) {
85 $field->{line} =~ s/(?<!\\)\[\[/\\\[\[/g;
90 # Fill out a template with the change info.
91 my $template=template("change.tmpl", blind_cache => 1);
94 commitdate => displaytime($change->{when}, "%X %x"),
95 wikiname => $config{wikiname},
97 $template->param(baseurl => "$config{url}/") if length $config{url};
98 IkiWiki::run_hooks(pagetemplate => sub {
99 shift->(page => $page, destpage => $page, template => $template);
102 my $file=$page."._change";
103 writefile($file, $config{srcdir}, $template->output);
104 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";
109 sub updatechanges ($$) { #{{{
111 my @changes=@{shift()};