]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/recentchangesdiff.pm
Merge branch 'master' of git://git.ikiwiki.info
[ikiwiki.git] / 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 => "pagetemplate", id => "recentchangesdiff",
12                 call => \&pagetemplate);
13 } #}}}
14
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 } #}}}
37
38 1