sub template_file ($) {
my $name=shift;
-
- my $template=srcfile("templates/$name", 1);
- return $template if defined $template;
- foreach my $dir ($config{templatedir},
- "$installdir/share/ikiwiki/templates") {
- return "$dir/$name" if -e "$dir/$name";
+ my $tpage=($name =~ /^\//) ? $name : "templates/$name";
+ if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) {
+ $tpage=$pagesources{$tpage};
+ $name.=".tmpl";
+ }
+
+ my $template=srcfile($tpage, 1);
+ if (! defined $template) {
+ $name=~s:/::; # avoid path traversal
+ foreach my $dir ($config{templatedir},
+ "$installdir/share/ikiwiki/templates") {
+ if (-e "$dir/$name") {
+ $template="$dir/$name";
+ last;
+ }
+ }
}
- return;
-}
-sub template ($;@) {
- template_depends(shift, undef, @_);
+ if (defined $template) {
+ return $template, $tpage if wantarray;
+ return $template;
+ }
+ return;
}
sub template_depends ($$;@) {
my $name=shift;
my $page=shift;
-
- if (defined $page) {
- add_depends($page, "templates/$name");
+
+ my ($filename, $tpage)=template_file($name);
+ if (defined $page && defined $tpage) {
+ add_depends($page, $tpage);
}
- my $filename=template_file($name);
+
+ return unless defined $filename;
require HTML::Template;
return HTML::Template->new(
);
}
+sub template ($;@) {
+ template_depends(shift, undef, @_);
+}
+
sub misctemplate ($$;@) {
my $title=shift;
my $pagebody=shift;