2 package IkiWiki::Plugin::recentchanges;
11 hook(type => "getsetup", id => "recentchanges", call => \&getsetup);
12 hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
13 hook(type => "refresh", id => "recentchanges", call => \&refresh);
14 hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
15 hook(type => "htmlize", id => "_change", call => \&htmlize);
16 # Load goto to fix up links from recentchanges
17 IkiWiki::loadplugin("goto");
27 recentchangespage => {
29 example => "recentchanges",
30 description => "name of the recentchanges page",
37 description => "number of changes to track",
44 $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
45 $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
52 foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
53 $seen{store($change, $config{recentchangespage})}=1;
56 # delete old and excess changes
57 foreach my $page (keys %pagesources) {
58 if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) {
59 unlink($config{srcdir}.'/'.$pagesources{$page});
64 # Enable the recentchanges link on wiki pages.
65 sub pagetemplate (@) {
67 my $template=$params{template};
68 my $page=$params{page};
70 if (defined $config{recentchangespage} && $config{rcs} &&
71 $page ne $config{recentchangespage} &&
72 $template->query(name => "recentchangesurl")) {
73 $template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
74 $template->param(have_actions => 1);
78 # Pages with extension _change have plain html markup, pass through.
81 return $params{content};
87 my $page="$config{recentchangespage}/change_".titlepage($change->{rev});
89 # Optimisation to avoid re-writing pages. Assumes commits never
90 # change (or that any changes are not important).
91 return $page if exists $pagesources{$page} && ! $config{rebuild};
93 # Limit pages to first 10, and add links to the changed pages.
94 my $is_excess = exists $change->{pages}[10];
95 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
98 if (length $config{cgiurl}) {
99 $_->{link} = "<a href=\"".
104 "\" rel=\"nofollow\">".
105 pagetitle($_->{page}).
109 $_->{link} = pagetitle($_->{page});
111 $_->{baseurl}="$config{url}/" if length $config{url};
114 } @{$change->{pages}}
116 push @{$change->{pages}}, { link => '...' } if $is_excess;
118 # See if the committer is an openid.
119 $change->{author}=$change->{user};
120 my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
121 if (defined $oiduser) {
122 $change->{authorurl}=$change->{user};
123 $change->{user}=$oiduser;
125 elsif (length $config{cgiurl}) {
126 $change->{authorurl} = IkiWiki::cgiurl(
128 page => IkiWiki::userpage($change->{author}),
132 if (ref $change->{message}) {
133 foreach my $field (@{$change->{message}}) {
134 if (exists $field->{line}) {
136 $field->{line} = encode_entities($field->{line});
137 # escape links and preprocessor stuff
138 $field->{line} = encode_entities($field->{line}, '\[\]');
143 # Fill out a template with the change info.
144 my $template=template("change.tmpl", blind_cache => 1);
147 commitdate => displaytime($change->{when}, "%X %x"),
148 wikiname => $config{wikiname},
151 $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev}))
152 if exists $config{url};
154 IkiWiki::run_hooks(pagetemplate => sub {
155 shift->(page => $page, destpage => $page,
156 template => $template, rev => $change->{rev});
159 my $file=$page."._change";
160 writefile($file, $config{srcdir}, $template->output);
161 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";