remove unnecessary and troublesome filter calls

This better defines what the filter hook is passed, to only be the raw,
complete text of a page. Not some snippet, or data read in from an
unrelated template.

Several plugins that filtered text that originates from an (already
filtered) page were modified not to do that. Note that this was not
done very consistently before; other plugins that receive text from a
page called preprocess on it w/o first calling filter.

The template plugin gets text from elsewhere, and was also changed not to
filter it. That leads to one known regression -- the embed plugin cannot
be used to embed stuff in templates now. But that plugin is deprecated
anyway.

Later we may want to increase the coverage of what is filtered. Perhaps
a good goal would be to allow writing a filter plugin that filters
out unwanted words, from any input. We're not there yet; not only
does the template plugin load unfiltered text from its templates now,
but so can the table plugin, and other plugins that use templates (like
inline!). I think we can cross that bridge when we come to it. If I wanted
such a censoring plugin, I'd probably make it use a sanitize hook instead,
for the better coverage.

For now I am concentrating on the needs of the two non-deprecated users
of filter. This should fix bugs/po_vs_templates, and it probably fixes
an obscure bug around txt's use of filter for robots.txt.
master
Joey Hess 2010-07-04 15:00:51 -04:00
parent 1b14a849ff
commit 192ce7a238
9 changed files with 19 additions and 27 deletions

View File

@ -61,12 +61,11 @@ sub replace_preserved_style ($) {
sub preprocess (@) {
my %params = @_;
# Preprocess the text to expand any preprocessor directives
# embedded inside it.
$params{text} = IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $params{text}));
return preserve_style($params{foreground}, $params{background}, $params{text});
return preserve_style($params{foreground}, $params{background},
# Preprocess the text to expand any preprocessor directives
# embedded inside it.
IkiWiki::preprocess($params{page}, $params{destpage},
$params{text}));
}
sub format (@) {

View File

@ -142,8 +142,6 @@ sub preprocess {
}
$content =~ s/\\"/"/g;
$content = IkiWiki::filter($page, $params{destpage}, $content);
if ($config{comments_allowdirectives}) {
$content = IkiWiki::preprocess($page, $params{destpage},
$content);

View File

@ -59,8 +59,7 @@ sub preprocess_if (@) {
else {
$ret="";
}
return IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $ret));
return IkiWiki::preprocess($params{page}, $params{destpage}, $ret);
}
package IkiWiki::PageSpec;

View File

@ -50,8 +50,8 @@ sub preprocess_copy (@) {
$savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
$savedtext{$params{page}}->{$params{id}} = $params{text};
return IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
return IkiWiki::preprocess($params{page}, $params{destpage}, $params{text})
if defined wantarray;
}
sub preprocess_paste (@) {
@ -70,8 +70,8 @@ sub preprocess_paste (@) {
error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
}
return IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));
return IkiWiki::preprocess($params{page}, $params{destpage},
$savedtext{$params{page}}->{$params{id}});
}
1;

View File

@ -33,9 +33,9 @@ sub preprocess (@) {
anchor => "more");
}
else {
$params{text}=IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $params{text}));
return "<a name=\"more\"></a>\n\n".$params{text};
return "<a name=\"more\"></a>\n\n".
IkiWiki::preprocess($params{page}, $params{destpage},
$params{text});
}
}

View File

@ -47,8 +47,7 @@ sub preprocess (@) {
$pagesidebar{$page}=
IkiWiki::htmlize($page, $page, $type,
IkiWiki::linkify($page, $page,
IkiWiki::preprocess($page, $page,
IkiWiki::filter($page, $page, $params{content}))));
IkiWiki::preprocess($page, $page, $params{content})));
}
return "";

View File

@ -53,8 +53,7 @@ sub preprocess (@) {
foreach my $param (keys %params) {
my $value=IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage},
$params{$param}), $scan);
$params{$param}, $scan);
if ($template->query(name => $param)) {
my $htmlvalue=IkiWiki::htmlize($params{page}, $params{destpage},
pagetype($pagesources{$params{page}}),
@ -69,8 +68,7 @@ sub preprocess (@) {
}
return IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage},
$template->output), $scan);
$template->output, $scan);
}
1

View File

@ -50,8 +50,7 @@ sub preprocess_toggleable (@) {
# Preprocess the text to expand any preprocessor directives
# embedded inside it.
$params{text}=IkiWiki::preprocess($params{page}, $params{destpage},
IkiWiki::filter($params{page}, $params{destpage}, $params{text}));
$params{text}=IkiWiki::preprocess($params{page}, $params{destpage}, $params{text});
my $id=genid($params{page}, $params{id});
my $class=(lc($params{open}) ne "yes") ? "toggleable" : "toggleable-open";

View File

@ -198,8 +198,8 @@ value is ignored.
hook(type => "filter", id => "foo", call => \&filter);
Runs on the raw source of a page, before anything else touches it, and can
make arbitrary changes. The function is passed named parameters "page",
Runs on the full raw source of a page, before anything else touches it, and
can make arbitrary changes. The function is passed named parameters "page",
"destpage", and "content". It should return the filtered content.
### preprocess