]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/remove.pm
(no commit message)
[git.ikiwiki.info.git] / IkiWiki / Plugin / remove.pm
index 7815016625a3c84b4e8dc212d9fb86f728adf31d..d23b2cc1016851ac537303f9a3438df7446f40bd 100644 (file)
@@ -3,7 +3,7 @@ package IkiWiki::Plugin::remove;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
 
 sub import {
        hook(type => "getsetup", id => "remove", call => \&getsetup);
 
 sub import {
        hook(type => "getsetup", id => "remove", call => \&getsetup);
@@ -18,6 +18,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => 0,
                plugin => {
                        safe => 1,
                        rebuild => 0,
+                       section => "web",
                },
 }
 
                },
 }
 
@@ -48,12 +49,31 @@ sub check_canremove ($$$) {
        # This is sorta overkill, but better safe than sorry.
        if (! defined pagetype($pagesources{$page})) {
                if (IkiWiki::Plugin::attachment->can("check_canattach")) {
        # This is sorta overkill, but better safe than sorry.
        if (! defined pagetype($pagesources{$page})) {
                if (IkiWiki::Plugin::attachment->can("check_canattach")) {
-                       IkiWiki::Plugin::attachment::check_canattach($session, $page, $file);
+                       IkiWiki::Plugin::attachment::check_canattach($session, $page, "$config{srcdir}/$file");
                }
                else {
                }
                else {
-                       error("renaming of attachments is not allowed");
+                       error("removal of attachments is not allowed");
                }
        }
                }
        }
+
+       my $canremove;
+       IkiWiki::run_hooks(canremove => sub {
+               return if defined $canremove;
+               my $ret=shift->(page => $page, cgi => $q, session => $session);
+               if (defined $ret) {
+                       if ($ret eq "") {
+                               $canremove=1;
+                       }
+                       elsif (ref $ret eq 'CODE') {
+                               $ret->();
+                               $canremove=0;
+                       }
+                       elsif (defined $ret) {
+                               error($ret);
+                               $canremove=0;
+                       }
+               }
+       });
 }
 
 sub formbuilder_setup (@) {
 }
 
 sub formbuilder_setup (@) {
@@ -83,10 +103,12 @@ sub confirmation_form ($$) {
                javascript => 0,
                params => $q,
                action => $config{cgiurl},
                javascript => 0,
                params => $q,
                action => $config{cgiurl},
-               stylesheet => IkiWiki::baseurl()."style.css",
+               stylesheet => 1,
                fields => [qw{do page}],
        );
        
                fields => [qw{do page}],
        );
        
+       $f->field(name => "sid", type => "hidden", value => $session->id,
+               force => 1);
        $f->field(name => "do", type => "hidden", value => "remove", force => 1);
 
        return $f, ["Remove", "Cancel"];
        $f->field(name => "do", type => "hidden", value => "remove", force => 1);
 
        return $f, ["Remove", "Cancel"];
@@ -147,7 +169,7 @@ sub formbuilder (@) {
                        removal_confirm($q, $session, 0, $form->field("page"));
                }
                elsif ($form->submitted eq "Remove Attachments") {
                        removal_confirm($q, $session, 0, $form->field("page"));
                }
                elsif ($form->submitted eq "Remove Attachments") {
-                       my @selected=$q->param("attachment_select");
+                       my @selected=map { Encode::decode_utf8($_) } $q->param("attachment_select");
                        if (! @selected) {
                                error(gettext("Please select the attachments to remove."));
                        }
                        if (! @selected) {
                                error(gettext("Please select the attachments to remove."));
                        }
@@ -168,7 +190,9 @@ sub sessioncgi ($$) {
                        postremove($session);
                }
                elsif ($form->submitted eq 'Remove' && $form->validate) {
                        postremove($session);
                }
                elsif ($form->submitted eq 'Remove' && $form->validate) {
-                       my @pages=$q->param("page");
+                       IkiWiki::checksessionexpiry($q, $session, $q->param('sid'));
+
+                       my @pages=$form->field("page");
        
                        # Validate removal by checking that the page exists,
                        # and that the user is allowed to edit(/remove) it.
        
                        # Validate removal by checking that the page exists,
                        # and that the user is allowed to edit(/remove) it.
@@ -218,7 +242,7 @@ sub sessioncgi ($$) {
                        }
                }
                else {
                        }
                }
                else {
-                       IkiWiki::showform($form, $buttons, $session, $q);
+                       removal_confirm($q, $session, 0, $form->field("page"));
                }
 
                exit 0;
                }
 
                exit 0;