summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2009-01-01 16:38:16 +0100
committerintrigeri <intrigeri@boum.org>2009-01-01 16:44:39 +0100
commit741b26aa176b34d0359a2b89dd6d8293fcdf2b3d (patch)
treea11600b8035bba15841272347eae72f2f68ac9df
parent5852f03efacb391f97d3d68e98ec8888cd09dc84 (diff)
remove: implemented a new canremove hook; use it in the po plugin
Signed-off-by: intrigeri <intrigeri@boum.org>
-rw-r--r--IkiWiki/Plugin/po.pm11
-rw-r--r--IkiWiki/Plugin/remove.pm20
-rw-r--r--doc/plugins/write.mdwn8
3 files changed, 39 insertions, 0 deletions
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);