]> sipb.mit.edu Git - ikiwiki.git/commitdiff
editpage: added a cansave hook
authorintrigeri <intrigeri@boum.org>
Thu, 1 Jan 2009 18:48:27 +0000 (19:48 +0100)
committerintrigeri <intrigeri@boum.org>
Thu, 1 Jan 2009 18:48:27 +0000 (19:48 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/editpage.pm
IkiWiki/Plugin/skeleton.pm.example
doc/plugins/write.mdwn

index ed994306f55251b561acf61459fcdc06fef8b994..91d125a5ca1ca30e836706a6e5e2aa43df6eced2 100644 (file)
@@ -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,
index 96c4a5d6b6515461dcc85ff316db3793e248f417..496a4dfe49265ddd8a7a41a16fbf1dd34980fe5e 100644 (file)
@@ -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=@_;
 
index 92e372cfab11b86d613e6ae15816c66774e2513e..fff142fa20b5f539673579218e0d2a43312c459c 100644 (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
 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);