init
[ikiwiki/action.git] / action.pm
1 #!/usr/bin/perl
2 # This file is une extension à IkiWiki
3 # permettant d’ajouter des actions aux pages.
4 # Copyright (C) 2010 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::action;
19 use warnings;
20 use strict;
21 use IkiWiki 3.00;
22 sub import {
23 IkiWiki::hook
24 ( type => "preprocess"
25 , id => "action"
26 , call => \&hook_preprocess_action );
27 IkiWiki::hook
28 ( type => "pageactions"
29 , id => "action"
30 , call => \&hook_preprocess_pageactions );
31 }
32 my %map;
33 sub hook_preprocess_pageactions(@) {
34 my %env = @_;
35 my $page = $env{page};
36 my @lst;
37 if (defined $page and exists $map{$page}) {
38 foreach (@{$map{$page}}) {
39 push @lst, $_;
40 }
41 }
42 return @lst;
43 }
44 sub hook_preprocess_action(@) {
45 my %env = @_;
46 my $page = $env{page};
47 if (exists $env{html} and defined $env{html}) {
48 if (length $env{html}) {
49 $map{$page} = []
50 if not defined $map{$page};
51 push @{$map{$page}}, "$env{html}";
52 }
53 else {
54 delete $map{$page};
55 }
56 }
57 return "";
58 }
59
60 1;