X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/e57749b702137b925064b60120ea22a98965c7d5..cb5aaa3cee8b35d6fc6e88a7449a9477a6587c7a:/IkiWiki/Plugin/recentchanges.pm diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 22f934f2e..4d7023c1c 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -4,8 +4,11 @@ package IkiWiki::Plugin::recentchanges; use warnings; use strict; use IkiWiki 2.00; +use Encode; +use HTML::Entities; 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); @@ -13,6 +16,28 @@ sub import { #{{{ 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}; @@ -28,7 +53,7 @@ sub refresh ($) { #{{{ # delete old and excess changes foreach my $page (keys %pagesources) { - if ($page =~ /\._change$/ && ! $seen{$page}) { + if ($pagesources{$page} =~ /\._change$/ && ! $seen{$page}) { unlink($config{srcdir}.'/'.$pagesources{$page}); } } @@ -39,7 +64,9 @@ sub pagetemplate (@) { #{{{ my %params=@_; my $template=$params{template}; my $page=$params{page}; - if ($config{rcs} && $page ne $config{recentchangespage} && + + if (defined $config{recentchangespage} && $config{rcs} && + $page ne $config{recentchangespage} && $template->query(name => "recentchangesurl")) { $template->param(recentchangesurl => urlto($config{recentchangespage}, $page)); $template->param(have_actions => 1); @@ -61,7 +88,7 @@ sub cgi ($) { #{{{ # page they link to is deleted, or newly created, or # changes for whatever reason. So this CGI handles that # dynamic linking stuff. - my $page=$cgi->param("page"); + my $page=decode_utf8($cgi->param("page")); if (!defined $page) { error("missing page parameter"); } @@ -78,7 +105,7 @@ sub cgi ($) { #{{{ "

"); } else { - IkiWiki::redirect($cgi, $config{url}."/".htmlpage($link)); + IkiWiki::redirect($cgi, urlto($link, undef, 1)); } exit; @@ -88,7 +115,7 @@ sub cgi ($) { #{{{ sub store ($$$) { #{{{ my $change=shift; - my $page="$config{recentchangespage}/change_".IkiWiki::titlepage($change->{rev}); + my $page="$config{recentchangespage}/change_".titlepage($change->{rev}); # Optimisation to avoid re-writing pages. Assumes commits never # change (or that any changes are not important). @@ -105,12 +132,12 @@ sub store ($$$) { #{{{ do => "recentchanges_link", page => $_->{page} ). - "\">". - IkiWiki::pagetitle($_->{page}). + "\" rel=\"nofollow\">". + pagetitle($_->{page}). "" } else { - $_->{link} = IkiWiki::pagetitle($_->{page}); + $_->{link} = pagetitle($_->{page}); } $_->{baseurl}="$config{url}/" if length $config{url}; @@ -133,11 +160,13 @@ sub store ($$$) { #{{{ ); } - # escape wikilinks and preprocessor stuff in commit messages if (ref $change->{message}) { foreach my $field (@{$change->{message}}) { if (exists $field->{line}) { - $field->{line} =~ s/(?{line} = encode_entities($field->{line}); + # escape links and preprocessor stuff + $field->{line} = encode_entities($field->{line}, '\[\]'); } } } @@ -149,8 +178,13 @@ sub store ($$$) { #{{{ commitdate => displaytime($change->{when}, "%X %x"), wikiname => $config{wikiname}, ); + + $template->param(permalink => "$config{url}/$config{recentchangespage}/#change-".titlepage($change->{rev})) + if exists $config{url}; + IkiWiki::run_hooks(pagetemplate => sub { - shift->(page => $page, destpage => $page, template => $template); + shift->(page => $page, destpage => $page, + template => $template, rev => $change->{rev}); }); my $file=$page."._change"; @@ -160,10 +194,4 @@ sub store ($$$) { #{{{ return $page; } #}}} -sub updatechanges ($$) { #{{{ - my $subdir=shift; - my @changes=@{shift()}; - -} #}}} - 1