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");
26 recentchangespage => {
28 example => "recentchanges",
29 description => "name of the recentchanges page",
36 description => "number of changes to track",
43 $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
44 $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
51 foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
52 $seen{store($change, $config{recentchangespage})}=1;
55 # delete old and excess changes
56 foreach my $page (keys %pagesources) {
57 if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) {
58 unlink($config{srcdir}.'/'.$pagesources{$page});
63 # Enable the recentchanges link.
64 sub pagetemplate (@) {
66 my $template=$params{template};
67 my $page=$params{page};
69 if (defined $config{recentchangespage} && $config{rcs} &&
70 $template->query(name => "recentchangesurl") &&
71 $page ne $config{recentchangespage}) {
72 $template->param(recentchangesurl => urlto($config{recentchangespage}, $page));
73 $template->param(have_actions => 1);
77 # Pages with extension _change have plain html markup, pass through.
80 return $params{content};
86 my $page="$config{recentchangespage}/change_".titlepage($change->{rev});
88 # Optimisation to avoid re-writing pages. Assumes commits never
89 # change (or that any changes are not important).
90 return $page if exists $pagesources{$page} && ! $config{rebuild};
92 # Limit pages to first 10, and add links to the changed pages.
93 my $is_excess = exists $change->{pages}[10];
94 delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
97 if (length $config{cgiurl}) {
98 $_->{link} = "<a href=\"".
103 "\" rel=\"nofollow\">".
104 pagetitle($_->{page}).
108 $_->{link} = pagetitle($_->{page});
110 $_->{baseurl}="$config{url}/" if length $config{url};
113 } @{$change->{pages}}
115 push @{$change->{pages}}, { link => '...' } if $is_excess;
117 $change->{author}=$change->{user};
118 my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
119 if (defined $oiduser) {
120 $change->{authorurl}=$change->{user};
121 $change->{user}=defined $change->{nickname} ? $change->{nickname} : $oiduser;
123 elsif (length $config{cgiurl}) {
124 $change->{authorurl} = IkiWiki::cgiurl(
126 page => IkiWiki::userpage($change->{author}),
130 if (ref $change->{message}) {
131 foreach my $field (@{$change->{message}}) {
132 if (exists $field->{line}) {
134 $field->{line} = encode_entities($field->{line});
135 # escape links and preprocessor stuff
136 $field->{line} = encode_entities($field->{line}, '\[\]');
141 # Fill out a template with the change info.
142 my $template=template("change.tmpl", blind_cache => 1);
145 commitdate => displaytime($change->{when}, "%X %x"),
146 wikiname => $config{wikiname},
149 $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev}))
150 if exists $config{url};
152 IkiWiki::run_hooks(pagetemplate => sub {
153 shift->(page => $page, destpage => $page,
154 template => $template, rev => $change->{rev});
157 my $file=$page."._change";
158 writefile($file, $config{srcdir}, $template->output);
159 utime $change->{when}, $change->{when}, "$config{srcdir}/$file";