]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/comments.pm
Merge remote branch 'smcv/ready/sort-package'
[git.ikiwiki.info.git] / IkiWiki / Plugin / comments.pm
index caed0d58c5e05fedc70a7a480a5247e728c83b69..4603417103c3abdb3e4d16beb6c60c8c90f05118 100644 (file)
@@ -38,6 +38,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => 1,
                plugin => {
                        safe => 1,
                        rebuild => 1,
+                       section => "web",
                },
                comments_pagespec => {
                        type => 'pagespec',
                },
                comments_pagespec => {
                        type => 'pagespec',
@@ -220,7 +221,9 @@ sub preprocess {
        }
 
        if (defined $params{subject}) {
        }
 
        if (defined $params{subject}) {
-               $pagestate{$page}{meta}{title} = $params{subject};
+               # encode title the same way meta does
+               eval q{use HTML::Entities};
+               $pagestate{$page}{meta}{title} = HTML::Entities::encode_numeric(decode_entities($params{subject}));
        }
 
        if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
        }
 
        if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
@@ -735,39 +738,43 @@ 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));
                }
        }
 
                }
        }
 
-       if ($template->query(name => 'commentsurl')) {
-               if ($shown) {
+       if ($shown) {
+               if ($template->query(name => 'commentsurl')) {
                        $template->param(commentsurl =>
                                urlto($page, undef, 1).'#comments');
                }
                        $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');
                }
                        # 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",
                                        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;
                }
        }
 
                }
        }
 
@@ -815,6 +822,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;
@@ -828,7 +841,7 @@ sub unique_comment_location ($$$) {
 
        eval q{use Digest::MD5 'md5_hex'};
        error($@) if $@;
 
        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;
 
 
        my $dir=shift;
 
@@ -844,14 +857,14 @@ sub unique_comment_location ($$$) {
 
 sub page_to_id ($) {
        # Converts a comment page name into a unique, legal html id
 
 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 $@;
 
        # 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;
 }
        
 package IkiWiki::PageSpec;