]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/moderatedcomments.pm
moderatedcomments: New plugin to allow comment moderation w/o relying on blogspam.net.
[ikiwiki.git] / IkiWiki / Plugin / moderatedcomments.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::moderatedcomments;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "getsetup", id => "moderatedcomments",  call => \&getsetup);
10         hook(type => "checkcontent", id => "moderatedcomments", call => \&checkcontent);
11 }
12
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 0,
18                 },
19                 moderate_users => {
20                         type => 'boolean',
21                         example => 1,
22                         description => 'Moderate comments of logged-in users?',
23                         safe => 1,
24                         rebuild => 0,
25                 },
26 }
27
28 sub checkcontent (@) {
29         my %params=@_;
30         
31         # only handle comments  
32         return undef unless pagespec_match($params{page}, "postcomment(*)",
33                                 location => $params{page});
34
35         # admins and maybe users can comment w/o moderation
36         my $session=$params{session};
37         my $user=$session->param("name") if $session;
38         return undef if defined $user && (IkiWiki::is_admin($user) ||
39                 (exists $config{moderate_users} && ! $config{moderate_users}));
40
41         return gettext("comment needs moderation");
42 }
43
44 1