Pass a destpage parameter to the sanitize hook.

Because the search plugin needed it, also because it's one of the few
plugins that didn't already have it.

I also considered adding it to htmlize, but I really cannot imagine caring
what the destpage is when htmlizing. (I'll probably be poven wrong later.)
master
Joey Hess 2008-06-04 01:24:23 -04:00
parent 1546b48b97
commit 1dddec0ba9
15 changed files with 31 additions and 30 deletions

View File

@ -641,8 +641,9 @@ sub userlink ($) { #{{{
}
} #}}}
sub htmlize ($$$) { #{{{
sub htmlize ($$$$) { #{{{
my $page=shift;
my $destpage=shift;
my $type=shift;
my $content=shift;
@ -661,6 +662,7 @@ sub htmlize ($$$) { #{{{
run_hooks(sanitize => sub {
$content=shift->(
page => $page,
destpage => $destpage,
content => $content,
);
});

View File

@ -397,7 +397,7 @@ sub cgi_editpage ($$) { #{{{
);
});
$form->tmpl_param("page_preview",
htmlize($page, $type,
htmlize($page, $page, $type,
linkify($page, $page,
preprocess($page, $page,
filter($page, $page, $content), 0, 1))));

View File

@ -352,7 +352,7 @@ sub get_inline_content ($$) { #{{{
my $type=pagetype($file);
if (defined $type) {
$nested++;
my $ret=htmlize($page, $type,
my $ret=htmlize($page, $destpage, $type,
linkify($page, $destpage,
preprocess($page, $destpage,
filter($page, $destpage,

View File

@ -53,7 +53,7 @@ sub htmlize ($$$) { #{{{
my $page = shift;
my $destpage = shift;
return IkiWiki::htmlize($page, pagetype($pagesources{$page}),
return IkiWiki::htmlize($page, $destpage, pagetype($pagesources{$page}),
IkiWiki::linkify($page, $destpage,
IkiWiki::preprocess($page, $destpage, shift)));
}

View File

@ -57,7 +57,7 @@ my $scrubber;
sub index (@) { #{{{
my %params=@_;
return $params{content} if %IkiWiki::preprocessing;
return $params{content} if $IkiWiki::preprocessing{$params{destpage}};
my $db=xapiandb();
my $doc=Search::Xapian::Document->new();
@ -70,7 +70,7 @@ sub index (@) { #{{{
$title=IkiWiki::pagetitle($params{page});
}
# Remove any html from text to be indexed.
# Remove html from text to be indexed.
if (! defined $scrubber) {
eval q{use HTML::Scrubber};
if (! $@) {

View File

@ -27,7 +27,7 @@ sub sidebar_content ($) { #{{{
my $content=readfile(srcfile($sidebar_file));
return unless length $content;
return IkiWiki::htmlize($page, $sidebar_type,
return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type,
IkiWiki::linkify($sidebar_page, $page,
IkiWiki::preprocess($sidebar_page, $page,
IkiWiki::filter($sidebar_page, $page, $content))));

View File

@ -175,7 +175,7 @@ sub htmlize ($$$) { #{{{
my $page = shift;
my $destpage = shift;
return IkiWiki::htmlize($page, pagetype($pagesources{$page}),
return IkiWiki::htmlize($page, $destpage, pagetype($pagesources{$page}),
IkiWiki::preprocess($page, $destpage, shift));
}

View File

@ -48,7 +48,7 @@ sub preprocess (@) { #{{{
foreach my $param (keys %params) {
if ($template->query(name => $param)) {
$template->param($param =>
IkiWiki::htmlize($params{page},
IkiWiki::htmlize($params{page}, $params{destpage},
pagetype($pagesources{$params{page}}),
$params{$param}));
}

View File

@ -191,7 +191,7 @@ sub render ($) { #{{{
will_render($page, htmlpage($page), 1);
return if $type=~/^_/;
my $content=htmlize($page, $type,
my $content=htmlize($page, $page, $type,
linkify($page, $page,
preprocess($page, $page,
filter($page, $page,
@ -520,7 +520,7 @@ sub commandline_render () { #{{{
$content=filter($page, $page, $content);
$content=preprocess($page, $page, $content);
$content=linkify($page, $page, $content);
$content=htmlize($page, $type, $content);
$content=htmlize($page, $page, $type, $content);
$pagemtime{$page}=(stat($srcfile))[9];
print genpage($page, $content);

1
debian/changelog vendored
View File

@ -8,6 +8,7 @@ ikiwiki (2.49) UNRELEASED; urgency=low
* Filter hooks are no longer called during the scan phase. This will
prevent wikilinks added by filters from being scanned properly. But
no known filter hook does that, so let's not waste time on it.
* Pass a destpage parameter to the sanitize hook.
-- Joey Hess <joeyh@debian.org> Fri, 30 May 2008 19:08:54 -0400

View File

@ -7,11 +7,9 @@ This plugin adds full text search to ikiwiki, using the
and the [[cpan Search::Xapian]] perl module. (The [[cpan HTML::Scrubber]]
perl module will also be used, if available.)
Ikiwiki will handle indexing new and changed page contents. Note that it
indexes page contents before they are preprocessed and converted to html,
as this tends to produce less noisy search results. Also, since it only
indexes page contents, files copied by the [[rawhtml]] plugin will not be
indexed, nor will other types of data files.
Ikiwiki will handle indexing new and changed page contents. Note that since
it only indexes page contents, files copied by the [[rawhtml]] plugin will
not be indexed, nor will other types of data files.
There is one setting you may need to use in the config file. `omega_cgi`
should point to the location of the omega cgi program. The default location

View File

@ -211,8 +211,8 @@ want to change the default ("page.tmpl"). Template files are looked for in
Use this to implement html sanitization or anything else that needs to
modify the body of a page after it has been fully converted to html.
The function is passed named parameters: "page" and "content", and
should return the sanitized content.
The function is passed named parameters: "page", "destpage", and "content",
and should return the sanitized content.
### format

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-06-04 00:52-0400\n"
"POT-Creation-Date: 2008-06-04 01:17-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -707,7 +707,7 @@ msgstr ""
#. translators: preprocessor directive name,
#. translators: the second a page name, the
#. translators: third a number.
#: ../IkiWiki.pm:761
#: ../IkiWiki.pm:763
#, perl-format
msgid "%s preprocessing loop detected on %s at depth %i"
msgstr ""

View File

@ -13,6 +13,6 @@ BEGIN { use_ok("IkiWiki"); }
%config=IkiWiki::defaultconfig();
$config{srcdir}=$config{destdir}="/dev/null";
IkiWiki::loadplugins(); IkiWiki::checkconfig();
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test1.mdwn")));
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test3.mdwn")),
ok(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test1.mdwn")));
ok(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test3.mdwn")),
"wtf?") for 1..100;

View File

@ -12,16 +12,16 @@ $config{srcdir}=$config{destdir}="/dev/null";
IkiWiki::loadplugins();
IkiWiki::checkconfig();
is(IkiWiki::htmlize("foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
is(IkiWiki::htmlize("foo", "foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
"basic");
is(IkiWiki::htmlize("foo", "mdwn", readfile("t/test1.mdwn")),
is(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test1.mdwn")),
Encode::decode_utf8(qq{<p><img src="../images/o.jpg" alt="o" title="&oacute;" />\nóóóóó</p>\n}),
"utf8; bug #373203");
ok(IkiWiki::htmlize("foo", "mdwn", readfile("t/test2.mdwn")),
ok(IkiWiki::htmlize("foo", "foo", "mdwn", readfile("t/test2.mdwn")),
"this file crashes markdown if it's fed in as decoded utf-8");
sub gotcha {
my $html=IkiWiki::htmlize("foo", "mdwn", shift);
my $html=IkiWiki::htmlize("foo", "foo", "mdwn", shift);
return $html =~ /GOTCHA/;
}
ok(!gotcha(q{<a href="javascript:alert('GOTCHA')">click me</a>}),
@ -56,15 +56,15 @@ ok(gotcha(q{<p>javascript:alert('GOTCHA')</p>}),
be perverse and assume it is?)");
ok(gotcha(q{<img src="javascript.png?GOTCHA">}), "not javascript");
ok(gotcha(q{<a href="javascript.png?GOTCHA">foo</a>}), "not javascript");
is(IkiWiki::htmlize("foo", "mdwn",
is(IkiWiki::htmlize("foo", "foo", "mdwn",
q{<img alt="foo" src="foo.gif">}),
q{<img alt="foo" src="foo.gif">}, "img with alt tag allowed");
is(IkiWiki::htmlize("foo", "mdwn",
is(IkiWiki::htmlize("foo", "foo", "mdwn",
q{<a href="http://google.com/">}),
q{<a href="http://google.com/">}, "absolute url allowed");
is(IkiWiki::htmlize("foo", "mdwn",
is(IkiWiki::htmlize("foo", "foo", "mdwn",
q{<a href="foo.html">}),
q{<a href="foo.html">}, "relative url allowed");
is(IkiWiki::htmlize("foo", "mdwn",
is(IkiWiki::htmlize("foo", "foo", "mdwn",
q{<span class="foo">bar</span>}),
q{<span class="foo">bar</span>}, "class attribute allowed");