X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=IkiWiki%2FPlugin%2Frecentchanges.pm;h=ef108b3f00d4f031ef3ca3b0f1bab228f0dce279;hb=17b2afe721d5b8fd2468fca56e91fe83bf49be64;hp=8135f9adb3d8071aedb30960952c803a3c95c310;hpb=7b6686ce7061c28eba88610b2ee55e4a0379ff1e;p=ikiwiki.git diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index 8135f9adb..ef108b3f0 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -3,22 +3,47 @@ package IkiWiki::Plugin::recentchanges; use warnings; use strict; -use IkiWiki 2.00; +use IkiWiki 3.00; +use Encode; +use HTML::Entities; -sub import { #{{{ +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 () { #{{{ +sub checkconfig () { $config{recentchangespage}='recentchanges' unless defined $config{recentchangespage}; $config{recentchangesnum}=100 unless defined $config{recentchangesnum}; -} #}}} +} -sub refresh ($) { #{{{ +sub refresh ($) { my %seen; # add new changes @@ -32,27 +57,29 @@ sub refresh ($) { #{{{ unlink($config{srcdir}.'/'.$pagesources{$page}); } } -} #}}} +} # Enable the recentchanges link on wiki pages. -sub pagetemplate (@) { #{{{ +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); } -} #}}} +} # Pages with extension _change have plain html markup, pass through. -sub htmlize (@) { #{{{ +sub htmlize (@) { my %params=@_; return $params{content}; -} #}}} +} -sub cgi ($) { #{{{ +sub cgi ($) { my $cgi=shift; if (defined $cgi->param('do') && $cgi->param('do') eq "recentchanges_link") { # This is a link from a change page to some @@ -61,13 +88,22 @@ 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"); } IkiWiki::loadindex(); + # If the page is internal (like a comment), see if it has a + # permalink. Comments do. + if (IkiWiki::isinternal($page) && + defined $pagestate{$page}{meta}{permalink}) { + IkiWiki::redirect($cgi, + $pagestate{$page}{meta}{permalink}); + exit; + } + my $link=bestlink("", $page); if (! length $link) { print "Content-type: text/html\n\n"; @@ -78,17 +114,17 @@ sub cgi ($) { #{{{ "

"); } else { - IkiWiki::redirect($cgi, $config{url}."/".htmlpage($link)); + IkiWiki::redirect($cgi, urlto($link, undef, 1)); } exit; } } -sub store ($$$) { #{{{ +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 +141,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 +169,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,6 +187,10 @@ 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, rev => $change->{rev}); @@ -159,6 +201,6 @@ sub store ($$$) { #{{{ utime $change->{when}, $change->{when}, "$config{srcdir}/$file"; return $page; -} #}}} +} 1