]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/pagetemplate.pm
smiley: Detect smileys inside pre and tags, and do not expand.
[ikiwiki.git] / IkiWiki / Plugin / pagetemplate.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::pagetemplate;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 my %templates;
9
10 sub import { #{{{
11         hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
12         hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
13 } # }}}
14
15 sub preprocess (@) { #{{{
16         my %params=@_;
17
18         if (! exists $params{template} ||
19             $params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
20             ! defined IkiWiki::template_file($params{template})) {
21                  return "[[pagetemplate ".gettext("bad or missing template")."]]";
22         }
23
24         if ($params{page} eq $params{destpage}) {
25                 $templates{$params{page}}=$params{template};
26         }
27
28         return "";
29 } # }}}
30
31 sub templatefile (@) { #{{{
32         my %params=@_;
33
34         if (exists $templates{$params{page}}) {
35                 return $templates{$params{page}};
36         }
37         
38         return undef;
39 } # }}}
40
41 1