summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/comments.pm2
-rw-r--r--IkiWiki/Plugin/editpage.pm2
-rw-r--r--IkiWiki/Plugin/edittemplate.pm22
-rw-r--r--IkiWiki/Plugin/google.pm2
-rw-r--r--IkiWiki/Plugin/inline.pm27
-rw-r--r--IkiWiki/Plugin/search.pm2
-rw-r--r--IkiWiki/Plugin/template.pm37
-rw-r--r--IkiWiki/Plugin/underlay.pm11
-rw-r--r--IkiWiki/Render.pm21
9 files changed, 56 insertions, 70 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 58bd4b851..ed75a6e46 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -274,7 +274,7 @@ sub editcomment ($$) {
action => $config{cgiurl},
header => 0,
table => 0,
- template => scalar IkiWiki::template_params('editcomment.tmpl'),
+ template => template('editcomment.tmpl'),
);
IkiWiki::decode_form_utf8($form);
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 26e38abc1..5c94ecbca 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -78,7 +78,7 @@ sub cgi_editpage ($$) {
action => $config{cgiurl},
header => 0,
table => 0,
- template => scalar template_params("editpage.tmpl"),
+ template => template("editpage.tmpl"),
);
decode_form_utf8($form);
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index 5f0551d92..d65072010 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -114,28 +114,18 @@ sub filltemplate ($$) {
my $template_page=shift;
my $page=shift;
- my $template_file=$pagesources{$template_page};
- if (! defined $template_file) {
- return;
- }
-
my $template;
eval {
- $template=HTML::Template->new(
- filter => sub {
- my $text_ref = shift;
- $$text_ref=&Encode::decode_utf8($$text_ref);
- chomp $$text_ref;
- },
- filename => srcfile($template_file),
- die_on_bad_params => 0,
- no_includes => 1,
- );
+ # force page name absolute so it doesn't look in templates/
+ $template=template("/".$template_page);
};
if ($@) {
# Indicate that the earlier preprocessor directive set
# up a template that doesn't work.
- return "[[!pagetemplate ".gettext("failed to process")." $@]]";
+ return "[[!pagetemplate ".gettext("failed to process template:")." $@]]";
+ }
+ if (! defined $template) {
+ return;
}
$template->param(name => $page);
diff --git a/IkiWiki/Plugin/google.pm b/IkiWiki/Plugin/google.pm
index 48ad4c8ce..68cb16513 100644
--- a/IkiWiki/Plugin/google.pm
+++ b/IkiWiki/Plugin/google.pm
@@ -36,7 +36,7 @@ sub pagetemplate (@) {
# Add search box to page header.
if ($template->query(name => "searchform")) {
if (! defined $form) {
- my $searchform = template("googleform.tmpl", blind_cache => 1);
+ my $searchform = template_depends("googleform.tmpl", $page, blind_cache => 1);
$searchform->param(url => $config{url});
$form=$searchform->output;
}
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 3359af314..95fe90312 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -299,7 +299,7 @@ sub preprocess_inline (@) {
(exists $params{postform} && yesno($params{postform}))) &&
IkiWiki->can("cgi_editpage")) {
# Add a blog post form, with feed buttons.
- my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
+ my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
$formtemplate->param(cgiurl => $config{cgiurl});
$formtemplate->param(rootpage => rootpage(%params));
$formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
@@ -320,19 +320,28 @@ sub preprocess_inline (@) {
}
elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
# Add feed buttons.
- my $linktemplate=template("feedlink.tmpl", blind_cache => 1);
+ my $linktemplate=template_depends("feedlink.tmpl", $params{page}, blind_cache => 1);
$linktemplate->param(rssurl => $rssurl) if $rss;
$linktemplate->param(atomurl => $atomurl) if $atom;
$ret.=$linktemplate->output;
}
if (! $feedonly) {
- require HTML::Template;
- my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1);
- if (! @params) {
- error sprintf(gettext("nonexistant template %s"), $params{template});
+ my $template;
+ if (! $raw) {
+ # cannot use wiki pages as templates; template not sanitized due to
+ # format hook hack
+ eval {
+ $template=template_depends($params{template}.".tmpl", $params{page},
+ blind_cache => 1);
+ };
+ if ($@) {
+ error gettext("failed to process template:")." $@";
+ }
+ if (! $template) {
+ error sprintf(gettext("template %s not found"), $params{template}.".tmpl");
+ }
}
- my $template=HTML::Template->new(@params) unless $raw;
my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
foreach my $page (@list) {
@@ -534,7 +543,7 @@ sub genfeed ($$$$$@) {
my $url=URI->new(encode_utf8(urlto($page,"",1)));
- my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
+ my $itemtemplate=template_depends($feedtype."item.tmpl", $page, blind_cache => 1);
my $content="";
my $lasttime = 0;
foreach my $p (@pages) {
@@ -598,7 +607,7 @@ sub genfeed ($$$$$@) {
$lasttime = $pagemtime{$p} if $pagemtime{$p} > $lasttime;
}
- my $template=template($feedtype."page.tmpl", blind_cache => 1);
+ my $template=template_depends($feedtype."page.tmpl", $page, blind_cache => 1);
$template->param(
title => $page ne "index" ? pagetitle($page) : $config{wikiname},
wikiname => $config{wikiname},
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm
index a1e7026ca..55edf8752 100644
--- a/IkiWiki/Plugin/search.pm
+++ b/IkiWiki/Plugin/search.pm
@@ -52,7 +52,7 @@ sub pagetemplate (@) {
# Add search box to page header.
if ($template->query(name => "searchform")) {
if (! defined $form) {
- my $searchform = template("searchform.tmpl", blind_cache => 1);
+ my $searchform = template_depends("searchform.tmpl", $page, blind_cache => 1);
$searchform->param(searchaction => $config{cgiurl});
$form=$searchform->output;
}
diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm
index 98a13b5fa..d2b2fef55 100644
--- a/IkiWiki/Plugin/template.pm
+++ b/IkiWiki/Plugin/template.pm
@@ -5,7 +5,6 @@ package IkiWiki::Plugin::template;
use warnings;
use strict;
use IkiWiki 3.00;
-use HTML::Template;
use Encode;
sub import {
@@ -34,36 +33,20 @@ sub preprocess (@) {
error gettext("missing id parameter")
}
- my $template_page="templates/$params{id}";
- add_depends($params{page}, $template_page);
-
- my $template_file;
- if (exists $pagesources{$template_page}) {
- $template_file=srcfile($pagesources{$template_page});
- }
- else {
- $template_file=IkiWiki::template_file("$params{id}.tmpl")
- }
- return sprintf(gettext("template %s not found"),
- htmllink($params{page}, $params{destpage}, "/".$template_page))
- unless defined $template_file;
-
+ # The bare id is used, so a page templates/$id can be used as
+ # the template.
my $template;
eval {
- $template=HTML::Template->new(
- filter => sub {
- my $text_ref = shift;
- $$text_ref=&Encode::decode_utf8($$text_ref);
- chomp $$text_ref;
- },
- filename => $template_file,
- die_on_bad_params => 0,
- no_includes => 1,
- blind_cache => 1,
- );
+ $template=template_depends($params{id}, $params{page},
+ blind_cache => 1);
};
if ($@) {
- error gettext("failed to process:")." $@"
+ error gettext("failed to process template:")." $@";
+ }
+ if (! $template) {
+ error sprintf(gettext("%s not found"),
+ htmllink($params{page}, $params{destpage},
+ "/templates/$params{id}"))
}
$params{basename}=IkiWiki::basename($params{page});
diff --git a/IkiWiki/Plugin/underlay.pm b/IkiWiki/Plugin/underlay.pm
index 116fe7324..3ea19c635 100644
--- a/IkiWiki/Plugin/underlay.pm
+++ b/IkiWiki/Plugin/underlay.pm
@@ -27,14 +27,6 @@ sub getsetup () {
safe => 0,
rebuild => 1,
},
- add_templates => {
- type => "string",
- example => ["$ENV{HOME}/.ikiwiki/templates"],
- description => "extra template directories to add",
- advanced => 1,
- safe => 0,
- rebuild => 1,
- },
}
sub checkconfig () {
@@ -43,9 +35,6 @@ sub checkconfig () {
add_underlay($dir);
}
}
- if ($config{add_templates}) {
- push @{$config{templatedirs}}, @{$config{add_templates}};
- }
}
1;
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 49d080c16..8ae0cbd4f 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -74,7 +74,16 @@ sub genpage ($$) {
$templatefile=$file;
}
});
- my $template=template(defined $templatefile ? $templatefile : 'page.tmpl', blind_cache => 1);
+ my $template;
+ if (defined $templatefile) {
+ $template=template_depends($templatefile, $page,
+ blind_cache => 1);
+ }
+ else {
+ # no explicit depends as special case
+ $template=template('page.tmpl',
+ blind_cache => 1);
+ }
my $actions=0;
if (length $config{cgiurl}) {
@@ -761,8 +770,14 @@ sub refresh () {
foreach my $file (@$new, @$del) {
render_linkers($file);
}
-
- if (@$changed || @$internal_changed ||
+
+ if ($rendered{"templates/page.tmpl"}) {
+ foreach my $f (@$files) {
+ next if $f eq "templates/page.tmpl";
+ render($f, sprintf(gettext("building %s, which depends on %s"), $f, "templates/page.tmpl"));
+ }
+ }
+ elsif (@$changed || @$internal_changed ||
@$del || @$internal_del || @$internal_new) {
1 while render_dependent($files, $new, $internal_new,
$del, $internal_del, $internal_changed,