-sub import { #{{{
- hook(type => "checkconfig", id => "recentchanges",
- call => \&checkconfig);
- hook(type => "needsbuild", id => "recentchanges",
- call => \&needsbuild);
- hook(type => "preprocess", id => "recentchanges",
- call => \&preprocess);
- hook(type => "htmlize", id => "_change",
- call => \&htmlize);
-} #}}}
-
-sub checkconfig () { #{{{
- my @changes=IkiWiki::rcs_recentchanges(100);
- updatechanges("*", "recentchanges", \@changes);
-} #}}}
-
-sub needsbuild () { #{{{
- # TODO
-} #}}}
-
-sub preprocess (@) { #{{{
- my %params=@_;
+sub import {
+ hook(type => "getsetup", id => "recentchanges", call => \&getsetup);
+ hook(type => "checkconfig", id => "recentchanges", call => \&checkconfig);
+ hook(type => "refresh", id => "recentchanges", call => \&refresh);
+ hook(type => "pagetemplate", id => "recentchanges", call => \&pagetemplate);
+ hook(type => "htmlize", id => "_change", call => \&htmlize);
+ hook(type => "cgi", id => "recentchanges", call => \&cgi);
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1,
+ },
+ recentchangespage => {
+ type => "string",
+ example => "recentchanges",
+ description => "name of the recentchanges page",
+ safe => 1,
+ rebuild => 1,
+ },
+ recentchangesnum => {
+ type => "integer",
+ example => 100,
+ description => "number of changes to track",
+ safe => 1,
+ rebuild => 0,
+ },
+}
+
+sub checkconfig () {
+ $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage};
+ $config{recentchangesnum}=100 unless defined $config{recentchangesnum};
+}
+
+sub refresh ($) {
+ my %seen;
+
+ # add new changes
+ foreach my $change (IkiWiki::rcs_recentchanges($config{recentchangesnum})) {
+ $seen{store($change, $config{recentchangespage})}=1;
+ }
+
+ # delete old and excess changes
+ foreach my $page (keys %pagesources) {
+ if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) {
+ unlink($config{srcdir}.'/'.$pagesources{$page});
+ }
+ }
+}