2007-07-26 22:50:55 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::pagetemplate;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki 2.00;
|
|
|
|
|
|
|
|
my %templates;
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "pagetemplate", call => \&getsetup);
|
2007-07-26 22:50:55 +02:00
|
|
|
hook(type => "preprocess", id => "pagetemplate", call => \&preprocess);
|
|
|
|
hook(type => "templatefile", id => "pagetemplate", call => \&templatefile);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2007-07-26 22:50:55 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 23:20:21 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 23:20:21 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2007-07-26 22:50:55 +02:00
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
if (! exists $params{template} ||
|
|
|
|
$params{template} !~ /^[-A-Za-z0-9._+]+$/ ||
|
|
|
|
! defined IkiWiki::template_file($params{template})) {
|
2008-07-13 21:05:34 +02:00
|
|
|
error gettext("bad or missing template")
|
2007-07-26 22:50:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($params{page} eq $params{destpage}) {
|
|
|
|
$templates{$params{page}}=$params{template};
|
|
|
|
}
|
|
|
|
|
2007-08-05 20:22:21 +02:00
|
|
|
return "";
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2007-07-26 22:50:55 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub templatefile (@) {
|
2007-07-26 22:50:55 +02:00
|
|
|
my %params=@_;
|
|
|
|
|
|
|
|
if (exists $templates{$params{page}}) {
|
|
|
|
return $templates{$params{page}};
|
|
|
|
}
|
|
|
|
|
|
|
|
return undef;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2007-07-26 22:50:55 +02:00
|
|
|
|
|
|
|
1
|