2008-03-03 21:53:34 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::recentchangesdiff;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-11-18 08:43:17 +01:00
|
|
|
use HTML::Entities;
|
2008-03-03 21:53:34 +01:00
|
|
|
|
2008-03-12 20:45:10 +01:00
|
|
|
my $maxlines=200;
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "recentchangesdiff",
|
|
|
|
call => \&getsetup);
|
2008-03-03 21:53:34 +01:00
|
|
|
hook(type => "pagetemplate", id => "recentchangesdiff",
|
|
|
|
call => \&pagetemplate);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-03-03 21:53:34 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 23:20:21 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 23:20:21 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub pagetemplate (@) {
|
2008-03-03 21:53:34 +01:00
|
|
|
my %params=@_;
|
|
|
|
my $template=$params{template};
|
|
|
|
if ($config{rcs} && exists $params{rev} && length $params{rev} &&
|
|
|
|
$template->query(name => "diff")) {
|
2008-03-12 20:45:10 +01:00
|
|
|
my @lines=IkiWiki::rcs_diff($params{rev});
|
|
|
|
if (@lines) {
|
|
|
|
my $diff;
|
|
|
|
if (@lines > $maxlines) {
|
|
|
|
# only include so many lines of diff
|
|
|
|
$diff=join("", @lines[0..($maxlines-1)])."\n".
|
|
|
|
gettext("(Diff truncated)");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$diff=join("", @lines);
|
|
|
|
}
|
2008-11-18 08:48:24 +01:00
|
|
|
# escape html
|
|
|
|
$diff = encode_entities($diff);
|
2008-03-03 21:53:34 +01:00
|
|
|
# escape links and preprocessor stuff
|
2008-11-18 08:43:17 +01:00
|
|
|
$diff = encode_entities($diff, '\[\]');
|
2008-03-03 21:53:34 +01:00
|
|
|
$template->param(diff => $diff);
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-03-03 21:53:34 +01:00
|
|
|
|
|
|
|
1
|