<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,
		},
		moderate_users =&gt; {
			type =&gt; 'boolean',
			example =&gt; 1,
			description =&gt; 'Moderate comments of logged-in users?',
			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});

	# admins and maybe users can comment w/o moderation
	my $session=$params{session};
	my $user=$session-&gt;param("name") if $session;
	return undef if defined $user &amp;&amp; (IkiWiki::is_admin($user) ||
		(exists $config{moderate_users} &amp;&amp; ! $config{moderate_users}));

	return gettext("comment needs moderation");
}

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