aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/moderatedcomments.pm
blob: afe1ceedf0940cf3ebe94e7de56b5faf0f1c720f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
package IkiWiki::Plugin::moderatedcomments;

use warnings;
use strict;
use IkiWiki 3.00;

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

sub getsetup () {
	return
		plugin => {
			safe => 1,
			rebuild => 0,
			section => "auth",
		},
		moderate_users => {
			type => 'boolean',
			example => 1,
			description => 'Moderate comments of logged-in users?',
			safe => 1,
			rebuild => 0,
		},
}

sub checkcontent (@) {
	my %params=@_;
	
	# only handle comments	
	return undef unless pagespec_match($params{page}, "postcomment(*)",
	                	location => $params{page});

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

	return gettext("comment needs moderation");
}

1