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")) {
|
2010-12-30 00:58:49 +01:00
|
|
|
my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
|
2008-03-12 20:45:10 +01:00
|
|
|
if (@lines) {
|
|
|
|
my $diff;
|
2012-01-23 23:36:33 +01:00
|
|
|
my $trunc=0;
|
2008-03-12 20:45:10 +01:00
|
|
|
if (@lines > $maxlines) {
|
2012-01-23 23:36:33 +01:00
|
|
|
$diff=join("", @lines[0..($maxlines-1)]);
|
|
|
|
$trunc=1;
|
2008-03-12 20:45:10 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$diff=join("", @lines);
|
|
|
|
}
|
2012-01-23 23:36:33 +01:00
|
|
|
if (length $diff > 102400) {
|
|
|
|
$diff=substr($diff, 0, 10240);
|
|
|
|
$trunc=1;
|
|
|
|
}
|
|
|
|
if ($trunc) {
|
|
|
|
$diff.="\n".gettext("(Diff truncated)");
|
|
|
|
}
|
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
|