aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-03-26 16:45:53 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-03-26 16:45:53 -0400
commit10822a22b3d8872afb31e1847ee7448af86c574d (patch)
tree77a47c4b3a38d69759c1b4faa47108b1daa4481d /IkiWiki
parent3481a35953c0f8e858b382829c239411b06889c4 (diff)
downloadikiwiki-10822a22b3d8872afb31e1847ee7448af86c574d.tar
ikiwiki-10822a22b3d8872afb31e1847ee7448af86c574d.tar.gz
comments: Fix anchor ids to be legal xhtml. Closes: #521339
Well, that was a PITA. Luckily, this doesn't break guids to comments in rss feeds, though it does change the links. I haven't put in a warning about needing to rebuild to get this fix. It's probably good enough for new comments to get the fix, without a lot of mass rebuilding.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/comments.pm24
1 files changed, 22 insertions, 2 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 5782d9083..2ad422f5f 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,21 @@ 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;
+
+ # It needs to start with a letter.
+ $page="comment_".$page;
+
+ # Encode any illegal characters.
+ $page=~s/([^A-Za-z0-9-_:.])/"__".ord($1)."__"/eg;
+
+ return $page;
+}
+
package IkiWiki::PageSpec;
sub match_postcomment ($$;@) {