diff options
author | Jonas Smedegaard <dr@jones.dk> | 2010-08-27 10:01:58 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2010-08-27 10:01:58 +0200 |
commit | f398ad035b973608d380c9939ea845d8e2a0cdc2 (patch) | |
tree | 1ba1a0c94e375ab8ed609eaa57a542c6b87de5a8 /IkiWiki/Plugin/moderatedcomments.pm | |
parent | 958e5735c946263a111420fe47abe58782581e8c (diff) | |
parent | 6d213a0c739d5b34357b01a616f99197eeba6ad9 (diff) |
Merge branch 'master' of git://git.ikiwiki.info
Diffstat (limited to 'IkiWiki/Plugin/moderatedcomments.pm')
-rw-r--r-- | IkiWiki/Plugin/moderatedcomments.pm | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/moderatedcomments.pm b/IkiWiki/Plugin/moderatedcomments.pm new file mode 100644 index 000000000..5957833fc --- /dev/null +++ b/IkiWiki/Plugin/moderatedcomments.pm @@ -0,0 +1,64 @@ +#!/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, + section => "auth", + }, + moderate_pagespec => { + type => 'pagespec', + example => '*', + description => 'PageSpec matching users or comment locations to moderate', + link => 'ikiwiki/PageSpec', + safe => 1, + rebuild => 0, + }, +} + +sub checkcontent (@) { + my %params=@_; + + # 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()"; + } + + my $session=$params{session}; + my $user=$session->param("name"); + if (pagespec_match($params{page}, $config{moderate_pagespec}, + location => $params{page}, + (defined $user ? (user => $user) : ()), + (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()), + )) { + return gettext("comment needs moderation"); + } + else { + return undef; + } +} + +1 |