]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/recentchangesdiff.pm
simplify key determination code
[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 => "pagetemplate", id => "recentchangesdiff",
12                 call => \&pagetemplate);
13 } #}}}
15 sub pagetemplate (@) { #{{{
16         my %params=@_;
17         my $template=$params{template};
18         if ($config{rcs} && exists $params{rev} && length $params{rev} &&
19             $template->query(name => "diff")) {
20                 my @lines=IkiWiki::rcs_diff($params{rev});
21                 if (@lines) {
22                         my $diff;
23                         if (@lines > $maxlines) {
24                                 # only include so many lines of diff
25                                 $diff=join("", @lines[0..($maxlines-1)])."\n".
26                                         gettext("(Diff truncated)");
27                         }
28                         else {
29                                 $diff=join("", @lines);
30                         }
31                         # escape links and preprocessor stuff
32                         $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
33                         $template->param(diff => $diff);
34                 }
35         }
36 } #}}}
38 1