From: Gilles Dubuc Date: Thu, 24 Nov 2016 12:14:11 +0000 (+0100) Subject: Serve 400 instead of 500 when invalid thumbnail parameters are requested X-Git-Tag: 1.31.0-rc.0~4740^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=80c1e8343e58bf44aac158b98a7bf69fbb78ed8b;p=lhc%2Fweb%2Fwiklou.git Serve 400 instead of 500 when invalid thumbnail parameters are requested 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. Bug: T147784 Change-Id: I4d24a93e655f04d8119e77798d5df5a45caaafcf --- diff --git a/includes/media/MediaTransformOutput.php b/includes/media/MediaTransformOutput.php index b3a555aa5c..46b96745fa 100644 --- a/includes/media/MediaTransformOutput.php +++ b/includes/media/MediaTransformOutput.php @@ -476,6 +476,10 @@ class MediaTransformError extends MediaTransformOutput { function isError() { return true; } + + function getHttpStatusCode() { + return 500; + } } /** @@ -490,6 +494,10 @@ class TransformParameterError extends MediaTransformError { max( isset( $params['height'] ) ? $params['height'] : 0, 120 ), wfMessage( 'thumbnail_invalid_params' )->text() ); } + + function getHttpStatusCode() { + return 400; + } } /** @@ -511,4 +519,8 @@ class TransformTooBigImageAreaError extends MediaTransformError { )->text() ); } + + function getHttpStatusCode() { + return 400; + } } diff --git a/thumb.php b/thumb.php index fca25c55d2..c38b89c251 100644 --- a/thumb.php +++ b/thumb.php @@ -341,6 +341,7 @@ function wfStreamThumb( array $params ) { // 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 @@ function wfStreamThumb( array $params ) { } } 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() ) {