From 741b26aa176b34d0359a2b89dd6d8293fcdf2b3d Mon Sep 17 00:00:00 2001 From: intrigeri Date: Thu, 1 Jan 2009 16:38:16 +0100 Subject: remove: implemented a new canremove hook; use it in the po plugin Signed-off-by: intrigeri --- IkiWiki/Plugin/po.pm | 11 +++++++++++ IkiWiki/Plugin/remove.pm | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 205066341..5670f3608 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -39,6 +39,7 @@ sub import { hook(type => "rename", id => "po", call => \&renamepages); hook(type => "delete", id => "po", call => \&mydelete); hook(type => "change", id => "po", call => \&change); + hook(type => "canremove", id => "po", call => \&canremove); hook(type => "editcontent", id => "po", call => \&editcontent); $origsubs{'bestlink'}=\&IkiWiki::bestlink; @@ -406,6 +407,16 @@ sub change(@) { } } +sub canremove ($$$) { + my ($page, $cgi, $session) = (shift, shift, shift); + + if (istranslation($page)) { + return gettext("Can not remove a translation. Removing the master page,". + "though, removes its translations as well."); + } + return undef; +} + # As we're previewing or saving a page, the content may have # changed, so tell the next filter() invocation it must not be lazy. sub editcontent () { diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm index 21989aff3..2e3614cca 100644 --- a/IkiWiki/Plugin/remove.pm +++ b/IkiWiki/Plugin/remove.pm @@ -54,6 +54,26 @@ sub check_canremove ($$$) { error("renaming of attachments is not allowed"); } } + + my $canremove; + IkiWiki::run_hooks(canremove => sub { + return if defined $canremove; + my $ret=shift->($page, $q, $session); + if (defined $ret) { + if ($ret eq "") { + $canremove=1; + } + elsif (ref $ret eq 'CODE') { + $ret->(); + $canremove=0; + } + elsif (defined $ret) { + error($ret); + $canremove=0; + } + } + }); + return $canremove; } sub formbuilder_setup (@) { -- cgit v1.2.3