Per bug 28135, disable $wgMaxImageArea check when transforming using a hook, and...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 15 Oct 2011 20:36:02 +0000 (20:36 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 15 Oct 2011 20:36:02 +0000 (20:36 +0000)
RELEASE-NOTES-1.19
includes/media/Bitmap.php

index a07c7b3..ce48ecf 100644 (file)
@@ -15,6 +15,8 @@ production.
 * (bug 27132) movefile right granted by default to registered users.
 * Default cookie lifetime ($wgCookieExpiration) is increased to 180 days.
 * (bug 31204) Removed old user.user_options
+* $wgMaxImageArea now applies to jpeg files if they are not scaled with
+  ImageMagick. 
 
 === New features in 1.19 ===
 * (bug 19838) Possibility to get all interwiki prefixes if the interwiki
index 6c57615..a5cc711 100644 (file)
@@ -21,7 +21,7 @@ class BitmapHandler extends ImageHandler {
         * @return bool
         */
        function normaliseParams( $image, &$params ) {
-               global $wgMaxImageArea;
+               
                if ( !parent::normaliseParams( $image, $params ) ) {
                        return false;
                }
@@ -42,20 +42,44 @@ class BitmapHandler extends ImageHandler {
                                return true;
                        }
                }
-
+               
+               return true;
+       }
+       
+       /**
+        * Check if the file is smaller than the maximum image area for 
+        * thumbnailing. Check will always pass if the scaler is 'hookaborted' or
+        * if the scaler is 'im' and the mime type is 'image/jpeg'
+        * 
+        * @param File $image
+        * @param string $scaler 
+        */
+       function checkImageArea( $image, $scaler ) {
+               global $wgMaxImageArea;
                # Don't thumbnail an image so big that it will fill hard drives and send servers into swap
                # JPEG has the handy property of allowing thumbnailing without full decompression, so we make
                # an exception for it.
-               # @todo FIXME: This actually only applies to ImageMagick
-               if ( $mimeType !== 'image/jpeg' &&
-                       $srcWidth * $srcHeight > $wgMaxImageArea )
+               
+               
+               if ( $image->getMimeType() == 'image/jpeg' && $scaler == 'im' )
                {
-                       return false;
+                       # ImageMagick can efficiently downsize jpg images without loading
+                       # the entire file in memory
+                       return true;
                }
-
-               return true;
+               
+               if ( $scaler == 'hookaborted' )
+               {
+                       # If a hook wants to transform the image, it is responsible for 
+                       # checking the image size, so abort here
+                       return true;
+               }
+               
+               # Do the actual check
+               return $this->getImageArea( $image, $image->getWidth(), $image->getHeight() ) <= $wgMaxImageArea;
        }
 
+
        /**
         * Extracts the width/height if the image will be scaled before rotating
         *
@@ -160,6 +184,12 @@ class BitmapHandler extends ImageHandler {
                        wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" );
                        $scaler = 'hookaborted';
                }
+               
+               # Check max image area
+               if ( !$this->checkImageArea( $image, $scaler ) )
+               {
+                       return new TransformParameterError( $params );
+               }
 
                switch ( $scaler ) {
                        case 'hookaborted':