From: Joey Hess Date: Wed, 4 Jun 2008 05:24:23 +0000 (-0400) Subject: Pass a destpage parameter to the sanitize hook. X-Git-Tag: 2.49~21 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1dddec0ba9f66f082f4b8349916cdb6bdb5636e3;p=ikiwiki.git 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.) --- diff --git a/IkiWiki.pm b/IkiWiki.pm index 3f92bda06..a9debfb7d 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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, ); }); diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 532f9c5f6..8a294e887 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -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)))); diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 7d81e9182..344620ebe 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -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, diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 0afe1c362..e2914a78a 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -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))); } diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index 3dc70f0b7..aa0a8085e 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -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 (! $@) { diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index a49726768..7c2e6e1f6 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -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)))); diff --git a/IkiWiki/Plugin/table.pm b/IkiWiki/Plugin/table.pm index 20c71e1c7..11474c8f0 100644 --- a/IkiWiki/Plugin/table.pm +++ b/IkiWiki/Plugin/table.pm @@ -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)); } diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm index 416762fe1..a6e34fcc9 100644 --- a/IkiWiki/Plugin/template.pm +++ b/IkiWiki/Plugin/template.pm @@ -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})); } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 3422024d1..272eb239a 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -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); diff --git a/debian/changelog b/debian/changelog index c667142a2..34112ab26 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Fri, 30 May 2008 19:08:54 -0400 diff --git a/doc/plugins/search.mdwn b/doc/plugins/search.mdwn index 67e3b85ef..e53c28c7c 100644 --- a/doc/plugins/search.mdwn +++ b/doc/plugins/search.mdwn @@ -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 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 606031cf2..35f391f7f 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -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 diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index 9d791153f..f65f42212 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/t/crazy-badass-perl-bug.t b/t/crazy-badass-perl-bug.t index 27812559b..80724d174 100755 --- a/t/crazy-badass-perl-bug.t +++ b/t/crazy-badass-perl-bug.t @@ -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; diff --git a/t/htmlize.t b/t/htmlize.t index b19dbcf68..a7e7f8c39 100755 --- a/t/htmlize.t +++ b/t/htmlize.t @@ -12,16 +12,16 @@ $config{srcdir}=$config{destdir}="/dev/null"; IkiWiki::loadplugins(); IkiWiki::checkconfig(); -is(IkiWiki::htmlize("foo", "mdwn", "foo\n\nbar\n"), "

foo

\n\n

bar

\n", +is(IkiWiki::htmlize("foo", "foo", "mdwn", "foo\n\nbar\n"), "

foo

\n\n

bar

\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{

o\nóóóóó

\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{click me}), @@ -56,15 +56,15 @@ ok(gotcha(q{

javascript:alert('GOTCHA')

}), be perverse and assume it is?)"); ok(gotcha(q{}), "not javascript"); ok(gotcha(q{foo}), "not javascript"); -is(IkiWiki::htmlize("foo", "mdwn", +is(IkiWiki::htmlize("foo", "foo", "mdwn", q{foo}), q{foo}, "img with alt tag allowed"); -is(IkiWiki::htmlize("foo", "mdwn", +is(IkiWiki::htmlize("foo", "foo", "mdwn", q{}), q{}, "absolute url allowed"); -is(IkiWiki::htmlize("foo", "mdwn", +is(IkiWiki::htmlize("foo", "foo", "mdwn", q{}), q{}, "relative url allowed"); -is(IkiWiki::htmlize("foo", "mdwn", +is(IkiWiki::htmlize("foo", "foo", "mdwn", q{bar}), q{bar}, "class attribute allowed");