X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/ace3665f811774a6eb64b908bf88178b0c8f3689..6b0ac401cdbe3a0e4a6997411542e1e0598ccbe5:/IkiWiki/Plugin/attachment.pm diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 4d6dee23e..fd4096edf 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -116,9 +116,10 @@ sub formbuilder_setup (@) { $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}); } } @@ -272,11 +273,13 @@ sub attachments_save { 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; } @@ -303,8 +306,8 @@ sub attachment_location ($) { 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;