editpage: added a cansave hook

Signed-off-by: intrigeri <intrigeri@boum.org>
master
intrigeri 2009-01-01 19:48:27 +01:00
parent e895157397
commit d69fdf6445
3 changed files with 53 additions and 0 deletions

View File

@ -81,6 +81,33 @@ sub check_canedit ($$$;$) {
return $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 ($$) { sub cgi_editpage ($$) {
my $q=shift; my $q=shift;
my $session=shift; my $session=shift;
@ -370,6 +397,7 @@ sub cgi_editpage ($$) {
} }
my $content=$form->field('editcontent'); my $content=$form->field('editcontent');
check_cansave($page, $content, $q, $session);
run_hooks(editcontent => sub { run_hooks(editcontent => sub {
$content=shift->( $content=shift->(
content => $content, content => $content,

View File

@ -30,6 +30,7 @@ sub import {
hook(type => "auth", id => "skeleton", call => \&auth); hook(type => "auth", id => "skeleton", call => \&auth);
hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi); hook(type => "sessioncgi", id => "skeleton", call => \&sessioncgi);
hook(type => "canedit", id => "skeleton", call => \&canedit); hook(type => "canedit", id => "skeleton", call => \&canedit);
hook(type => "cansave", id => "skeleton", call => \&cansave);
hook(type => "editcontent", id => "skeleton", call => \&editcontent); hook(type => "editcontent", id => "skeleton", call => \&editcontent);
hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup); hook(type => "formbuilder_setup", id => "skeleton", call => \&formbuilder_setup);
hook(type => "formbuilder", id => "skeleton", call => \&formbuilder); hook(type => "formbuilder", id => "skeleton", call => \&formbuilder);
@ -180,6 +181,15 @@ sub canedit ($$$) {
debug("skeleton plugin running in 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 ($$$) { sub editcontent ($$$) {
my %params=@_; my %params=@_;

View File

@ -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 since it's sometimes used to test to see which pages in a set of pages a
user can edit. 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 ### canremove
hook(type => "canremove", id => "foo", call => \&canremove); hook(type => "canremove", id => "foo", call => \&canremove);