X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/503d83ffbc358714ad84e46ce523b8702268edb6..260ee2a28368691a5f1a7dee918717a28d28ed2e:/IkiWiki/Plugin/comments.pm diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 5782d9083..98f9f8b3d 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -224,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}; @@ -490,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 { @@ -759,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 => @@ -808,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 ($$;@) {