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.
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 => "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");
}
IkiWiki::loadplugin("filecheck");
}
}
sub attachment_holding_dir {
}
sub attachment_holding_dir {
+ my $page=attachment_location(shift);
return $config{wikistatedir}."/attachments/".
IkiWiki::possibly_foolish_untaint(linkpage($page));
}
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;
# Stores the attachment in a holding area, not yet in the wiki proper.
sub attachment_store {
my $filename=shift;
- # Needed for fast_file_copy.
- require IkiWiki::Render;
+ require IkiWiki::Render;
writefile($filename, $dest, undef, 1, sub {
IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_);
});
writefile($filename, $dest, undef, 1, sub {
IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_);
});
push @attachments, $dest;
}
return unless @attachments;
push @attachments, $dest;
}
return unless @attachments;
+ require IkiWiki::Render;
+ IkiWiki::prune($dir);
# Check the attachments in and trigger a wiki refresh.
if ($config{rcs}) {
# Check the attachments in and trigger a wiki refresh.
if ($config{rcs}) {
my $session=shift;
my $attachment=shift;
my @pages=@_;
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);
}
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.)
# without losing any edits.
# (But don't save what button was submitted, to avoid
# looping back to here.)
if ($q->param("do") eq 'remove') {
if ($q->param("do") eq 'remove') {
my ($form, $buttons)=confirmation_form($q, $session);
IkiWiki::decode_form_utf8($form);
my ($form, $buttons)=confirmation_form($q, $session);
IkiWiki::decode_form_utf8($form);
IkiWiki::checksessionexpiry($q, $session, $q->param('sid'));
my @pages=$form->field("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;
# Validate removal by checking that the page exists,
# and that the user is allowed to edit(/remove) it.
my @files;