moderatedcomments: Added moderate_pagespec
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 11 Mar 2010 20:44:10 +0000 (15:44 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 11 Mar 2010 20:44:10 +0000 (15:44 -0500)
* 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.

IkiWiki/Plugin/moderatedcomments.pm
debian/changelog
doc/plugins/moderatedcomments.mdwn

index afe1ceedf0940cf3ebe94e7de56b5faf0f1c720f..b0a328a06dffb040f2d6af4a5ba71f2b1a76f6b1 100644 (file)
@@ -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
index d1253c0796b35f12edb4a0290342cd0012965111..c58e612db545ad2f6cb601f9864bafdd201c32a9 100644 (file)
@@ -1,6 +1,14 @@
 ikiwiki (3.20100303) UNRELEASED; urgency=low
 
   * Fix utf8 issues in calls to md5_hex.
+  * 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.
 
  -- Joey Hess <joeyh@debian.org>  Tue, 09 Mar 2010 19:46:35 -0500
 
index 97924d742a1ea5d7184ef8ab44d6f2adb30cbea4..c29b0b052f6ba2c7fb3d6ad7f467d8453ea0a143 100644 (file)
@@ -5,6 +5,8 @@ This plugin causes [[comments]] to be held for manual moderation.
 Admins can access the comment moderation queue via their preferences page.
 
 By default, all comments made by anyone who is not an admin will be held
-for moderation. The `moderate_users` setting can be set to false to avoid
-moderating comments of logged-in users, while still moderating anonymous
-comments.
+for moderation. The `moderate_pagespec` setting can be used to specify a
+[[ikiwiki/PageSpec]] to match comments and users who should be moderated.
+For example, to avoid moderating comments from logged-in users, set
+`moderate_pagespec` to "!user(*)". Or to moderate everyone except for
+admins, set it to "!admin(*)".