f2fc5c1b1d47074334461f935b2e145754a960c2
[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 warnings;
21 use IkiWiki 3.00;
22 use Encode;
23 sub import {
24 IkiWiki::hook
25 ( type => "getsetup"
26 , id => "createpage"
27 , call => \&hook_preprocess_getsetup );
28 IkiWiki::hook
29 ( type => "pageactions"
30 , id => "createpage"
31 , call => \&hook_preprocess_pageactions );
32 }
33 sub hook_preprocess_getsetup () {
34 return
35 plugin => {
36 safe => 1,
37 rebuild => 1,
38 section => "misc",
39 },
40 }
41 sub hook_preprocess_pageactions (@) {
42 my %params = @_;
43 my $page = $params{page};
44 my $form = "";
45 if ($IkiWiki::config{cgiurl}) {
46 $form =<<EOT;
47 <form method="get" action="$IkiWiki::config{cgiurl}" id="newpageform">
48 <input type="hidden" name="from" value="$page"/>
49 <input type="text" name="page" value="" class="input" placeholder="Chemin/Nouvelle_page"/>
50 <button name="do" value="create" class="button">Créer</button>
51 </form>
52 EOT
53 }
54 return (decode_utf8($form));
55 }
56
57 1;