+
+ # attachments in holding directory
+ my $dir=attachment_holding_location($page);
+ my $heldmsg=gettext("this attachment is not yet saved");
+ foreach my $file (glob("$dir/*")) {
+ $file=Encode::decode_utf8($file);
+ next unless -f $file;
+ my $base=IkiWiki::basename($file);
+ my $f=$loc.$base;
+ $attachments{$f}={
+ $std->($f, (stat($file))[9]*2, stored_msg(), (stat(_))[7]),
+ link => $base,
+ }
+ }
+
+ # Sort newer attachments to the end of the list.
+ return sort { $a->{mtime_raw} <=> $b->{mtime_raw} || $a->{link} cmp $b->{link} }
+ values %attachments;
+}
+
+sub stored_msg {
+ gettext("just uploaded");
+}
+
+sub json_response ($$$$) {
+ my $q=shift;
+ my $form=shift;
+ my $filename=shift;
+ my $stored_msg=shift;
+
+ if (! defined $form->submitted ||
+ $form->submitted ne "Upload Attachment") {
+ eval q{use JSON};
+ error $@ if $@;
+ print "Content-type: text/html\n\n";
+ my $size=-s $filename;
+ print to_json([
+ {
+ name => IkiWiki::basename($filename),
+ size => $size,
+ humansize => IkiWiki::Plugin::filecheck::humansize($size),
+ stored_msg => $stored_msg,
+
+ }
+ ]);
+ exit 0;