X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/4e92548ebc39c083e7ed8b870f4c13ba229127cd..565e5291cd037c155e976b69f7b8d26c5b64a389:/IkiWiki/Plugin/comments.pm diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 995d1f4eb..98f9f8b3d 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -26,6 +26,8 @@ sub import { hook(type => "htmlize", id => "_comment", call => \&htmlize); hook(type => "pagetemplate", id => "comments", call => \&pagetemplate); hook(type => "formbuilder_setup", id => "comments", call => \&formbuilder_setup); + # Load goto to fix up user page links for logged-in commenters + IkiWiki::loadplugin("goto"); IkiWiki::loadplugin("inline"); } @@ -222,7 +224,7 @@ sub preprocess { if ($params{page} =~ m/\/(\Q$config{comments_pagename}\E\d+)$/) { $pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page}), undef, 1). - "#".$params{page}; + "#".page_to_id($params{page}); } eval q{use Date::Parse}; @@ -488,7 +490,8 @@ sub editcomment ($$) { # Jump to the new comment on the page. # The trailing question mark tries to avoid broken # caches and get the most recent version of the page. - IkiWiki::redirect($cgi, urlto($page, undef, 1)."?updated#$location"); + IkiWiki::redirect($cgi, urlto($page, undef, 1). + "?updated#".page_to_id($location)); } else { @@ -603,7 +606,8 @@ sub formbuilder_setup (@) { my %params=@_; my $form=$params{form}; - if ($form->title eq "preferences") { + if ($form->title eq "preferences" && + IkiWiki::is_admin($params{session}->param("name"))) { push @{$params{buttons}}, "Comment Moderation"; if ($form->submitted && $form->submitted eq "Comment Moderation") { commentmoderation($params{cgi}, $params{session}); @@ -669,7 +673,7 @@ sub previewcomment ($$$) { sub commentsshown ($) { my $page=shift; - return ! pagespec_match($page, "*/$config{comments_pagename}*", + return ! pagespec_match($page, "internal(*/$config{comments_pagename}*)", location => $page) && pagespec_match($page, $config{comments_pagespec}, location => $page); @@ -756,6 +760,10 @@ sub pagetemplate (@) { if (!exists $commentstate{$page}) { return; } + + if ($template->query(name => 'commentid')) { + $template->param(commentid => page_to_id($page)); + } if ($template->query(name => 'commentuser')) { $template->param(commentuser => @@ -805,6 +813,18 @@ sub unique_comment_location ($) { return $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 + # comment. + my $page=shift; + + eval q{use Digest::MD5 'md5_hex'}; + error($@) if $@; + + return "comment-".md5_hex($page); +} + package IkiWiki::PageSpec; sub match_postcomment ($$;@) {