Merge "Handle missing width nicely in thumb.php"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 11 Feb 2015 09:09:54 +0000 (09:09 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 11 Feb 2015 09:09:54 +0000 (09:09 +0000)
autoload.php
includes/media/ImageHandler.php
includes/media/MediaTransformInvalidParametersException.php [new file with mode: 0644]
thumb.php

index 9855e90..d0c313a 100644 (file)
@@ -726,6 +726,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',
        'MediaWikiI18N' => __DIR__ . '/includes/skins/MediaWikiI18N.php',
index 6dd0453..787f21e 100644 (file)
@@ -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 (file)
index 0000000..15a2ca5
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * MediaWiki exception thrown by some methods when the transform parameter array is invalid
+ *
+ * @ingroup Exception
+ */
+class MediaTransformInvalidParametersException extends MWException {}
index 28f22fd..70cd1e6 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -252,10 +252,12 @@ function wfStreamThumb( array $params ) {
        try {
                $thumbName = $img->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;