]> sipb.mit.edu Git - ikiwiki.git/commitdiff
comments: Display number of comments in comment action link.
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 14 Feb 2010 23:27:47 +0000 (18:27 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 15 Feb 2010 00:11:18 +0000 (19:11 -0500)
This was not doable before, but when I added transitive dependency handling
in the big dependency rewrite, it became possible to include a comment
count when inlining.

This also improves the action link when a page has no comments. It will
link direct to the cgi to allow posting the first comment. And if the page
is locked to prevent posting new comments, the link is no longer shown.

IkiWiki/Plugin/comments.pm
debian/changelog

index 5bcf4a981406dac4ed93a9b7d17d9a066b4acc43..8f8472f075f20c69e57578b75041c4ce145224f1 100644 (file)
@@ -736,9 +736,7 @@ sub pagetemplate (@) {
                }
 
                if ($shown && commentsopen($page)) {
                }
 
                if ($shown && commentsopen($page)) {
-                       my $addcommenturl = IkiWiki::cgiurl(do => 'comment',
-                               page => $page);
-                       $template->param(addcommenturl => $addcommenturl);
+                       $template->param(addcommenturl => addcommenturl($page));
                }
        }
 
                }
        }
 
@@ -755,16 +753,26 @@ sub pagetemplate (@) {
                                urlto($page, undef, 1).'comments.atom');
                }
 
                                urlto($page, undef, 1).'comments.atom');
                }
 
-               # XXX Would be nice to say how many comments there are in
-               # the link. But, to update the number, blog pages
-               # would have to update whenever comments of any inlines
-               # page are added, which is not currently done.
                if ($template->query(name => 'commentslink')) {
                if ($template->query(name => 'commentslink')) {
-                       $template->param(commentslink =>
-                               htmllink($page, $params{destpage}, $page,
-                                       linktext => gettext("Comments"),
+                       my $num=num_comments($page, $config{srcdir});
+                       my $link;
+                       if ($num > 0) {
+                               $link = htmllink($page, $params{destpage}, $page,
+                                       linktext => sprintf(ngettext("%i comment", "%i comments", $num), $num),
                                        anchor => "comments",
                                        anchor => "comments",
-                                       noimageinline => 1));
+                                       noimageinline => 1
+                               );
+                       }
+                       elsif (commentsopen($page)) {
+                               $link = "<a href=\"".addcommenturl($page)."\">".
+                                       #translators: Here "Comment" is a verb;
+                                       #translators: the user clicks on it to
+                                       #translators: post a comment.
+                                       gettext("Comment").
+                                       "</a>";
+                       }
+                       $template->param(commentslink => $link)
+                               if defined $link;
                }
        }
 
                }
        }
 
@@ -812,6 +820,12 @@ sub pagetemplate (@) {
        }
 }
 
        }
 }
 
+sub addcommenturl ($) {
+       my $page=shift;
+
+       return IkiWiki::cgiurl(do => 'comment', page => $page);
+}
+
 sub num_comments ($$) {
        my $page=shift;
        my $dir=shift;
 sub num_comments ($$) {
        my $page=shift;
        my $dir=shift;
index c91feae0de169a0b89ca68729efba45d29b89ef8..e3ec89eed9010cda82f31cc1251816d4261f3e0f 100644 (file)
@@ -1,3 +1,11 @@
+ikiwiki (3.20100213) UNRELEASED; urgency=low
+
+  * comments: Display number of comments in comment action link.
+  * Rebuild wikis on upgrade to this version to get the comment counts
+    added to existing pages.
+
+ -- Joey Hess <joeyh@debian.org>  Sun, 14 Feb 2010 17:02:10 -0500
+
 ikiwiki (3.20100212) unstable; urgency=low
 
   * template: Preprocess parameters before htmlizing.
 ikiwiki (3.20100212) unstable; urgency=low
 
   * template: Preprocess parameters before htmlizing.