2 package IkiWiki::Plugin::edittemplate;
9 hook(type => "needsbuild", id => "edittemplate",
10 call => \&needsbuild);
11 hook(type => "preprocess", id => "edittemplate",
12 call => \&preprocess);
13 hook(type => "formbuilder_setup", id => "edittemplate",
14 call => \&formbuilder_setup);
17 sub needsbuild (@) { #{{{
20 foreach my $page (keys %pagestate) {
21 if (exists $pagestate{$page}{edittemplate}) {
22 if (grep { $_ eq $pagesources{$page} } @$needsbuild) {
23 # remove state, it will be re-added
24 # if the preprocessor directive is still
25 # there during the rebuild
26 delete $pagestate{$page}{edittemplate};
32 sub preprocess (@) { #{{{
35 return "" if $params{page} ne $params{destpage};
37 if (! exists $params{template} || ! length($params{template})) {
38 return return "[[meta ".gettext("template not specified")."]]";
40 if (! exists $params{match} || ! length($params{match})) {
41 return return "[[meta ".gettext("match not specified")."]]";
44 $pagestate{$params{page}}{edittemplate}{$params{match}}=$params{template};
46 return sprintf(gettext("edittemplate %s registered for %s"),
47 $params{template}, $params{match});
50 sub formbuilder_setup { #{{{
52 my $form=$params{form};
53 my $page=$form->field("page");
55 return if $form->title ne "editpage"
56 || $form->field("do") ne "create";
58 $form->field(name => "editcontent", value => "hi mom!");