r99911 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99910‎ | r99911 | r99912 >
Date:20:36, 15 October 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
Per bug 28135, disable $wgMaxImageArea check when transforming using a hook, and enable the check for non IM scalers.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/media/Bitmap.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -15,6 +15,8 @@
1616 * (bug 27132) movefile right granted by default to registered users.
1717 * Default cookie lifetime ($wgCookieExpiration) is increased to 180 days.
1818 * (bug 31204) Removed old user.user_options
 19+* $wgMaxImageArea now applies to jpeg files if they are not scaled with
 20+ ImageMagick.
1921
2022 === New features in 1.19 ===
2123 * (bug 19838) Possibility to get all interwiki prefixes if the interwiki
Index: trunk/phase3/includes/media/Bitmap.php
@@ -21,7 +21,7 @@
2222 * @return bool
2323 */
2424 function normaliseParams( $image, &$params ) {
25 - global $wgMaxImageArea;
 25+
2626 if ( !parent::normaliseParams( $image, $params ) ) {
2727 return false;
2828 }
@@ -42,20 +42,44 @@
4343 return true;
4444 }
4545 }
46 -
 46+
 47+ return true;
 48+ }
 49+
 50+ /**
 51+ * Check if the file is smaller than the maximum image area for
 52+ * thumbnailing. Check will always pass if the scaler is 'hookaborted' or
 53+ * if the scaler is 'im' and the mime type is 'image/jpeg'
 54+ *
 55+ * @param File $image
 56+ * @param string $scaler
 57+ */
 58+ function checkImageArea( $image, $scaler ) {
 59+ global $wgMaxImageArea;
4760 # Don't thumbnail an image so big that it will fill hard drives and send servers into swap
4861 # JPEG has the handy property of allowing thumbnailing without full decompression, so we make
4962 # an exception for it.
50 - # @todo FIXME: This actually only applies to ImageMagick
51 - if ( $mimeType !== 'image/jpeg' &&
52 - $srcWidth * $srcHeight > $wgMaxImageArea )
 63+
 64+
 65+ if ( $image->getMimeType() == 'image/jpeg' && $scaler == 'im' )
5366 {
54 - return false;
 67+ # ImageMagick can efficiently downsize jpg images without loading
 68+ # the entire file in memory
 69+ return true;
5570 }
56 -
57 - return true;
 71+
 72+ if ( $scaler == 'hookaborted' )
 73+ {
 74+ # If a hook wants to transform the image, it is responsible for
 75+ # checking the image size, so abort here
 76+ return true;
 77+ }
 78+
 79+ # Do the actual check
 80+ return $this->getImageArea( $image, $image->getWidth(), $image->getHeight() ) <= $wgMaxImageArea;
5881 }
5982
 83+
6084 /**
6185 * Extracts the width/height if the image will be scaled before rotating
6286 *
@@ -160,6 +184,12 @@
161185 wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" );
162186 $scaler = 'hookaborted';
163187 }
 188+
 189+ # Check max image area
 190+ if ( !$this->checkImageArea( $image, $scaler ) )
 191+ {
 192+ return new TransformParameterError( $params );
 193+ }
164194
165195 switch ( $scaler ) {
166196 case 'hookaborted':

Follow-up revisions

RevisionCommit summaryAuthorDate
r99912Per bug 28135:...btongminh20:39, 15 October 2011
r99916Follow-up r99911: fix tests...btongminh21:38, 15 October 2011
r100579Updated documentation of $wgMaxImageArea for r99911 etc.tstarling04:45, 24 October 2011
r101677Per comments on r99911 move $wgMaxImageArea check back to normaliseParams(). ...btongminh20:48, 2 November 2011
r101678Follow-up r99911, r99912: Hook into new BitmapHandlerCheckImageArea hookbtongminh20:51, 2 November 2011
r104386Fix for r99911: don't use getImageArea() to determine the area for comparison...tstarling04:37, 28 November 2011
r104389MFT VipsScaler dependencies r99911, r99916, r99917, r101677, r104386, r104387...tstarling05:04, 28 November 2011

Comments

#Comment by Bryan (talk | contribs)   20:38, 15 October 2011

Needed for VipsScaler deployment.

#Comment by Brion VIBBER (talk | contribs)   21:03, 15 October 2011

phpunit test failures:

$ php phpunit.php includes/media/BitmapScalingTest.php 
PHPUnit 3.5.15 by Sebastian Bergmann.

.......FF

Time: 0 seconds, Memory: 14.75Mb

There were 2 failures:

1) BitmapScalingTest::testTooBigImage
Failed asserting that <boolean:true> is false.

/Library/WebServer/Documents/trunk/tests/phpunit/includes/media/BitmapScalingTest.php:108
/Library/WebServer/Documents/trunk/tests/phpunit/MediaWikiTestCase.php:64
/Library/WebServer/Documents/trunk/tests/phpunit/MediaWikiPHPUnitCommand.php:31
/Library/WebServer/Documents/trunk/tests/phpunit/phpunit.php:60

2) BitmapScalingTest::testTooBigMustRenderImage
Failed asserting that <boolean:true> is false.

/Library/WebServer/Documents/trunk/tests/phpunit/includes/media/BitmapScalingTest.php:115
/Library/WebServer/Documents/trunk/tests/phpunit/MediaWikiTestCase.php:64
/Library/WebServer/Documents/trunk/tests/phpunit/MediaWikiPHPUnitCommand.php:31
/Library/WebServer/Documents/trunk/tests/phpunit/phpunit.php:60

FAILURES!
Tests: 9, Assertions: 16, Failures: 2.
#Comment by Bryan (talk | contribs)   21:41, 15 October 2011

Fixed tests in r99916

#Comment by Tim Starling (talk | contribs)   05:11, 24 October 2011

Moving the area check from normaliseParams() to doTransform() after the TRANSFORM_LATER case means that it will be done by the 404 handler only. The parser will generate valid links to image, and thumb.php will generate an uncacheable HTTP 500 error, meaning that scaling will be retried every time someone views the page. If the page is a popular one, that could be many times per second. That's one of the reasons why it was in normaliseParams().

#Comment by Bryan (talk | contribs)   17:12, 24 October 2011

Hm.

Then this would require a new hook in normaliseParams().

#Comment by Bryan (talk | contribs)   19:25, 8 November 2011

Marking new per r101677

#Comment by Tim Starling (talk | contribs)   04:13, 28 November 2011

You know, it would make things easier if you included all the changes that you made in your commit message, including the associated rationale.

Status & tagging log