add paths to plugin files in copyright
[ikiwiki.git] / IkiWiki / Plugin / moderatedcomments.pm
blob5957833fc2de44dc20484f616f8813ff0306400b
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::moderatedcomments;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9 hook(type => "getsetup", id => "moderatedcomments", call => \&getsetup);
10 hook(type => "checkcontent", id => "moderatedcomments", call => \&checkcontent);
13 sub getsetup () {
14 return
15 plugin => {
16 safe => 1,
17 rebuild => 0,
18 section => "auth",
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,
30 sub checkcontent (@) {
31 my %params=@_;
33 # only handle comments
34 return undef unless pagespec_match($params{page}, "postcomment(*)",
35 location => $params{page});
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(*)";
45 # default is to moderate all except admins
46 if (! exists $config{moderate_pagespec}) {
47 $config{moderate_pagespec}="!admin()";
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");
59 else {
60 return undef;