X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FTransformationalImageHandler.php;h=fd8d81d24c2e9c1dacf6b30f1a73dda0de63c6c0;hb=85f924e59135271ef57b50a5f8b2a52be833413a;hp=b3ae2965696ae5535ce35f9bc56c1b9bde91fb75;hpb=30e009794bacc2e3138c372e6ddf876dca2d4a9c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index b3ae296569..fd8d81d24c 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -61,29 +61,6 @@ abstract class TransformationalImageHandler extends ImageHandler { } } - # Check if the file is smaller than the maximum image area for thumbnailing - # For historical reasons, hook starts with BitmapHandler - $checkImageAreaHookResult = null; - wfRunHooks( - 'BitmapHandlerCheckImageArea', - array( $image, &$params, &$checkImageAreaHookResult ) - ); - - if ( is_null( $checkImageAreaHookResult ) ) { - global $wgMaxImageArea; - - if ( $srcWidth * $srcHeight > $wgMaxImageArea - && !( $image->getMimeType() == 'image/jpeg' - && $this->getScalerType( false, false ) == 'im' ) - ) { - # Only ImageMagick can efficiently downsize jpg images without loading - # the entire file in memory - return false; - } - } else { - return $checkImageAreaHookResult; - } - return true; } @@ -190,6 +167,11 @@ abstract class TransformationalImageHandler extends ImageHandler { return $this->getClientScalingThumbnailImage( $image, $scalerParams ); } + if ( !$this->isImageAreaOkForThumbnaling( $image, $params ) ) { + global $wgMaxImageArea; + return new TransformTooBigImageAreaError( $params, $wgMaxImageArea ); + } + if ( $flags & self::TRANSFORM_LATER ) { wfDebug( __METHOD__ . ": Transforming later per flags.\n" ); $newParams = array( @@ -240,7 +222,7 @@ abstract class TransformationalImageHandler extends ImageHandler { # Try a hook. Called "Bitmap" for historical reasons. /** @var $mto MediaTransformOutput */ $mto = null; - wfRunHooks( 'BitmapHandlerTransform', array( $this, $image, &$scalerParams, &$mto ) ); + Hooks::run( 'BitmapHandlerTransform', array( $this, $image, &$scalerParams, &$mto ) ); if ( !is_null( $mto ) ) { wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" ); $scaler = 'hookaborted'; @@ -596,4 +578,43 @@ abstract class TransformationalImageHandler extends ImageHandler { public function mustRender( $file ) { return $this->canRotate() && $this->getRotation( $file ) != 0; } + + /** + * Check if the file is smaller than the maximum image area for thumbnailing. + * + * Runs the 'BitmapHandlerCheckImageArea' hook. + * + * @param File $file + * @param array $params + * @return bool + * @since 1.25 + */ + public function isImageAreaOkForThumbnaling( $file, &$params ) { + global $wgMaxImageArea; + + # For historical reasons, hook starts with BitmapHandler + $checkImageAreaHookResult = null; + Hooks::run( + 'BitmapHandlerCheckImageArea', + array( $file, &$params, &$checkImageAreaHookResult ) + ); + + if ( !is_null( $checkImageAreaHookResult ) ) { + // was set by hook, so return that value + return (bool)$checkImageAreaHookResult; + } + + $srcWidth = $file->getWidth( $params['page'] ); + $srcHeight = $file->getHeight( $params['page'] ); + + if ( $srcWidth * $srcHeight > $wgMaxImageArea + && !( $file->getMimeType() == 'image/jpeg' + && $this->getScalerType( false, false ) == 'im' ) + ) { + # Only ImageMagick can efficiently downsize jpg images without loading + # the entire file in memory + return false; + } + return true; + } }