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 $page=shift;
my $destpage=shift;
my $type=shift; my $type=shift;
my $content=shift; my $content=shift;
@ -661,6 +662,7 @@ sub htmlize ($$$) { #{{{
run_hooks(sanitize => sub { run_hooks(sanitize => sub {
$content=shift->( $content=shift->(
page => $page, page => $page,
destpage => $destpage,
content => $content, content => $content,
); );
}); });

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -191,7 +191,7 @@ sub render ($) { #{{{
will_render($page, htmlpage($page), 1); will_render($page, htmlpage($page), 1);
return if $type=~/^_/; return if $type=~/^_/;
my $content=htmlize($page, $type, my $content=htmlize($page, $page, $type,
linkify($page, $page, linkify($page, $page,
preprocess($page, $page, preprocess($page, $page,
filter($page, $page, filter($page, $page,
@ -520,7 +520,7 @@ sub commandline_render () { #{{{
$content=filter($page, $page, $content); $content=filter($page, $page, $content);
$content=preprocess($page, $page, $content); $content=preprocess($page, $page, $content);
$content=linkify($page, $page, $content); $content=linkify($page, $page, $content);
$content=htmlize($page, $type, $content); $content=htmlize($page, $page, $type, $content);
$pagemtime{$page}=(stat($srcfile))[9]; $pagemtime{$page}=(stat($srcfile))[9];
print genpage($page, $content); 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 * Filter hooks are no longer called during the scan phase. This will
prevent wikilinks added by filters from being scanned properly. But prevent wikilinks added by filters from being scanned properly. But
no known filter hook does that, so let's not waste time on it. 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 -- 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]] and the [[cpan Search::Xapian]] perl module. (The [[cpan HTML::Scrubber]]
perl module will also be used, if available.) perl module will also be used, if available.)
Ikiwiki will handle indexing new and changed page contents. Note that it Ikiwiki will handle indexing new and changed page contents. Note that since
indexes page contents before they are preprocessed and converted to html, it only indexes page contents, files copied by the [[rawhtml]] plugin will
as this tends to produce less noisy search results. Also, since it only not be indexed, nor will other types of data files.
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` 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 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 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. modify the body of a page after it has been fully converted to html.
The function is passed named parameters: "page" and "content", and The function is passed named parameters: "page", "destpage", and "content",
should return the sanitized content. and should return the sanitized content.
### format ### format

View File

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

View File

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

View File

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