<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::recentchangesdiff;

use warnings;
use strict;
use IkiWiki 3.00;
use HTML::Entities;

my $maxlines=200;

sub import {
	add_underlay("javascript");
	hook(type =&gt; "getsetup", id =&gt; "recentchangesdiff",
		call =&gt; \&amp;getsetup);
	hook(type =&gt; "pagetemplate", id =&gt; "recentchangesdiff",
		call =&gt; \&amp;pagetemplate);
	hook(type =&gt; "format", id =&gt; "recentchangesdiff.pm", call =&gt; \&amp;format);
}

sub getsetup () {
	return 
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1,
		},
}

sub pagetemplate (@) {
	my %params=@_;
	my $template=$params{template};
	if ($config{rcs} &amp;&amp; exists $params{rev} &amp;&amp; length $params{rev} &amp;&amp;
	    $template-&gt;query(name =&gt; "diff")) {
		my @lines=IkiWiki::rcs_diff($params{rev}, $maxlines+1);
		if (@lines) {
			my $diff;
			my $trunc=0;
			if (@lines &gt; $maxlines) {
				$diff=join("", @lines[0..($maxlines-1)]);
				$trunc=1;
			}
			else {
				$diff=join("", @lines);
			}
			if (length $diff &gt; 102400) {
				$diff=substr($diff, 0, 10240);
				$trunc=1;
			}
			if ($trunc) {
				$diff.="\n".gettext("(Diff truncated)");
			}
			# escape html
			$diff = encode_entities($diff);
			# escape links and preprocessor stuff
			$diff = encode_entities($diff, '\[\]');
			$template-&gt;param(diff =&gt; $diff);
		}
	}
}

sub format (@) {
        my %params=@_;

	if (! ($params{content}=~s!^(&lt;body[^&gt;]*&gt;)!$1.include_javascript($params{page})!em)) {
		# no &lt;body&gt; 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 '&lt;script src="'.urlto("ikiwiki/ikiwiki.js", $from).
		'" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;'."\n".
		'&lt;script src="'.urlto("ikiwiki/toggle.js", $from).
		'" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;';
}

1
</pre></body></html>