r104389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104388‎ | r104389 | r104390 >
Date:05:04, 28 November 2011
Author:tstarling
Status:ok
Tags:
Comment:
MFT VipsScaler dependencies r99911, r99916, r99917, r101677, r104386, r104387, except omitting the interface change to getImageArea() and some whitespace and comment changes.
Modified paths:
  • /branches/wmf/1.18wmf1/docs/hooks.txt (modified) (history)
  • /branches/wmf/1.18wmf1/includes/AutoLoader.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/media/Bitmap.php (modified) (history)
  • /branches/wmf/1.18wmf1/tests/phpunit/includes/media/BitmapScalingTest.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/docs/hooks.txt
@@ -595,6 +595,11 @@
596596 &$scalerParams: Array with scaler parameters
597597 &$mto: null, set to a MediaTransformOutput
598598
 599+'BitmapHandlerCheckImageArea': by BitmapHandler::normaliseParams, after all normalizations have been performed, except for the $wgMaxImageArea check
 600+$image: File
 601+&$params: Array of parameters
 602+&$checkImageAreaHookResult: null, set to true or false to override the $wgMaxImageArea check result
 603+
599604 'PerformRetroactiveAutoblock': called before a retroactive autoblock is applied to a user
600605 $block: Block object (which is set to be autoblocking)
601606 &$blockIds: Array of block IDs of the autoblock
Index: branches/wmf/1.18wmf1/tests/phpunit/includes/media/BitmapScalingTest.php
@@ -3,13 +3,16 @@
44 class BitmapScalingTest extends MediaWikiTestCase {
55
66 function setUp() {
7 - global $wgMaxImageArea;
 7+ global $wgMaxImageArea, $wgCustomConvertCommand;
88 $this->oldMaxImageArea = $wgMaxImageArea;
 9+ $this->oldCustomConvertCommand = $wgCustomConvertCommand;
910 $wgMaxImageArea = 1.25e7; // 3500x3500
 11+ $wgCustomConvertCommand = 'dummy'; // Set so that we don't get client side rendering
1012 }
1113 function tearDown() {
12 - global $wgMaxImageArea;
 14+ global $wgMaxImageArea, $wgCustomConvertCommand;
1315 $wgMaxImageArea = $this->oldMaxImageArea;
 16+ $wgCustomConvertCommand = $this->oldCustomConvertCommand;
1417 }
1518 /**
1619 * @dataProvider provideNormaliseParams
@@ -105,22 +108,31 @@
106109 $file = new FakeDimensionFile( array( 4000, 4000 ) );
107110 $handler = new BitmapHandler;
108111 $params = array( 'width' => '3700' ); // Still bigger than max size.
109 - $this->assertFalse( $handler->normaliseParams( $file, $params ) );
 112+ $this->assertEquals( 'TransformParameterError',
 113+ get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
110114 }
111115 function testTooBigMustRenderImage() {
112116 $file = new FakeDimensionFile( array( 4000, 4000 ) );
113117 $file->mustRender = true;
114118 $handler = new BitmapHandler;
115119 $params = array( 'width' => '5000' ); // Still bigger than max size.
116 - $this->assertFalse( $handler->normaliseParams( $file, $params ) );
 120+ $this->assertEquals( 'TransformParameterError',
 121+ get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
117122 }
 123+
 124+ function testImageArea() {
 125+ $file = new FakeDimensionFile( array( 7, 9 ) );
 126+ $handler = new BitmapHandler;
 127+ $this->assertEquals( 63, $handler->getImageArea( $file ) );
 128+ }
118129 }
119130
120131 class FakeDimensionFile extends File {
121132 public $mustRender = false;
122133
123134 public function __construct( $dimensions ) {
124 - parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), null );
 135+ parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
 136+ new NullRepo( null ) );
125137
126138 $this->dimensions = $dimensions;
127139 }
@@ -133,4 +145,7 @@
134146 public function mustRender() {
135147 return $this->mustRender;
136148 }
 149+ public function getPath() {
 150+ return '';
 151+ }
137152 }
Index: branches/wmf/1.18wmf1/includes/media/Bitmap.php
@@ -21,12 +21,10 @@
2222 * @return bool
2323 */
2424 function normaliseParams( $image, &$params ) {
25 - global $wgMaxImageArea;
2625 if ( !parent::normaliseParams( $image, $params ) ) {
2726 return false;
2827 }
2928
30 - $mimeType = $image->getMimeType();
3129 # Obtain the source, pre-rotation dimensions
3230 $srcWidth = $image->getWidth( $params['page'] );
3331 $srcHeight = $image->getHeight( $params['page'] );
@@ -42,15 +40,22 @@
4341 return true;
4442 }
4543 }
46 -
47 - # Don't thumbnail an image so big that it will fill hard drives and send servers into swap
48 - # JPEG has the handy property of allowing thumbnailing without full decompression, so we make
49 - # an exception for it.
50 - # @todo FIXME: This actually only applies to ImageMagick
51 - if ( $mimeType !== 'image/jpeg' &&
52 - $srcWidth * $srcHeight > $wgMaxImageArea )
53 - {
54 - return false;
 44+
 45+ # Check if the file is smaller than the maximum image area for thumbnailing
 46+ $checkImageAreaHookResult = null;
 47+ wfRunHooks( 'BitmapHandlerCheckImageArea', array( $image, &$params, &$checkImageAreaHookResult ) );
 48+ if ( is_null( $checkImageAreaHookResult ) ) {
 49+ global $wgMaxImageArea;
 50+
 51+ if ( $srcWidth * $srcHeight > $wgMaxImageArea &&
 52+ !( $image->getMimeType() == 'image/jpeg' &&
 53+ self::getScalerType( false, false ) == 'im' ) ) {
 54+ # Only ImageMagick can efficiently downsize jpg images without loading
 55+ # the entire file in memory
 56+ return false;
 57+ }
 58+ } else {
 59+ return $checkImageAreaHookResult;
5560 }
5661
5762 return true;
Index: branches/wmf/1.18wmf1/includes/AutoLoader.php
@@ -458,6 +458,7 @@
459459 'LocalFileMoveBatch' => 'includes/filerepo/LocalFile.php',
460460 'LocalFileRestoreBatch' => 'includes/filerepo/LocalFile.php',
461461 'LocalRepo' => 'includes/filerepo/LocalRepo.php',
 462+ 'NullRepo' => 'includes/filerepo/NullRepo.php',
462463 'OldLocalFile' => 'includes/filerepo/OldLocalFile.php',
463464 'RepoGroup' => 'includes/filerepo/RepoGroup.php',
464465 'UnregisteredLocalFile' => 'includes/filerepo/UnregisteredLocalFile.php',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99911Per bug 28135, disable $wgMaxImageArea check when transforming using a hook, ...btongminh20:36, 15 October 2011
r99916Follow-up r99911: fix tests...btongminh21:38, 15 October 2011
r99917Revert unrelated changes from r99916btongminh21:40, 15 October 2011
r101677Per comments on r99911 move $wgMaxImageArea check back to normaliseParams(). ...btongminh20:48, 2 November 2011
r104386Fix for r99911: don't use getImageArea() to determine the area for comparison...tstarling04:37, 28 November 2011
r104387Fix for r101677: remove the extra parameters from the other getImageArea() ca...tstarling04:40, 28 November 2011

Status & tagging log