]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/recentchanges.pm
Patch for anchor-based change permalinks in recent changes feed
[ikiwiki.git] / IkiWiki / Plugin / recentchanges.pm
index 6ab4f9d033a66e2ce57ab83b5a26b9a429811b91..d0e4176ffb862c6c8dc554bc5047124f82661c41 100644 (file)
@@ -4,6 +4,7 @@ package IkiWiki::Plugin::recentchanges;
 use warnings;
 use strict;
 use IkiWiki 2.00;
+use Encode;
 
 sub import { #{{{
        hook(type => "getsetup", id => "recentchanges", call => \&getsetup);
@@ -16,16 +17,20 @@ sub import { #{{{
 
 sub getsetup () { #{{{
        return
+               plugin => {
+                       safe => 1,
+                       rebuild => 1,
+               },
                recentchangespage => {
                        type => "string",
-                       default => "recentchanges",
+                       example => "recentchanges",
                        description => "name of the recentchanges page",
                        safe => 1,
                        rebuild => 1,
                },
                recentchangesnum => {
                        type => "integer",
-                       default => 100,
+                       example => 100,
                        description => "number of changes to track",
                        safe => 1,
                        rebuild => 0,
@@ -82,7 +87,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");
                }
@@ -99,7 +104,7 @@ sub cgi ($) { #{{{
                                "</p>");
                }
                else {
-                       IkiWiki::redirect($cgi, $config{url}.IkiWiki::beautify_urlpath("/".htmlpage($link)));
+                       IkiWiki::redirect($cgi, urlto($link, undef, 1));
                }
 
                exit;
@@ -109,7 +114,9 @@ sub cgi ($) { #{{{
 sub store ($$$) { #{{{
        my $change=shift;
 
-       my $page="$config{recentchangespage}/change_".IkiWiki::titlepage($change->{rev});
+       my $page="$config{recentchangespage}/change_".titlepage($change->{rev});
+       my $baseurl = IkiWiki::baseurl();
+       my $permalink="$baseurl$config{recentchangespage}/#change-".titlepage($change->{rev});
 
        # Optimisation to avoid re-writing pages. Assumes commits never
        # change (or that any changes are not important).
@@ -127,11 +134,11 @@ sub store ($$$) { #{{{
                                                page => $_->{page}
                                        ).
                                        "\">".
-                                       IkiWiki::pagetitle($_->{page}).
+                                       pagetitle($_->{page}).
                                        "</a>"
                        }
                        else {
-                               $_->{link} = IkiWiki::pagetitle($_->{page});
+                               $_->{link} = pagetitle($_->{page});
                        }
                        $_->{baseurl}="$config{url}/" if length $config{url};
 
@@ -168,7 +175,9 @@ sub store ($$$) { #{{{
        $template->param(
                %$change,
                commitdate => displaytime($change->{when}, "%X %x"),
+               commitdate_raw => scalar localtime($change->{when}),
                wikiname => $config{wikiname},
+               permalink => $permalink,
        );
        IkiWiki::run_hooks(pagetemplate => sub {
                shift->(page => $page, destpage => $page,