comments: If comment content checks fail, store the comment (in .ikiwiki/comments_pen...
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 25 Jan 2009 20:42:13 +0000 (15:42 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Sun, 25 Jan 2009 20:42:13 +0000 (15:42 -0500)
IkiWiki/Plugin/comments.pm
IkiWiki/Plugin/editpage.pm
debian/changelog
doc/plugins/comments.mdwn

index 6d0e45a97d29f49569f306b616aada1183f36510..4d225b90ae88b40524b51858edcc9366efd99c01 100644 (file)
@@ -380,14 +380,7 @@ sub sessioncgi ($$) {
        IkiWiki::check_canedit($page, $cgi, $session);
        $postcomment=0;
 
-       # FIXME: rather a simplistic way to make the comments...
-       my $i = 0;
-       my $file;
-       my $location;
-       do {
-               $i++;
-               $location = "$page/$config{comments_pagename}$i";
-       } while (-e "$config{srcdir}/$location._comment");
+       my $location=unique_comment_location($page, $config{srcdir});
 
        my $content = "[[!_comment format=$type\n";
 
@@ -470,21 +463,33 @@ sub sessioncgi ($$) {
                IkiWiki::checksessionexpiry($cgi, $session);
                
                $postcomment=1;
-               IkiWiki::check_content(content => $form->field('editcontent'),
+               my $ok=IkiWiki::check_content(content => $form->field('editcontent'),
                        subject => $form->field('subject'),
                        $config{comments_allowauthor} ? (
                                author => $form->field('author'),
                                url => $form->field('url'),
                        ) : (),
                        page => $location,
-                       cgi => $cgi, session => $session
+                       cgi => $cgi,
+                       session => $session,
+                       nonfatal => 1,
                );
                $postcomment=0;
-               
-               my $file = "$location._comment";
+
+               if (! $ok) {
+                       my $penddir=$config{wikistatedir}."/comments_pending";
+                       $location=unique_comment_location($page, $penddir);
+                       writefile("$location._comment", $penddir, $content);
+                       print IkiWiki::misctemplate(gettext(gettext("comment stored for moderation")),
+                               "<p>".
+                               gettext("Your comment will be posted after moderator review"),
+                               "</p>");
+                       exit;
+               }
 
                # FIXME: could probably do some sort of graceful retry
                # on error? Would require significant unwinding though
+               my $file = "$location._comment";
                writefile($file, $config{srcdir}, $content);
 
                my $conflict;
@@ -654,6 +659,20 @@ sub pagetemplate (@) {
        }
 }
 
+sub unique_comment_location ($) {
+       my $page=shift;
+       my $dir=shift;
+
+       my $location;
+       my $i = 0;
+       do {
+               $i++;
+               $location = "$page/$config{comments_pagename}$i";
+       } while (-e "$dir/$location._comment");
+
+       return $location;
+}
+
 package IkiWiki::PageSpec;
 
 sub match_postcomment ($$;@) {
index bba52e4fd322e8bbad5f63a13198ff5f491cdef5..c206d96a44f521200861271bd2256a03b49ccfa2 100644 (file)
@@ -105,11 +105,12 @@ sub check_content (@) {
                                $ok=1;
                        }
                        elsif (ref $ret eq 'CODE') {
-                               $ret->();
+                               $ret->() unless $params{nonfatal};
                                $ok=0;
                        }
                        elsif (defined $ret) {
-                               error($ret);
+                               error($ret) unless $params{nonfatal};
+                               $ok=0;
                        }
                }
 
index 96089c101b83eb107207e9f1ad3e46ebb99f78d5..002ae12c1224052b082c7fefb2673a265ef49624 100644 (file)
@@ -6,6 +6,8 @@ ikiwiki (3.03) UNRELEASED; urgency=low
   * Remove nonstandard css. Closes: #512378
   * blogspam: Fix use of blogspam_options and blogspam_server
     config settings.
+  * comments: If comment content checks fail, store the comment
+    (in .ikiwiki/comments_pending) for moderator review.
 
  -- Joey Hess <joeyh@debian.org>  Sun, 18 Jan 2009 14:50:57 -0500
 
index 72b11af645a607711af4a3d16b39057d74ff9738..4cee3b9ad1d61ebcce952fc60a772f29b0a2370c 100644 (file)
@@ -41,3 +41,10 @@ There are some global options for the setup file:
   specify a name for themselves, and the \[[!meta author]] and
   \[[!meta authorurl]] directives will not be overridden by the comments
   plugin
+
+## comment moderation
+
+If you enable the [[blogspam]] plugin, comments that appear spammy will be
+held for moderation. These comments are stored in
+`.ikiwiki/comments_pending/`, and can be deleted, or moved into the
+wiki's srcdir to be posted.