]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
simplify example
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
index 077c4776bb85e68337bf356093e20a0b5c087290..de193bd12b358d2850a823c3e492af1844b4a292 100644 (file)
@@ -109,7 +109,7 @@ sub htmlize {
 
 sub htmlize_pending {
        my %params = @_;
-       return sprintf(gettext("comment pending %s"),
+       return sprintf(gettext("this comment needs %s"),
                '<a href="'.
                IkiWiki::cgiurl(do => "commentmoderation").'">'.
                gettext("moderation").'</a>');
@@ -262,6 +262,10 @@ sub sessioncgi ($$) {
        elsif ($do eq 'commentmoderation') {
                commentmoderation($cgi, $session);
        }
+       elsif ($do eq 'commentsignin') {
+               IkiWiki::cgi_signin($cgi, $session);
+               exit;
+       }
 }
 
 # Mostly cargo-culted from IkiWiki::plugin::editpage
@@ -339,7 +343,7 @@ sub editcomment ($$) {
 
        if (! defined $session->param('name')) {
                # Make signinurl work and return here.
-               $form->tmpl_param(signinurl => IkiWiki::cgiurl(do => 'signin'));
+               $form->tmpl_param(signinurl => IkiWiki::cgiurl(do => 'commentsignin'));
                $session->param(postsignin => $ENV{QUERY_STRING});
                IkiWiki::cgi_savesession($session);
        }
@@ -855,7 +859,7 @@ sub num_comments ($$) {
        my $dir=shift;
 
        my @comments=glob("$dir/$page/$config{comments_pagename}*._comment");
-       return @comments;
+       return int @comments;
 }
 
 sub unique_comment_location ($$$$) {
@@ -904,28 +908,32 @@ sub match_comment ($$;@) {
        my $page = shift;
        my $glob = shift;
 
-       my $match=match_glob($page, "$glob/*", internal => 1, @_);
-       if ($match && exists $IkiWiki::pagesources{$page}) {
-               my $type=IkiWiki::pagetype($IkiWiki::pagesources{$page});
-               if (defined $type && $type ne "_comment") {
-                       return IkiWiki::FailReason->new("$page is not a comment");
-               }
+       # To see if it's a comment, check the source file type.
+       # Deal with comments that were just deleted.
+       my $source=exists $IkiWiki::pagesources{$page} ?
+               $IkiWiki::pagesources{$page} :
+               $IkiWiki::delpagesources{$page};
+       my $type=IkiWiki::pagetype($source);
+       if (defined $type && $type ne "_comment") {
+               return IkiWiki::FailReason->new("$page is not a comment");
        }
-       return $match;
+
+       return match_glob($page, "$glob/*", internal => 1, @_);
 }
 
 sub match_comment_pending ($$;@) {
        my $page = shift;
        my $glob = shift;
-
-       my $match=match_glob($page, "$glob/*", internal => 1, @_);
-       if ($match && $IkiWiki::pagesources{$page}) {
-               my $type=IkiWiki::pagetype($IkiWiki::pagesources{$page});
-               if (defined $type && $type ne "_comment_pending") {
-                       return IkiWiki::FailReason->new("$page is not a pending comment");
-               }
+       
+       my $source=exists $IkiWiki::pagesources{$page} ?
+               $IkiWiki::pagesources{$page} :
+               $IkiWiki::delpagesources{$page};
+       my $type=IkiWiki::pagetype($source);
+       if (defined $type && $type ne "_comment_pending") {
+               return IkiWiki::FailReason->new("$page is not a pending comment");
        }
-       return $match;
+
+       return match_glob($page, "$glob/*", internal => 1, @_);
 }
 
 1