wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / templates.pl
blob1c2d4aa6113bed10b32005b98cd41c08807f5f01
1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/templates.pl">templates.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Template_Extension">Template Extension</a></p>';
21 # Any page with a name ending in "Template" is a valid template.
22 # When creating a page, the $EditNote is prefixed with a list of
23 # available templates. When the user clicks on one of the links,
24 # The text area is filled with the template.
26 $Action{'edit'} = \&TemplateDoEdit;
28 use vars qw($TemplatePattern);
30 $TemplatePattern = q{Template$}; # strange quoting because of cperl-mode ;)
32 sub TemplateDoEdit {
33 my ($id, $newText, $preview) = @_;
34 AllPagesList(); # prepare %IndexHash
35 if (not $IndexHash{$id}) {
36 local $EditNote = TemplateList($id) . $EditNote;
37 if (GetParam('template', '') and $IndexHash{GetParam('template', '')}) {
38 return DoEdit($id, GetPageContent(GetParam('template', '')), 1);
39 } else {
40 return DoEdit($id, $newText, $preview); # call with localized $EditNote
43 DoEdit($id, $newText, $preview); # catch all
46 sub TemplateList {
47 my $id = shift;
48 my @list = map {
49 my $page = $_;
50 my $name = $_;
51 $name =~ s/_/ /g;
52 ScriptLink("action=edit;id=$id;template=$page", $name);
53 } grep(/$TemplatePattern/, AllPagesList());
54 return $q->div({-class=>'templates'},
55 $q->p(T('Alternatively, use one of the following templates:')),
56 $q->ul($q->li(\@list))) if @list;