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