diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2010-03-11 15:44:10 -0500 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2010-03-11 15:44:10 -0500 |
commit | ac3aac560f74457ded48ba3b5a14d0bbbf9b6d92 (patch) | |
tree | db7b5d162ffb2a8cb6ae93b33090ff114033a457 /IkiWiki/Plugin | |
parent | 2f2fbdf3a32ae7c7132441ad90c67553f80c306d (diff) |
moderatedcomments: Added moderate_pagespec
* moderatedcomments: Added moderate_pagespec that can be used
to control which users or comment locations are moderated.
This can be used, just for example, to moderate http://myopenid.com/*
if you're getting a lot of spammers from one particular openid
provider (who should perhaps answer your emails about them),
while not moderating other users.
* moderatedcomments: The moderate_users setting is deprecated. Instead,
set moderate_pagespec to "!admin()" or "user(*)" instead.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/moderatedcomments.pm | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/IkiWiki/Plugin/moderatedcomments.pm b/IkiWiki/Plugin/moderatedcomments.pm index afe1ceedf..b0a328a06 100644 --- a/IkiWiki/Plugin/moderatedcomments.pm +++ b/IkiWiki/Plugin/moderatedcomments.pm @@ -17,10 +17,11 @@ sub getsetup () { rebuild => 0, section => "auth", }, - moderate_users => { - type => 'boolean', - example => 1, - description => 'Moderate comments of logged-in users?', + moderate_pagespec => { + type => 'pagespec', + example => 'user(http://*)', + description => 'PageSpec matching users or comment locations to moderate', + link => 'ikiwiki/PageSpec', safe => 1, rebuild => 0, }, @@ -32,14 +33,32 @@ sub checkcontent (@) { # only handle comments return undef unless pagespec_match($params{page}, "postcomment(*)", location => $params{page}); + + # 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()"; + } - # admins and maybe users can comment w/o moderation my $session=$params{session}; my $user=$session->param("name") if $session; - return undef if defined $user && (IkiWiki::is_admin($user) || - (exists $config{moderate_users} && ! $config{moderate_users})); - - return gettext("comment needs moderation"); + 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; + } } 1 |