template: Make edit link for new templates ensure the page is located under toplevel...
[ikiwiki] / IkiWiki / Plugin / recentchangesdiff.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::recentchangesdiff;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 my $maxlines=200;
9
10 sub import { #{{{
11         hook(type => "getsetup", id => "recentchangesdiff",
12                 call => \&getsetup);
13         hook(type => "pagetemplate", id => "recentchangesdiff",
14                 call => \&pagetemplate);
15 } #}}}
16
17 sub getsetup () { #{{{
18         return 
19                 plugin => {
20                         safe => 1,
21                         rebuild => 1,
22                 },
23 } #}}}
24
25 sub pagetemplate (@) { #{{{
26         my %params=@_;
27         my $template=$params{template};
28         if ($config{rcs} && exists $params{rev} && length $params{rev} &&
29             $template->query(name => "diff")) {
30                 my @lines=IkiWiki::rcs_diff($params{rev});
31                 if (@lines) {
32                         my $diff;
33                         if (@lines > $maxlines) {
34                                 # only include so many lines of diff
35                                 $diff=join("", @lines[0..($maxlines-1)])."\n".
36                                         gettext("(Diff truncated)");
37                         }
38                         else {
39                                 $diff=join("", @lines);
40                         }
41                         # escape links and preprocessor stuff
42                         $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
43                         $template->param(diff => $diff);
44                 }
45         }
46 } #}}}
47
48 1