diff options
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/attachment.pm | 25 | ||||
-rw-r--r-- | IkiWiki/Plugin/remove.pm | 15 |
2 files changed, 31 insertions, 9 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index eb8846d06..c6f8891c2 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -10,7 +10,7 @@ sub import { hook(type => "getsetup", id => "attachment", call => \&getsetup); hook(type => "checkconfig", id => "attachment", call => \&checkconfig); hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup); - hook(type => "formbuilder", id => "attachment", call => \&formbuilder); + hook(type => "formbuilder", id => "attachment", call => \&formbuilder, last => 1); IkiWiki::loadplugin("filecheck"); } @@ -154,12 +154,27 @@ sub formbuilder (@) { } sub attachment_holding_dir { - my $page=shift; + my $page=attachment_location(shift); return $config{wikistatedir}."/attachments/". IkiWiki::possibly_foolish_untaint(linkpage($page)); } +sub remove_held_attachment { + my $attachment=shift; + + my $f=attachment_holding_dir($attachment); + $f=~s/\/$//; + if (-f $f) { + require IkiWiki::Render; + IkiWiki::prune($f); + return 1; + } + else { + return 0; + } +} + # Stores the attachment in a holding area, not yet in the wiki proper. sub attachment_store { my $filename=shift; @@ -221,8 +236,7 @@ sub attachment_store { } } binmode($fh); - # Needed for fast_file_copy. - require IkiWiki::Render; + require IkiWiki::Render; writefile($filename, $dest, undef, 1, sub { IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_); }); @@ -248,7 +262,8 @@ sub attachments_save { push @attachments, $dest; } return unless @attachments; - rmdir($dir); + require IkiWiki::Render; + IkiWiki::prune($dir); # Check the attachments in and trigger a wiki refresh. if ($config{rcs}) { diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm index bc481502a..5e5b83349 100644 --- a/IkiWiki/Plugin/remove.pm +++ b/IkiWiki/Plugin/remove.pm @@ -117,13 +117,20 @@ sub removal_confirm ($$@) { my $session=shift; my $attachment=shift; my @pages=@_; + + # Special case for unsaved attachments. + @pages=grep { + ! (IkiWiki::Plugin::attachment->can("remove_held_attachment") && + IkiWiki::Plugin::attachment::remove_held_attachment($_)) + } @pages; + return unless @pages; foreach my $page (@pages) { IkiWiki::check_canedit($page, $q, $session); check_canremove($page, $q, $session); } - # Save current form state to allow returning to it later + # Save current form state to allow returning to it later # without losing any edits. # (But don't save what button was submitted, to avoid # looping back to here.) @@ -178,10 +185,10 @@ sub formbuilder (@) { } sub sessioncgi ($$) { - my $q=shift; + my $q=shift; if ($q->param("do") eq 'remove') { - my $session=shift; + my $session=shift; my ($form, $buttons)=confirmation_form($q, $session); IkiWiki::decode_form_utf8($form); @@ -192,7 +199,7 @@ sub sessioncgi ($$) { 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; |