#!/usr/bin/perl
	# This file is une extension à IkiWiki
	# permettant d’ajouter des actions aux pages.
	# Copyright (C) 2010  Julien Moutinho
	#
	# This program is free software: you can redistribute it and/or modify
	# it under the terms of the GNU General Public License as published
	# by the Free Software Foundation, either version 3 of the License,
	# or any later version.
	#
	# This program is distributed in the hope that it will be useful,
	# but WITHOUT ANY WARRANTY; without even the implied warranty
	# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	# See the GNU General Public License for more details.
	#
	# You should have received a copy of the GNU General Public License
	# along with this program.  If not, see <http://www.gnu.org/licenses/>.
package IkiWiki::Plugin::action;
use warnings;
use strict;
use IkiWiki 3.00;
sub import {
	IkiWiki::hook
	 ( type => "preprocess"
	 , id   => "action"
	 , call => \&hook_preprocess_action );
	IkiWiki::hook
	 ( type => "pageactions"
	 , id   => "action"
	 , call => \&hook_preprocess_pageactions );
 }
my %map;
sub hook_preprocess_pageactions(@) {
	my %env = @_;
	my $page = $env{page};
	my @lst;
	if (defined $page and exists $map{$page}) {
		foreach (@{$map{$page}}) {
			push @lst, $_;
		 }
	 }
	return @lst;
 }
sub hook_preprocess_action(@) {
	my %env = @_;
	my $page = $env{page};
	if (exists $env{html} and defined $env{html}) {
		if (length $env{html}) {
			$map{$page} = []
				if not defined $map{$page};
			push @{$map{$page}}, "$env{html}";
		 }
		else {
			delete $map{$page};
		 }
	 }
	return "";
 }

1;
