aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2010-02-14 18:27:47 -0500
committerJoey Hess <joey@gnu.kitenet.net>2010-02-14 19:11:18 -0500
commitc21eb47e627de2dfd5409b459b2e11498c534f3c (patch)
treee92408f9e519fb996ed3c77c7f7358d18d1f8fae /IkiWiki
parent9a0b9bdc88c1b47c14ad0b587c93bbac400e61ac (diff)
downloadikiwiki-c21eb47e627de2dfd5409b459b2e11498c534f3c.tar
ikiwiki-c21eb47e627de2dfd5409b459b2e11498c534f3c.tar.gz
comments: Display number of comments in comment action link.
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.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/comments.pm36
1 files changed, 25 insertions, 11 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 5bcf4a981..8f8472f07 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -736,9 +736,7 @@ sub pagetemplate (@) {
}
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');
}
- # 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')) {
- $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",
- 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;