]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
clarify why absolute is tested & stripped here
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
index 5bcf4a981406dac4ed93a9b7d17d9a066b4acc43..1c219b6c6adeb492a361e1459567b6a0614a4e44 100644 (file)
@@ -221,7 +221,9 @@ sub preprocess {
        }
 
        if (defined $params{subject}) {
-               $pagestate{$page}{meta}{title} = $params{subject};
+               # decode title the same way meta does
+               eval q{use HTML::Entities};
+               $pagestate{$page}{meta}{title} = decode_entities($params{subject});
        }
 
        if ($params{page} =~ m/\/\Q$config{comments_pagename}\E\d+_/) {
@@ -336,7 +338,7 @@ sub editcomment ($$) {
        my $page = $form->field('page');
        $page = IkiWiki::possibly_foolish_untaint($page);
        if (! defined $page || ! length $page ||
-               IkiWiki::file_pruned($page, $config{srcdir})) {
+               IkiWiki::file_pruned($page)) {
                error(gettext("bad page name"));
        }
 
@@ -546,7 +548,7 @@ sub commentmoderation ($$) {
                                # pending comment before untainting.
                                my ($f)= $id =~ /$config{wiki_file_regexp}/;
                                if (! defined $f || ! length $f ||
-                                   IkiWiki::file_pruned($f, $config{srcdir})) {
+                                   IkiWiki::file_pruned($f)) {
                                        error("illegal file");
                                }
 
@@ -736,9 +738,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 +755,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 +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;
@@ -825,7 +841,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 +857,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;