fix IkiWiki/Plugin/createpage.pm
[cyclowiki.git] / .ikiwiki / lib / IkiWiki / Plugin / createpage.pm
1 #!/usr/bin/perl
2 # This file is une extension à IkiWiki
3 # permettant d’ajouter une action de création de page aux pages.
4 # Copyright (C) 2014 Julien Moutinho
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published
8 # by the Free Software Foundation, either version 3 of the License,
9 # or any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty
13 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package IkiWiki::Plugin::createpage;
19 use strict;
20 use utf8;
21 use warnings;
22 use IkiWiki 3.00;
23 use Encode;
24 sub import {
25 IkiWiki::hook
26 ( type => "getsetup"
27 , id => "createpage"
28 , call => \&hook_preprocess_getsetup );
29 IkiWiki::hook
30 ( type => "pageactions"
31 , id => "createpage"
32 , call => \&hook_preprocess_pageactions );
33 }
34 sub hook_preprocess_getsetup () {
35 return
36 plugin => {
37 safe => 1,
38 rebuild => 1,
39 section => "misc",
40 },
41 }
42 sub hook_preprocess_pageactions (@) {
43 my %params = @_;
44 my $page = $params{page};
45 my $form = "";
46 if ($IkiWiki::config{cgiurl}) {
47 $form =<<EOT;
48 <form method="get" action="$IkiWiki::config{cgiurl}" id="newpageform">
49 <input type="hidden" name="from" value="$page"/>
50 <input type="text" name="page" value="" class="input" placeholder="Chemin/Nouvelle_page"/>
51 <button name="do" value="create" class="button">Créer</button>
52 </form>
53 EOT
54 }
55 return $form;
56 }
57
58 1;