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,
16 hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
17 hook(type => "htmlize", id => "_change", call => \&htmlize);
18 # Load goto to fix up links from recentchanges
19 IkiWiki::loadplugin("goto");
28 recentchangespage => {
30 example => "recentchanges",
31 description => "name of the recentchanges page",
38 description => "number of changes to track",
45 $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
46 $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
53 foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
54 $seen{store($change, $config{recentchangespage})}=1;
57 # delete old and excess changes
58 foreach my $page (keys %pagesources) {
59 if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) {
60 unlink($config{srcdir}.'/'.$pagesources{$page});
65 # Enable the recentchanges link on wiki pages.
68 my $page=$params{page};
70 if (defined $config{recentchangespage} && $config{rcs} &&
71 $page ne $config{recentchangespage}) {
72 return htmllink($page, $page, $config{recentchangespage},
73 linktext => gettext("RecentChanges"));
77 # Backwards compatability for templates still using
79 sub pagetemplate (@) {
81 my $template=$params{template};
82 my $page=$params{page};
84 if (defined $config{recentchangespage} && $config{rcs} &&
85 $template->query(name => "recentchangesurl") &&
86 $page ne $config{recentchangespage}) {
87 $template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
88 $template->param(have_actions => 1);
92 # Pages with extension _change have plain html markup, pass through.
95 return $params{content};
101 my $page="$config{recentchangespage}/change_".titlepage($change->{rev});
103 # Optimisation to avoid re-writing pages. Assumes commits never
104 # change (or that any changes are not important).
105 return $page if exists $pagesources{$page} && ! $config{rebuild};
107 # Limit pages to first 10, and add links to the changed pages.
108 my $is_excess = exists $change->{pages}[10];
109 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
112 if (length $config{cgiurl}) {
113 $_->{link} = "<a href=\"".
118 "\" rel=\"nofollow\">".
119 pagetitle($_->{page}).
123 $_->{link} = pagetitle($_->{page});
125 $_->{baseurl}="$config{url}/" if length $config{url};
128 } @{$change->{pages}}
130 push @{$change->{pages}}, { link => '...' } if $is_excess;
132 # See if the committer is an openid.
133 $change->{author}=$change->{user};
134 my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
135 if (defined $oiduser) {
136 $change->{authorurl}=$change->{user};
137 $change->{user}=$oiduser;
139 elsif (length $config{cgiurl}) {
140 $change->{authorurl} = IkiWiki::cgiurl(
142 page => IkiWiki::userpage($change->{author}),
146 if (ref $change->{message}) {
147 foreach my $field (@{$change->{message}}) {
148 if (exists $field->{line}) {
150 $field->{line} = encode_entities($field->{line});
151 # escape links and preprocessor stuff
152 $field->{line} = encode_entities($field->{line}, '\[\]');
157 # Fill out a template with the change info.
158 my $template=template("change.tmpl", blind_cache => 1);
161 commitdate => displaytime($change->{when}, "%X %x"),
162 wikiname => $config{wikiname},
165 $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev}))
166 if exists $config{url};
168 IkiWiki::run_hooks(pagetemplate => sub {
169 shift->(page => $page, destpage => $page,
170 template => $template, rev => $change->{rev});
173 my $file=$page."._change";
174 writefile($file, $config{srcdir}, $template->output);
175 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";