Gilles has uploaded a new change for review.
https://gerrit.wikimedia.org/r/323385
Change subject: Serve 400 instead of 500 when invalid thumbnail parameters are
requested
......................................................................
Serve 400 instead of 500 when invalid thumbnail parameters are requested
Bug: T147784
This was requested because of 0px thumbnail requests, but there are
other cases where parameters are detected as invalid and 400 is
semantically more correct than 500 in that situation.
Change-Id: I4d24a93e655f04d8119e77798d5df5a45caaafcf
---
M includes/media/MediaTransformOutput.php
M thumb.php
2 files changed, 14 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/85/323385/1
diff --git a/includes/media/MediaTransformOutput.php
b/includes/media/MediaTransformOutput.php
index b3a555a..46b9674 100644
--- a/includes/media/MediaTransformOutput.php
+++ b/includes/media/MediaTransformOutput.php
@@ -476,6 +476,10 @@
function isError() {
return true;
}
+
+ function getHttpStatusCode() {
+ return 500;
+ }
}
/**
@@ -489,6 +493,10 @@
max( isset( $params['width'] ) ? $params['width'] : 0,
120 ),
max( isset( $params['height'] ) ? $params['height'] :
0, 120 ),
wfMessage( 'thumbnail_invalid_params' )->text() );
+ }
+
+ function getHttpStatusCode() {
+ return 400;
}
}
@@ -511,4 +519,8 @@
)->text()
);
}
+
+ function getHttpStatusCode() {
+ return 400;
+ }
}
diff --git a/thumb.php b/thumb.php
index fca25c5..c38b89c 100644
--- a/thumb.php
+++ b/thumb.php
@@ -341,6 +341,7 @@
// Check for thumbnail generation errors...
$msg = wfMessage( 'thumbnail_error' );
$errorCode = 500;
+
if ( !$thumb ) {
$errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform()
returned false' )->escaped();
if ( $errorMsg instanceof MessageSpecifier &&
@@ -350,6 +351,7 @@
}
} elseif ( $thumb->isError() ) {
$errorMsg = $thumb->getHtmlMsg();
+ $errorCode = $thumb->getHttpStatusCode();
} elseif ( !$thumb->hasFile() ) {
$errorMsg = $msg->rawParams( 'No path supplied in thumbnail
object' )->escaped();
} elseif ( $thumb->fileIsSource() ) {
--
To view, visit https://gerrit.wikimedia.org/r/323385
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4d24a93e655f04d8119e77798d5df5a45caaafcf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits