$form->tmpl_param("attachments-class" => "toggleable-open");
}
- # Save attachments in holding area before previewing so
- # they can be seen in the preview.
- if ($form->submitted eq "Preview") {
+ # Save attachments in holding area before previewing and
+ # saving.
+ if ($form->submitted eq "Preview" ||
+ $form->submitted eq "Save Page") {
attachments_save($form, $params{session});
}
}
my $dir=attachment_holding_location($form->field('page'));
foreach my $filename (glob("$dir/*")) {
next unless -f $filename;
- my $dest=$config{srcdir}."/".
+ my $destdir=$config{srcdir}."/".
linkpage(IkiWiki::possibly_foolish_untaint(
- attachment_location($form->field('page')))).
- IkiWiki::basename($filename);
+ attachment_location($form->field('page'))));
+ my $destfile=IkiWiki::basename($filename);
+ my $dest=$destdir.$destfile;
unlink($dest);
+ IkiWiki::prep_writefile($destfile, $destdir);
rename($filename, $dest);
push @attachments, $dest;
}
my $page=shift;
# Put the attachment in a subdir of the page it's attached
- # to, unless that page is an "index" page.
- $page=~s/(^|\/)index//;
+ # to, unless that page is the "index" page.
+ return "" if $page eq 'index';
$page.="/" if length $page;
return $page;