]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/recentchangesdiff.pm
po(refreshpot): define the input charset before read()'ing
[git.ikiwiki.info.git] / IkiWiki / Plugin / recentchangesdiff.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::recentchangesdiff;
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
8 my $maxlines=200;
10 sub import { #{{{
11         hook(type => "getsetup", id => "recentchangesdiff",
12                 call => \&getsetup);
13         hook(type => "pagetemplate", id => "recentchangesdiff",
14                 call => \&pagetemplate);
15 } #}}}
17 sub getsetup () { #{{{
18         return 
19                 plugin => {
20                         safe => 1,
21                         rebuild => 1,
22                 },
23 } #}}}
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 } #}}}
48 1