summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/editpage.pm28
-rw-r--r--IkiWiki/Plugin/skeleton.pm.example10
-rw-r--r--doc/plugins/write.mdwn15
3 files changed, 53 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index ed994306f..91d125a5c 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -81,6 +81,33 @@ sub check_canedit ($$$;$) {
return $canedit;
}
+sub check_cansave ($$$$) {
+ my $page=shift;
+ my $content=shift;
+ my $q=shift;
+ my $session=shift;
+
+ my $cansave;
+ run_hooks(cansave => sub {
+ return if defined $cansave;
+ my $ret=shift->($page, $content, $q, $session);
+ if (defined $ret) {
+ if ($ret eq "") {
+ $cansave=1;
+ }
+ elsif (ref $ret eq 'CODE') {
+ $ret->();
+ $cansave=0;
+ }
+ else {
+ error($ret);
+ $cansave=0;
+ }
+ }
+ });
+ return $cansave;
+}
+
sub cgi_editpage ($$) {
my $q=shift;
my $session=shift;
@@ -370,6 +397,7 @@ sub cgi_editpage ($$) {
}
my $content=$form->field('editcontent');
+ check_cansave($page, $content, $q, $session);
run_hooks(editcontent => sub {
$content=shift->(
content => $content,
diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example
index 96c4a5d6b..496a4dfe4 100644
--- a/IkiWiki/Plugin/skeleton.pm.example
+++ b/IkiWiki/Plugin/skeleton.pm.example
@@ -30,6 +30,7 @@ sub import {
hook(type => "auth", id => "skeleton", call => \&auth);
hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi);
hook(type => "canedit", id => "skeleton", call => \&canedit);
+ hook(type => "cansave", id => "skeleton", call => \&cansave);
hook(type => "editcontent", id => "skeleton", call => \&editcontent);
hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup);
hook(type => "formbuilder", id => "skeleton", call => \&formbuilder);
@@ -180,6 +181,15 @@ sub canedit ($$$) {
debug("skeleton plugin running in canedit");
}
+sub cansave ($$$$) {
+ my $page=shift;
+ my $content=shift;
+ my $cgi=shift;
+ my $session=shift;
+
+ debug("skeleton plugin running in cansave")
+}
+
sub editcontent ($$$) {
my %params=@_;
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 92e372cfa..fff142fa2 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -321,6 +321,21 @@ 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.
+### cansave
+
+ hook(type => "cansave", id => "foo", call => \&cansave);
+
+This hook can be used to implement arbitrary access methods to control
+when a page being edited can be saved using the web interface (commits
+from revision control bypass it).
+
+When a page is about to be saved, each registered cansave hook is
+called in turn, and passed the page name, the edited content, a CGI
+object and a session object.
+
+The return value of a cansave hook is interpreted the same as for the
+canedit hook.
+
### canremove
hook(type => "canremove", id => "foo", call => \&canremove);