2 package IkiWiki::Plugin::recentchangesdiff;
12 add_underlay("javascript");
13 hook(type => "getsetup", id => "recentchangesdiff",
15 hook(type => "pagetemplate", id => "recentchangesdiff",
16 call => \&pagetemplate);
17 hook(type => "format", id => "recentchangesdiff.pm", call => \&format);
28 sub pagetemplate (@) {
30 my $template=$params{template};
31 if ($config{rcs} && exists $params{rev} && length $params{rev} &&
32 $template->query(name => "diff")) {
33 my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
37 if (@lines > $maxlines) {
38 $diff=join("", @lines[0..($maxlines-1)]);
42 $diff=join("", @lines);
44 if (length $diff > 102400) {
45 $diff=substr($diff, 0, 10240);
49 $diff.="\n".gettext("(Diff truncated)");
52 $diff = encode_entities($diff);
53 # escape links and preprocessor stuff
54 $diff = encode_entities($diff, '\[\]');
55 $template->param(diff => $diff);
63 if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
64 # no <body> tag, probably in preview mode
65 $params{content}=include_javascript(undef).$params{content};
67 return $params{content};
70 # taken verbatim from toggle.pm
71 sub include_javascript ($) {
74 return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
75 '" type="text/javascript" charset="utf-8"></script>'."\n".
76 '<script src="'.urlto("ikiwiki/toggle.js", $from).
77 '" type="text/javascript" charset="utf-8"></script>';