]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/remove.pm
Use local paths for redirection where possible
[ikiwiki.git] / IkiWiki / Plugin / remove.pm
index cbc8a0f2ce70719e770fc64853feaaa37252f23b..ab189766302ecb842d8b24e049478bf5328c1507 100644 (file)
@@ -18,6 +18,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => 0,
+                       section => "web",
                },
 }
 
@@ -41,17 +42,14 @@ sub check_canremove ($$$) {
                error(sprintf(gettext("%s is not a file"), $file));
        }
        
-       # Must be editable.
-       IkiWiki::check_canedit($page, $q, $session);
-
        # If a user can't upload an attachment, don't let them delete it.
        # 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 {
-                       error("renaming of attachments is not allowed");
+                       error("removal of attachments is not allowed");
                }
        }
 
@@ -73,6 +71,7 @@ sub check_canremove ($$$) {
                        }
                }
        });
+       return defined $canremove ? $canremove : 1;
 }
 
 sub formbuilder_setup (@) {
@@ -102,10 +101,12 @@ sub confirmation_form ($$) {
                javascript => 0,
                params => $q,
                action => $config{cgiurl},
-               stylesheet => IkiWiki::baseurl()."style.css",
+               stylesheet => 1,
                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"];
@@ -118,6 +119,7 @@ sub removal_confirm ($$@) {
        my @pages=@_;
 
        foreach my $page (@pages) {
+               IkiWiki::check_canedit($page, $q, $session);
                check_canremove($page, $q, $session);
        }
 
@@ -166,7 +168,7 @@ sub formbuilder (@) {
                        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."));
                        }
@@ -187,12 +189,15 @@ sub sessioncgi ($$) {
                        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.
                        my @files;
                        foreach my $page (@pages) {
+                               IkiWiki::check_canedit($page, $q, $session);
                                check_canremove($page, $q, $session);
                                
                                # This untaint is safe because of the
@@ -208,8 +213,10 @@ sub sessioncgi ($$) {
                                foreach my $file (@files) {
                                        IkiWiki::rcs_remove($file);
                                }
-                               IkiWiki::rcs_commit_staged(gettext("removed"),
-                                       $session->param("name"), $ENV{REMOTE_ADDR});
+                               IkiWiki::rcs_commit_staged(
+                                       message => gettext("removed"),
+                                       session => $session,
+                               );
                                IkiWiki::enable_commit_hook();
                                IkiWiki::rcs_update();
                        }
@@ -233,11 +240,11 @@ sub sessioncgi ($$) {
                                if (! exists $pagesources{$parent}) {
                                        $parent="index";
                                }
-                               IkiWiki::redirect($q, urlto($parent, '/', 1));
+                               IkiWiki::redirect($q, urlto($parent, undef));
                        }
                }
                else {
-                       removal_confirm($q, $session, 0, $q->param("page"));
+                       removal_confirm($q, $session, 0, $form->field("page"));
                }
 
                exit 0;