<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::moderatedcomments;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "moderatedcomments",  call =&gt; \&amp;getsetup);
	hook(type =&gt; "checkcontent", id =&gt; "moderatedcomments", call =&gt; \&amp;checkcontent);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 0,
			section =&gt; "auth",
		},
		moderate_pagespec =&gt; {
			type =&gt; 'pagespec',
			example =&gt; 'user(http://*)',
			description =&gt; 'PageSpec matching users or comment locations to moderate',
			link =&gt; 'ikiwiki/PageSpec',
			safe =&gt; 1,
			rebuild =&gt; 0,
		},
}

sub checkcontent (@) {
	my %params=@_;
	
	# only handle comments	
	return undef unless pagespec_match($params{page}, "postcomment(*)",
	                	location =&gt; $params{page});
	
	# backwards compatability
	if (exists $config{moderate_users} &amp;&amp;
	    ! exists $config{moderate_pagespec}) {
		$config{moderate_pagespec} = $config{moderate_users}
			? "!admin()"
			: "!user(*)";
	}

	# default is to moderate all except admins
	if (! exists $config{moderate_pagespec}) {
		$config{moderate_pagespec}="!admin()";
	}

	my $session=$params{session};
	my $user=$session-&gt;param("name") if $session;
	if (pagespec_match($params{page}, $config{moderate_pagespec},
			location =&gt; $params{page},
			(defined $user ? (user =&gt; $user) : ()),
			(defined $ENV{REMOTE_ADDR} ? (ip =&gt; $ENV{REMOTE_ADDR}) : ()),
	)) {
		return gettext("comment needs moderation");
	}
	else {
		return undef;
	}
}

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