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 ++++++++++++++++++++ doc/plugins/write.mdwn | 8 ++++++++ 3 files changed, 39 insertions(+) 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 (@) { diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index eb50ca4ef..e20cce763 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -321,6 +321,14 @@ This hook should avoid directly redirecting the user to a signin page, since it's sometimes used to test to see which pages in a set of pages a user can edit. +### canremove + + hook(type => "canremove", id => "foo", call => \&canremove); + +This hook can be used to implement arbitrary access methods to control when +a page can be removed using the web interface (commits from revision control +bypass it). It works exactly like the `canedit` hook. + ### editcontent hook(type => "editcontent", id => "foo", call => \&editcontent); -- cgit v1.2.3