From bc66a00b90e00971156f1aea5678ce88d006e84d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:07:36 +0000 Subject: [PATCH 1/8] comments: linkify and preprocess preview with correct 'page' param --- IkiWiki/Plugin/comments.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 644ef1be8..34bbafeed 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -432,8 +432,8 @@ sub sessioncgi ($$) { if ($form->submitted eq PREVIEW) { my $preview = IkiWiki::htmlize($location, $page, '_comment', - IkiWiki::linkify($page, $page, - IkiWiki::preprocess($page, $page, + IkiWiki::linkify($location, $page, + IkiWiki::preprocess($location, $page, IkiWiki::filter($location, $page, $content), 0, 1))); From 95b3bbbf7c786cc9e1dd7d7925ac75a0f525affd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:08:14 +0000 Subject: [PATCH 2/8] comments: run pagetemplate hooks This fixes the bug that comments are always said to be from an anonymous user at an unknown IP address. --- IkiWiki/Plugin/comments.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 34bbafeed..23e089761 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -447,6 +447,12 @@ sub sessioncgi ($$) { $template->param(title => $form->field('subject')); $template->param(ctime => displaytime(time)); + IkiWiki::run_hooks(pagetemplate => sub { + shift->(page => $location, + destpage => $page, + template => $template); + }); + $form->tmpl_param(page_preview => $template->output); } else { From 0844bd0b1567404243d95e616d3c7526e922822d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:23:59 +0000 Subject: [PATCH 3/8] beautify_urlpath: add ./ before checking for /index.html This fixes a bug: when a page links to its own #comments anchor you would get a link like "index.html#comments" rather than "./#comments". --- IkiWiki.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 47116089b..97c835cf6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -949,16 +949,16 @@ sub formattime ($;$) { sub beautify_urlpath ($) { my $url=shift; - if ($config{usedirs}) { - $url =~ s!/index.$config{htmlext}$!/!; - } - # Ensure url is not an empty link, and if necessary, # add ./ to avoid colon confusion. if ($url !~ /^\// && $url !~ /^\.\.\//) { $url="./$url"; } + if ($config{usedirs}) { + $url =~ s!/index.$config{htmlext}$!/!; + } + return $url; } From 5b1cf21a350ee6e3278b5279fbda9cd26ff8550d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:24:42 +0000 Subject: [PATCH 4/8] beautify_urlpath: if path already starts with ./, don't add another ./ --- IkiWiki.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 97c835cf6..6747a3ba4 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -951,7 +951,7 @@ sub beautify_urlpath ($) { # Ensure url is not an empty link, and if necessary, # add ./ to avoid colon confusion. - if ($url !~ /^\// && $url !~ /^\.\.\//) { + if ($url !~ /^\// && $url !~ /^\.\.?\//) { $url="./$url"; } From c42f174e655526bfaace70b31f9cbc79e2e1be9a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 15:24:53 +0000 Subject: [PATCH 5/8] beautify_urlpath: add a regression test --- t/beautify_urlpath.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 t/beautify_urlpath.t diff --git a/t/beautify_urlpath.t b/t/beautify_urlpath.t new file mode 100755 index 000000000..b9d3493a2 --- /dev/null +++ b/t/beautify_urlpath.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 7; + +BEGIN { use_ok("IkiWiki"); } + +$IkiWiki::config{usedirs} = 1; +$IkiWiki::config{htmlext} = "HTML"; +is(IkiWiki::beautify_urlpath("foo/bar"), "./foo/bar"); +is(IkiWiki::beautify_urlpath("../badger"), "../badger"); +is(IkiWiki::beautify_urlpath("./bleh"), "./bleh"); +is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/"); +is(IkiWiki::beautify_urlpath("index.HTML"), "./"); +$IkiWiki::config{usedirs} = 0; +is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/index.HTML"); From d0d598e429313756192927418757e2869004049e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 17:15:49 +0000 Subject: [PATCH 6/8] comments: substitute commentsurl and atomcommentsurl for use in feeds --- IkiWiki/Plugin/comments.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index 23e089761..0ae9eefe3 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -531,6 +531,8 @@ sub pagetemplate (@) { my $page = $params{page}; my $template = $params{template}; my $shown = ($template->query(name => 'commentslink') || + $template->query(name => 'commentsurl') || + $template->query(name => 'atomcommentsurl') || $template->query(name => 'comments')) && commentsshown($page); @@ -560,6 +562,22 @@ sub pagetemplate (@) { } } + if ($template->query(name => 'commentsurl')) { + if ($shown) { + $template->param(commentsurl => + urlto($page, undef, 1).'#comments'); + } + } + + if ($template->query(name => 'atomcommentsurl') && $config{usedirs}) { + if ($shown) { + # 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 From 3feebe31b61c04422c29d2e0c7c6f018b7772e29 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 17:16:12 +0000 Subject: [PATCH 7/8] atomitem.tmpl: include comments URLs (HTML and Atom versions) --- templates/atomitem.tmpl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/atomitem.tmpl b/templates/atomitem.tmpl index 1ff7f4f4e..768695a2c 100644 --- a/templates/atomitem.tmpl +++ b/templates/atomitem.tmpl @@ -39,4 +39,10 @@ + + " type="text/html" /> + + + " type="application/atom+xml" /> + From 9e5f504e1a9c428580c17e13fc1f76bc38727e3c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 21 Dec 2008 17:16:24 +0000 Subject: [PATCH 8/8] rssitem.tmpl: include comments URL (HTML only) --- templates/rssitem.tmpl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/rssitem.tmpl b/templates/rssitem.tmpl index 42936a668..a61b92b61 100644 --- a/templates/rssitem.tmpl +++ b/templates/rssitem.tmpl @@ -23,4 +23,7 @@ + + +