]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/comments.pm
use one parameter form of file_pruned here too
[ikiwiki.git] / IkiWiki / Plugin / comments.pm
index 5586cca522e5cb2e43422d99c267235197985c5d..32e4d09377001a3b769429a7b4561c26730ab091 100644 (file)
@@ -38,6 +38,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => 1,
+                       section => "web",
                },
                comments_pagespec => {
                        type => 'pagespec',
@@ -171,9 +172,8 @@ sub preprocess {
                else {
                        $commentauthorurl = IkiWiki::cgiurl(
                                do => 'goto',
-                               page => (length $config{userdir}
-                                       ? "$config{userdir}/$commentuser"
-                                       : "$commentuser"));
+                               page => IkiWiki::userpage($commentuser)
+                       );
 
                        $commentauthor = $commentuser;
                }
@@ -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");
                                }
 
@@ -643,7 +645,7 @@ sub comments_pending () {
                no_chdir => 1,
                wanted => sub {
                        $_=decode_utf8($_);
-                       if (IkiWiki::file_pruned($_, $dir)) {
+                       if (IkiWiki::file_pruned($_)) {
                                $File::Find::prune=1;
                        }
                        elsif (! -l $_ && ! -d _) {
@@ -651,7 +653,6 @@ sub comments_pending () {
                                my ($f)=/$config{wiki_file_regexp}/; # untaint
                                if (defined $f && $f =~ /\Q._comment\E$/) {
                                        my $ctime=(stat($f))[10];
-                                       $f=~s/^\Q$dir\E\/?//;
                                         push @ret, [$f, $ctime];
                                }
                        }
@@ -736,39 +737,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 = "<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;
                }
        }
 
@@ -816,6 +821,12 @@ sub pagetemplate (@) {
        }
 }
 
+sub addcommenturl ($) {
+       my $page=shift;
+
+       return IkiWiki::cgiurl(do => 'comment', page => $page);
+}
+
 sub num_comments ($$) {
        my $page=shift;
        my $dir=shift;
@@ -829,7 +840,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;
 
@@ -845,14 +856,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;