2009-10-26 18:24:27 +01:00
|
|
|
#!/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,
|
2010-02-12 04:24:15 +01:00
|
|
|
section => "auth",
|
2009-10-26 18:24:27 +01:00
|
|
|
},
|
2010-03-11 21:44:10 +01:00
|
|
|
moderate_pagespec => {
|
|
|
|
type => 'pagespec',
|
|
|
|
example => 'user(http://*)',
|
|
|
|
description => 'PageSpec matching users or comment locations to moderate',
|
|
|
|
link => 'ikiwiki/PageSpec',
|
2009-10-26 18:24:27 +01:00
|
|
|
safe => 1,
|
|
|
|
rebuild => 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checkcontent (@) {
|
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
# only handle comments
|
|
|
|
return undef unless pagespec_match($params{page}, "postcomment(*)",
|
|
|
|
location => $params{page});
|
2010-03-11 21:44:10 +01:00
|
|
|
|
|
|
|
# backwards compatability
|
|
|
|
if (exists $config{moderate_users} &&
|
|
|
|
! exists $config{moderate_pagespec}) {
|
|
|
|
$config{moderate_pagespec} = $config{moderate_users}
|
|
|
|
? "!admin()"
|
|
|
|
: "!user(*)";
|
|
|
|
}
|
|
|
|
|
|
|
|
# default is to moderate all except admins
|
|
|
|
if (! exists $config{moderate_pagespec}) {
|
|
|
|
$config{moderate_pagespec}="!admin()";
|
|
|
|
}
|
2009-10-26 18:24:27 +01:00
|
|
|
|
|
|
|
my $session=$params{session};
|
|
|
|
my $user=$session->param("name") if $session;
|
2010-03-11 21:44:10 +01:00
|
|
|
if (pagespec_match($params{page}, $config{moderate_pagespec},
|
|
|
|
location => $params{page},
|
|
|
|
(defined $user ? (user => $user) : ()),
|
|
|
|
(defined $ENV{REMOTE_ADDR} ? (ip => $ENV{REMOTE_ADDR}) : ()),
|
|
|
|
)) {
|
|
|
|
return gettext("comment needs moderation");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return undef;
|
|
|
|
}
|
2009-10-26 18:24:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1
|