Merge commit 'smcv/comments'

master
Joey Hess 2008-12-21 12:50:30 -05:00
commit 9bee6db8c6
5 changed files with 56 additions and 7 deletions

View File

@ -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 !~ /^\.\.\//) {
if ($url !~ /^\// && $url !~ /^\.\.?\//) {
$url="./$url";
}
if ($config{usedirs}) {
$url =~ s!/index.$config{htmlext}$!/!;
}
return $url;
}

View File

@ -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)));
@ -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 {
@ -525,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);
@ -554,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

View File

@ -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");

View File

@ -39,4 +39,10 @@
<TMPL_VAR CONTENT ESCAPE=HTML>
</content>
</TMPL_IF>
<TMPL_IF NAME="COMMENTSURL">
<link rel="comments" href="<TMPL_VAR NAME="COMMENTSURL">" type="text/html" />
</TMPL_IF>
<TMPL_IF NAME="ATOMCOMMENTSURL">
<link rel="comments" href="<TMPL_VAR NAME="ATOMCOMMENTSURL">" type="application/atom+xml" />
</TMPL_IF>
</entry>

View File

@ -23,4 +23,7 @@
<TMPL_ELSE>
<description><TMPL_VAR CONTENT ESCAPE=HTML></description>
</TMPL_IF>
<TMPL_IF NAME="COMMENTSURL">
<comments><TMPL_VAR NAME="COMMENTSURL"></comments>
</TMPL_IF>
</item>