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
This commit is contained in:
Kunal Mehta 2021-09-23 15:33:21 -07:00
parent 93e2497411
commit a7c90ecc5f
3 changed files with 14 additions and 0 deletions

View file

@ -27,6 +27,9 @@ of automatic detection of possible phone numbers in a webpage in Safari on iOS.
* … * …
==== Changed configuration ==== ==== 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 ==== ==== Removed configuration ====

View file

@ -1403,8 +1403,14 @@ $wgMediaInTargetLanguage = true;
* built-in image scalers, such as ImageMagick or GD. It is ignored for * built-in image scalers, such as ImageMagick or GD. It is ignored for
* JPEGs with ImageMagick, and when using the VipsScaler extension. * 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 * The default is 50 MB if decompressed to RGBA form, which corresponds to
* 12.5 million pixels or 3500x3500. * 12.5 million pixels or 3500x3500.
*
* @var string|bool
*/ */
$wgMaxImageArea = 1.25e7; $wgMaxImageArea = 1.25e7;

View file

@ -620,6 +620,11 @@ abstract class TransformationalImageHandler extends ImageHandler {
return (bool)$checkImageAreaHookResult; return (bool)$checkImageAreaHookResult;
} }
if ( $wgMaxImageArea === false ) {
// Checking is disabled, fine to thumbnail
return true;
}
$srcWidth = $file->getWidth( $params['page'] ); $srcWidth = $file->getWidth( $params['page'] );
$srcHeight = $file->getHeight( $params['page'] ); $srcHeight = $file->getHeight( $params['page'] );