remove: implemented a new canremove hook; use it in the po plugin
authorintrigeri <intrigeri@boum.org>
Thu, 1 Jan 2009 15:38:16 +0000 (16:38 +0100)
committerintrigeri <intrigeri@boum.org>
Thu, 1 Jan 2009 15:44:39 +0000 (16:44 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
IkiWiki/Plugin/remove.pm
doc/plugins/write.mdwn

index 205066341fc2105b436d7439312729c5dc06e680..5670f3608ef3a5bb8424fffb4c6c3898f72a868f 100644 (file)
@@ -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 () {
index 21989aff3ff1c812af0ca83f5d8ecd72046393aa..2e3614cca7dde3bfcffab25ffefe82591e4eafaa 100644 (file)
@@ -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 (@) {
index eb50ca4ef546765d61edd715fb207bfda93026f7..e20cce763e4b2d98fd11a2b0fbac1e4a3ab3498a 100644 (file)
@@ -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);