jenkins-bot has submitted this change and it was merged.

Change subject: Handle missing width nicely in thumb.php
......................................................................


Handle missing width nicely in thumb.php

Bug: T88508
Change-Id: I2cbe4ab914a9edba71461b194151938feeafeb11
---
M autoload.php
M includes/media/ImageHandler.php
A includes/media/MediaTransformInvalidParametersException.php
M thumb.php
4 files changed, 32 insertions(+), 3 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index 948a6aa..8542e5f 100644
--- a/autoload.php
+++ b/autoload.php
@@ -725,6 +725,7 @@
        '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 6dd0453..787f21e 100644
--- a/includes/media/ImageHandler.php
+++ b/includes/media/ImageHandler.php
@@ -57,7 +57,7 @@
                } 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 0000000..15a2ca5
--- /dev/null
+++ b/includes/media/MediaTransformInvalidParametersException.php
@@ -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 {}
diff --git a/thumb.php b/thumb.php
index ebcf79f..999ffb2 100644
--- a/thumb.php
+++ b/thumb.php
@@ -252,10 +252,12 @@
        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;

-- 
To view, visit https://gerrit.wikimedia.org/r/188730
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2cbe4ab914a9edba71461b194151938feeafeb11
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to