Optionally add indentation to maps
[ikiwiki] / 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_pagespec => {
21                         type => 'pagespec',
22                         example => '*',
23                         description => 'PageSpec matching users or comment locations to moderate',
24                         link => 'ikiwiki/PageSpec',
25                         safe => 1,
26                         rebuild => 0,
27                 },
28 }
29
30 sub checkcontent (@) {
31         my %params=@_;
32         
33         # only handle comments  
34         return undef unless pagespec_match($params{page}, "postcomment(*)",
35                                 location => $params{page});
36         
37         # backwards compatability
38         if (exists $config{moderate_users} &&
39             ! exists $config{moderate_pagespec}) {
40                 $config{moderate_pagespec} = $config{moderate_users}
41                         ? "!admin()"
42                         : "!user(*)";
43         }
44
45         # default is to moderate all except admins
46         if (! exists $config{moderate_pagespec}) {
47                 $config{moderate_pagespec}="!admin()";
48         }
49
50         my $session=$params{session};
51         my $user=$session->param("name");
52         if (pagespec_match($params{page}, $config{moderate_pagespec},
53                         location => $params{page},
54                         (defined $user ? (user => $user) : ()),
55                         (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()),
56         )) {
57                 return gettext("comment needs moderation");
58         }
59         else {
60                 return undef;
61         }
62 }
63
64 1