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 => "pageactions", id => "recentchanges", call => \&pageactions);
15 hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
16 hook(type => "htmlize", id => "_change", call => \&htmlize);
17 # Load goto to fix up links from recentchanges
18 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.
67 my $page=$params{page};
69 if (defined $config{recentchangespage} && $config{rcs} &&
70 $page ne $config{recentchangespage}) {
71 return htmllink($page, $page, $config{recentchangespage},
72 gettext("RecentChanges"));
76 # Backwards compatability for templates still using
78 sub pagetemplate (@) {
80 my $template=$params{template};
81 my $page=$params{page};
83 if (defined $config{recentchangespage} && $config{rcs} &&
84 $template->query(name => "recentchangesurl") &&
85 $page ne $config{recentchangespage}) {
86 $template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
87 $template->param(have_actions => 1);
91 # Pages with extension _change have plain html markup, pass through.
94 return $params{content};
100 my $page="$config{recentchangespage}/change_".titlepage($change->{rev});
102 # Optimisation to avoid re-writing pages. Assumes commits never
103 # change (or that any changes are not important).
104 return $page if exists $pagesources{$page} && ! $config{rebuild};
106 # Limit pages to first 10, and add links to the changed pages.
107 my $is_excess = exists $change->{pages}[10];
108 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
111 if (length $config{cgiurl}) {
112 $_->{link} = "<a href=\"".
117 "\" rel=\"nofollow\">".
118 pagetitle($_->{page}).
122 $_->{link} = pagetitle($_->{page});
124 $_->{baseurl}="$config{url}/" if length $config{url};
127 } @{$change->{pages}}
129 push @{$change->{pages}}, { link => '...' } if $is_excess;
131 # See if the committer is an openid.
132 $change->{author}=$change->{user};
133 my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
134 if (defined $oiduser) {
135 $change->{authorurl}=$change->{user};
136 $change->{user}=$oiduser;
138 elsif (length $config{cgiurl}) {
139 $change->{authorurl} = IkiWiki::cgiurl(
141 page => IkiWiki::userpage($change->{author}),
145 if (ref $change->{message}) {
146 foreach my $field (@{$change->{message}}) {
147 if (exists $field->{line}) {
149 $field->{line} = encode_entities($field->{line});
150 # escape links and preprocessor stuff
151 $field->{line} = encode_entities($field->{line}, '\[\]');
156 # Fill out a template with the change info.
157 my $template=template("change.tmpl", blind_cache => 1);
160 commitdate => displaytime($change->{when}, "%X %x"),
161 wikiname => $config{wikiname},
164 $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev}))
165 if exists $config{url};
167 IkiWiki::run_hooks(pagetemplate => sub {
168 shift->(page => $page, destpage => $page,
169 template => $template, rev => $change->{rev});
172 my $file=$page."._change";
173 writefile($file, $config{srcdir}, $template->output);
174 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";