allow template pages to not be under templates/

master
Joey Hess 2010-04-23 15:02:07 -04:00
parent ee8d237f98
commit 78fd3b35a2
2 changed files with 11 additions and 7 deletions

View File

@ -1654,7 +1654,7 @@ sub saveindex () {
sub template_file ($) { sub template_file ($) {
my $name=shift; my $name=shift;
my $tpage="templates/$name"; my $tpage=($name =~ /^\//) ? $name : "templates/$name";
if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) { if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) {
$tpage=$pagesources{$tpage}; $tpage=$pagesources{$tpage};
$name.=".tmpl"; $name.=".tmpl";
@ -1665,6 +1665,8 @@ sub template_file ($) {
return $template, $tpage if wantarray; return $template, $tpage if wantarray;
return $template; return $template;
} }
$name=~s:/::; # avoid path traversal
foreach my $dir ($config{templatedir}, foreach my $dir ($config{templatedir},
"$installdir/share/ikiwiki/templates") { "$installdir/share/ikiwiki/templates") {

View File

@ -705,12 +705,14 @@ Creates and returns a [[!cpan HTML::Template]] object. The first parameter
is the name of the template file. The optional remaining parameters are is the name of the template file. The optional remaining parameters are
passed to `HTML::Template->new`. passed to `HTML::Template->new`.
The template file is first looked for in the templates/ subdirectory of the Normally, the template file is first looked for in the templates/ subdirectory
srcdir. Failing that, it is looked for in the templatedir. Typically of the srcdir. Failing that, it is looked for in the templatedir.
the filename will have a ".tmpl" extension. If a filename with no extension
is passed, a wiki page in templates/ with its name is used as the template. Wiki pages can be used as templates. This should be done only for templates
That should only be done for templates which it is safe to let wiki users which it is safe to let wiki users edit. Enable it by passing a filename
edit. with no ".tmpl" extension. Template pages are normally looked for in
the templates/ directory. If the page name starts with "/", a page
elsewhere in the wiki can be used.
### `template_depends($$;@)` ### `template_depends($$;@)`