aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/attachment.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-06-14 14:44:20 -0400
committerJoey Hess <joey@kitenet.net>2011-06-14 14:44:20 -0400
commit04b2a4d6762b33a199b18de4df3991ecba87db7d (patch)
tree7a0c265e488eb9b8c6ab0e9bfe095b676b859e06 /IkiWiki/Plugin/attachment.pm
parentc55a32d3e18e5ed72be0dd74461f33ee5e39ef12 (diff)
downloadikiwiki-04b2a4d6762b33a199b18de4df3991ecba87db7d.tar
ikiwiki-04b2a4d6762b33a199b18de4df3991ecba87db7d.tar.gz
fix removal of helf attachments
Left out confirmation of removal for held attachments because a) they're not in the wiki yet, so confirmation is a bit unnecessary b) it would be hard c) eases later integration of jquery file upload interface Also changed where attachments of index are held (to match where they're stored in the srcdir). Note that the attachment formbuilder hook was made to run last, so that the list of attachments is not generated before removal, in the fast path w/o confirm.
Diffstat (limited to 'IkiWiki/Plugin/attachment.pm')
-rw-r--r--IkiWiki/Plugin/attachment.pm25
1 files changed, 20 insertions, 5 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}) {