Group related plugins into sections in the setup file, and drop unused rcs plugins...
[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                         section => "auth",
19                 },
20                 moderate_users => {
21                         type => 'boolean',
22                         example => 1,
23                         description => 'Moderate comments of logged-in users?',
24                         safe => 1,
25                         rebuild => 0,
26                 },
27 }
28
29 sub checkcontent (@) {
30         my %params=@_;
31         
32         # only handle comments  
33         return undef unless pagespec_match($params{page}, "postcomment(*)",
34                                 location => $params{page});
35
36         # admins and maybe users can comment w/o moderation
37         my $session=$params{session};
38         my $user=$session->param("name") if $session;
39         return undef if defined $user && (IkiWiki::is_admin($user) ||
40                 (exists $config{moderate_users} && ! $config{moderate_users}));
41
42         return gettext("comment needs moderation");
43 }
44
45 1