X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/9a0b9bdc88c1b47c14ad0b587c93bbac400e61ac..99b402cd622d38cb8337498d8fdb4f135e8be03c:/IkiWiki/Plugin/comments.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 5bcf4a981..98786f432 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 = "". + #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; } } @@ -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; @@ -825,7 +839,7 @@ sub unique_comment_location ($$$) { eval q{use Digest::MD5 'md5_hex'}; error($@) if $@; - my $content_md5=md5_hex(shift); + my $content_md5=md5_hex(Encode::encode_utf8(shift)); my $dir=shift; @@ -841,14 +855,14 @@ sub unique_comment_location ($$$) { sub page_to_id ($) { # Converts a comment page name into a unique, legal html id - # addtibute value, that can be used as an anchor to link to the + # attribute value, that can be used as an anchor to link to the # comment. my $page=shift; eval q{use Digest::MD5 'md5_hex'}; error($@) if $@; - return "comment-".md5_hex($page); + return "comment-".md5_hex(Encode::encode_utf8(($page))); } package IkiWiki::PageSpec;