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 {
|
2012-07-19 16:32:02 +02:00
|
|
|
add_underlay("javascript");
|
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);
|
2012-07-19 16:32:02 +02:00
|
|
|
hook(type => "format", id => "recentchangesdiff.pm", call => \&format);
|
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
|
|
|
|
2012-07-19 16:32:02 +02:00
|
|
|
sub format (@) {
|
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
|
|
|
|
# no <body> tag, probably in preview mode
|
|
|
|
$params{content}=include_javascript(undef).$params{content};
|
|
|
|
}
|
|
|
|
return $params{content};
|
|
|
|
}
|
|
|
|
|
|
|
|
# taken verbatim from toggle.pm
|
|
|
|
sub include_javascript ($) {
|
|
|
|
my $from=shift;
|
|
|
|
|
|
|
|
return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
|
|
|
|
'" type="text/javascript" charset="utf-8"></script>'."\n".
|
|
|
|
'<script src="'.urlto("ikiwiki/toggle.js", $from).
|
|
|
|
'" type="text/javascript" charset="utf-8"></script>';
|
|
|
|
}
|
|
|
|
|
2008-03-03 21:53:34 +01:00
|
|
|
1
|