Handle missing width nicely in thumb.php
authorGergő Tisza <tgr.huwiki@gmail.com>
Thu, 5 Feb 2015 02:16:06 +0000 (02:16 +0000)
committerGergő Tisza <tgr.huwiki@gmail.com>
Tue, 10 Feb 2015 19:40:49 +0000 (19:40 +0000)
Bug: T88508
Change-Id: I2cbe4ab914a9edba71461b194151938feeafeb11

autoload.php
includes/media/ImageHandler.php
includes/media/MediaTransformInvalidParametersException.php [new file with mode: 0644]
thumb.php

index 948a6aa..8542e5f 100644 (file)
@@ -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',
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 ebcf79f..999ffb2 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;