From a7c90ecc5f9fa7a48eb1616f3de7cd2d3771b816 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 23 Sep 2021 15:33:21 -0700 Subject: [PATCH] Allow skipping $wgMaxImageArea check If $wgMaxImageArea is false, MediaWiki will no longer check if the image fits within that area before trying to scale it. Extensions can still use the BitmapHandlerCheckImageArea hook to override it. This is primarily useful when using an external scaler like Wikimedia does with Thumbor, which decides whether it can scale images by using a timeout rather than based on size. Codesearch indicates that the only extension checking this setting is PagedTiffHandler, which will be updated in Iefa67321d07f7. Bug: T291014 Depends-On: Iefa67321d07f79d982388231e02e87e2f18aed40 Change-Id: Id10173bbddb32bc70e036f426369cfbea52cecf4 --- RELEASE-NOTES-1.38 | 3 +++ includes/DefaultSettings.php | 6 ++++++ includes/media/TransformationalImageHandler.php | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/RELEASE-NOTES-1.38 b/RELEASE-NOTES-1.38 index 0c44b57e37f..ea679c0e5df 100644 --- a/RELEASE-NOTES-1.38 +++ b/RELEASE-NOTES-1.38 @@ -27,6 +27,9 @@ of automatic detection of possible phone numbers in a webpage in Safari on iOS. * … ==== Changed configuration ==== +* $wgMaxImageArea - This setting may now be set to false to disable size + checking before scaling. Extensions can still override its value by + using the BitmapHandlerCheckImageArea hook. * … ==== Removed configuration ==== diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f6b4ec66fda..d281a03191f 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1403,8 +1403,14 @@ $wgMediaInTargetLanguage = true; * built-in image scalers, such as ImageMagick or GD. It is ignored for * JPEGs with ImageMagick, and when using the VipsScaler extension. * + * If set to false, MediaWiki will not check the size of the image before + * attempting to scale it. Extensions may still override this setting by + * using the BitmapHandlerCheckImageArea hook. + * * The default is 50 MB if decompressed to RGBA form, which corresponds to * 12.5 million pixels or 3500x3500. + * + * @var string|bool */ $wgMaxImageArea = 1.25e7; diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index 4b24a957573..2551e03ba5e 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -620,6 +620,11 @@ abstract class TransformationalImageHandler extends ImageHandler { return (bool)$checkImageAreaHookResult; } + if ( $wgMaxImageArea === false ) { + // Checking is disabled, fine to thumbnail + return true; + } + $srcWidth = $file->getWidth( $params['page'] ); $srcHeight = $file->getHeight( $params['page'] );