X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/20ba12802b3897bf48d8a7704a57e9cede2466bd..c21eb47e627de2dfd5409b459b2e11498c534f3c:/IkiWiki/Plugin/comments.pm diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 1e71749a4..8f8472f07 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -736,39 +736,43 @@ sub pagetemplate (@) { } if ($shown && commentsopen($page)) { - my $addcommenturl = IkiWiki::cgiurl(do => 'comment', - page => $page); - $template->param(addcommenturl => $addcommenturl); + $template->param(addcommenturl => addcommenturl($page)); } } - if ($template->query(name => 'commentsurl')) { - if ($shown) { + if ($shown) { + if ($template->query(name => 'commentsurl')) { $template->param(commentsurl => urlto($page, undef, 1).'#comments'); } - } - if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) { - if ($shown) { + if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) { # This will 404 until there are some comments, but I # think that's probably OK... $template->param(atomcommentsurl => urlto($page, undef, 1).'comments.atom'); } - } - if ($template->query(name => 'commentslink')) { - # 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 ($shown) { - $template->param(commentslink => - htmllink($page, $params{destpage}, $page, - linktext => gettext("Comments"), + if ($template->query(name => 'commentslink')) { + 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 = "". + #translators: Here "Comment" is a verb; + #translators: the user clicks on it to + #translators: post a comment. + gettext("Comment"). + ""; + } + $template->param(commentslink => $link) + if defined $link; } } @@ -816,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;