Add path and path_natural sort orders
[ikiwiki.git] / IkiWiki / Plugin / attachment.pm
index 52bac7c1e937ba87e2711ff41319e13a5cfd7814..fd4096edf7de153ef01145f310c459f255e3fffc 100644 (file)
@@ -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;
        }