From 769e7e339eea54bcd447f2d3882be2dcbc35b418 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Thu, 5 Feb 2015 02:16:06 +0000 Subject: [PATCH] Handle missing width nicely in thumb.php Bug: T88508 Change-Id: I2cbe4ab914a9edba71461b194151938feeafeb11 --- autoload.php | 1 + includes/media/ImageHandler.php | 2 +- ...diaTransformInvalidParametersException.php | 26 +++++++++++++++++++ thumb.php | 6 +++-- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 includes/media/MediaTransformInvalidParametersException.php diff --git a/autoload.php b/autoload.php index 948a6aa421..8542e5f7f1 100644 --- a/autoload.php +++ b/autoload.php @@ -725,6 +725,7 @@ $wgAutoloadLocalClasses = array( 'MediaHandler' => __DIR__ . '/includes/media/MediaHandler.php', 'MediaStatisticsPage' => __DIR__ . '/includes/specials/SpecialMediaStatistics.php', 'MediaTransformError' => __DIR__ . '/includes/media/MediaTransformOutput.php', + 'MediaTransformInvalidParametersException' => __DIR__ . '/includes/media/MediaTransformInvalidParametersException.php', 'MediaTransformOutput' => __DIR__ . '/includes/media/MediaTransformOutput.php', 'MediaWiki' => __DIR__ . '/includes/MediaWiki.php', 'MediaWikiBagOStuff' => __DIR__ . '/includes/objectcache/SqlBagOStuff.php', diff --git a/includes/media/ImageHandler.php b/includes/media/ImageHandler.php index 6dd0453ef1..787f21e443 100644 --- a/includes/media/ImageHandler.php +++ b/includes/media/ImageHandler.php @@ -57,7 +57,7 @@ abstract class ImageHandler extends MediaHandler { } elseif ( isset( $params['width'] ) ) { $width = $params['width']; } else { - throw new MWException( 'No width specified to ' . __METHOD__ ); + throw new MediaTransformInvalidParametersException( 'No width specified to ' . __METHOD__ ); } # Removed for ProofreadPage diff --git a/includes/media/MediaTransformInvalidParametersException.php b/includes/media/MediaTransformInvalidParametersException.php new file mode 100644 index 0000000000..15a2ca5546 --- /dev/null +++ b/includes/media/MediaTransformInvalidParametersException.php @@ -0,0 +1,26 @@ +thumbName( $params ); if ( !strlen( $thumbName ) ) { // invalid params? - wfThumbError( 400, 'The specified thumbnail parameters are not valid.' ); - return; + throw new MediaTransformInvalidParametersException( 'Empty return from File::thumbName' ); } $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style + } catch ( MediaTransformInvalidParametersException $e ) { + wfThumbError( 400, 'The specified thumbnail parameters are not valid: ' . $e->getMessage() ); + return; } catch ( MWException $e ) { wfThumbError( 500, $e->getHTML() ); return; -- 2.20.1