+ my $content = $form->field('editcontent');
+ $form->field(name => 'editcontent',
+ value => $content."\n\n".$add,
+ force => 1) if length $add;
+ }
+
+ # Generate the attachment list only after having added any new
+ # attachments.
+ $form->tmpl_param("attachment_list" => [attachment_list(scalar $form->field('page'))]);
+}
+
+sub attachment_holding_location {
+ my $page=attachment_location(shift);
+
+ my $dir=$config{wikistatedir}."/attachments/".
+ IkiWiki::possibly_foolish_untaint(linkpage($page));
+ $dir=~s/\/$//;
+ return $dir;
+}
+
+sub is_held_attachment {
+ my $attachment=shift;
+
+ my $f=attachment_holding_location($attachment);
+ if (-f $f) {
+ return $f
+ }
+ else {
+ return undef;
+ }
+}
+
+# Stores the attachment in a holding area, not yet in the wiki proper.
+sub attachment_store {
+ my $filename=shift;
+ my $form=shift;
+ my $q=shift;
+ my $session=shift;
+
+ # This is an (apparently undocumented) way to get the name
+ # of the temp file that CGI writes the upload to.
+ my $tempfile=$q->tmpFileName($filename);
+ if (! defined $tempfile || ! length $tempfile) {
+ # perl 5.8 needs an alternative, awful method
+ if ($q =~ /HASH/ && exists $q->{'.tmpfiles'}) {
+ foreach my $key (keys(%{$q->{'.tmpfiles'}})) {
+ $tempfile=$q->tmpFileName(\$key);
+ last if defined $tempfile && length $tempfile;
+ }
+ }
+ if (! defined $tempfile || ! length $tempfile) {
+ error("CGI::tmpFileName failed to return the uploaded file name");
+ }
+ }