aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-06-16 13:01:23 -0400
committerJoey Hess <joey@kitenet.net>2011-06-16 13:01:23 -0400
commit6ebb4e262ef70ec85436b7f0bff134009ce08f3b (patch)
tree18146a97f4716a2c82d8d38411225c93d86e1878 /IkiWiki
parent5f0dfdd1ea3681f8e9a87a7c17d409b92ce1083a (diff)
downloadikiwiki-6ebb4e262ef70ec85436b7f0bff134009ce08f3b.tar
ikiwiki-6ebb4e262ef70ec85436b7f0bff134009ce08f3b.tar.gz
show ikiwiki error when attachment is rejected
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/attachment.pm62
1 files changed, 38 insertions, 24 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index 4af9ac92b..490014a7e 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -212,22 +212,28 @@ sub attachment_store {
$filename=IkiWiki::basename($filename);
$filename=~s/.*\\+(.+)/$1/; # hello, windows
$filename=IkiWiki::possibly_foolish_untaint(linkpage($filename));
+ my $dest=attachment_holding_location($form->field('page'));
# Check that the user is allowed to edit the attachment.
my $final_filename=
linkpage(IkiWiki::possibly_foolish_untaint(
attachment_location($form->field('page')))).
$filename;
- if (IkiWiki::file_pruned($final_filename)) {
- error(gettext("bad attachment filename"));
+ eval {
+ if (IkiWiki::file_pruned($final_filename)) {
+ error(gettext("bad attachment filename"));
+ }
+ IkiWiki::check_canedit($final_filename, $q, $session);
+ # And that the attachment itself is acceptable.
+ check_canattach($session, $final_filename, $tempfile);
+ };
+ if ($@) {
+ json_response($q, $dest."/".$filename, $@);
+ error $@;
}
- IkiWiki::check_canedit($final_filename, $q, $session);
- # And that the attachment itself is acceptable.
- check_canattach($session, $final_filename, $tempfile);
# Move the attachment into holding directory.
# Try to use a fast rename; fall back to copying.
- my $dest=attachment_holding_location($form->field('page'));
IkiWiki::prep_writefile($filename, $dest);
unlink($dest."/".$filename);
if (rename($tempfile, $dest."/".$filename)) {
@@ -253,24 +259,7 @@ sub attachment_store {
});
}
- # Return JSON response for the jquery file upload widget.
- if ($q->Accept("application/json") >= 1.0 &&
- grep { /application\/json/i } $q->Accept) {
- eval q{use JSON};
- error $@ if $@;
- print "Content-type: application/json\n\n";
- my $size=-s $dest."/".$filename;
- print to_json([
- {
- name => $filename,
- size => $size,
- humansize => IkiWiki::Plugin::filecheck::humansize($size),
- stored_msg => stored_msg(),
-
- }
- ]);
- exit 0;
- }
+ json_response($q, $dest."/".$filename, stored_msg());
}
# Save all stored attachments for a page.
@@ -371,4 +360,29 @@ sub stored_msg {
gettext("just uploaded");
}
+sub json_response ($$$) {
+ my $q=shift;
+ my $filename=shift;
+ my $stored_msg=shift;
+
+ # for the jquery file upload widget
+ if ($q->Accept("application/json") >= 1.0 &&
+ grep { /application\/json/i } $q->Accept) {
+ eval q{use JSON};
+ error $@ if $@;
+ print "Content-type: application/json\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;
+ }
+}
+
1