r102751 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102750‎ | r102751 | r102752 >
Date:04:09, 11 November 2011
Author:bawolff
Status:ok (Comments)
Tags:
Comment:
(follow-up r99910) Make $wgEnableAutoRotation work...

Also unit-tests. There's a bit of duplication in the unit tests, and I wasn't sure if there was a better way with less duplication.
Modified paths:
  • /trunk/phase3/includes/media/ExifBitmap.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/media/ExifRotationTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/ExifBitmap.php
@@ -134,12 +134,17 @@
135135 * @return array
136136 */
137137 function getImageSize( $image, $path ) {
 138+ global $wgEnableAutoRotation;
138139 $gis = parent::getImageSize( $image, $path );
139140
140141 // Don't just call $image->getMetadata(); File::getPropsFromPath() calls us with a bogus object.
141142 // This may mean we read EXIF data twice on initial upload.
142 - $meta = $this->getMetadata( $image, $path );
143 - $rotation = $this->getRotationForExif( $meta );
 143+ if ( $wgEnableAutoRotation ) {
 144+ $meta = $this->getMetadata( $image, $path );
 145+ $rotation = $this->getRotationForExif( $meta );
 146+ } else {
 147+ $rotation = 0;
 148+ }
144149
145150 if ($rotation == 90 || $rotation == 270) {
146151 $width = $gis[0];
Index: trunk/phase3/tests/phpunit/includes/media/ExifRotationTest.php
@@ -20,10 +20,15 @@
2121 global $wgShowEXIF;
2222 $this->show = $wgShowEXIF;
2323 $wgShowEXIF = true;
 24+
 25+ global $wgEnableAutoRotation;
 26+ $this->oldAuto = $wgEnableAutoRotation;
 27+ $wgEnableAutoRotation = true;
2428 }
2529 public function tearDown() {
26 - global $wgShowEXIF;
 30+ global $wgShowEXIF, $wgEnableAutoRotation;
2731 $wgShowEXIF = $this->show;
 32+ $wgEnableAutoRotation = $this->oldAuto;
2833 }
2934
3035 /**
@@ -31,6 +36,9 @@
3237 * @dataProvider providerFiles
3338 */
3439 function testMetadata( $name, $type, $info ) {
 40+ if ( !BitmapHandler::canRotate() ) {
 41+ $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
 42+ }
3543 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $name, $type );
3644 $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
3745 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
@@ -41,6 +49,9 @@
4250 * @dataProvider providerFiles
4351 */
4452 function testRotationRendering( $name, $type, $info, $thumbs ) {
 53+ if ( !BitmapHandler::canRotate() ) {
 54+ $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
 55+ }
4556 foreach( $thumbs as $size => $out ) {
4657 if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
4758 $params = array(
@@ -109,6 +120,95 @@
110121 )
111122 );
112123 }
 124+
 125+ /**
 126+ * Same as before, but with auto-rotation disabled.
 127+ * @dataProvider providerFilesNoAutoRotate
 128+ */
 129+ function testMetadataNoAutoRotate( $name, $type, $info ) {
 130+ global $wgEnableAutoRotation;
 131+ $wgEnableAutoRotation = false;
 132+
 133+ $file = UnregisteredLocalFile::newFromPath( $this->filePath . $name, $type );
 134+ $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
 135+ $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
 136+
 137+ $wgEnableAutoRotation = true;
 138+ }
 139+
 140+ /**
 141+ *
 142+ * @dataProvider providerFilesNoAutoRotate
 143+ */
 144+ function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
 145+ global $wgEnableAutoRotation;
 146+ $wgEnableAutoRotation = false;
 147+
 148+ foreach( $thumbs as $size => $out ) {
 149+ if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
 150+ $params = array(
 151+ 'width' => $matches[1],
 152+ );
 153+ } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
 154+ $params = array(
 155+ 'width' => $matches[1],
 156+ 'height' => $matches[2]
 157+ );
 158+ } else {
 159+ throw new MWException('bogus test data format ' . $size);
 160+ }
 161+
 162+ $file = $this->localFile( $name, $type );
 163+ $thumb = $file->transform( $params, File::RENDER_NOW );
 164+
 165+ $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
 166+ $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
 167+
 168+ $gis = getimagesize( $thumb->getPath() );
 169+ if ($out[0] > $info['width']) {
 170+ // Physical image won't be scaled bigger than the original.
 171+ $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size");
 172+ $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size");
 173+ } else {
 174+ $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size");
 175+ $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size");
 176+ }
 177+ }
 178+ $wgEnableAutoRotation = true;
 179+ }
 180+
 181+ function providerFilesNoAutoRotate() {
 182+ return array(
 183+ array(
 184+ 'landscape-plain.jpg',
 185+ 'image/jpeg',
 186+ array(
 187+ 'width' => 1024,
 188+ 'height' => 768,
 189+ ),
 190+ array(
 191+ '800x600px' => array( 800, 600 ),
 192+ '9999x800px' => array( 1067, 800 ),
 193+ '800px' => array( 800, 600 ),
 194+ '600px' => array( 600, 450 ),
 195+ )
 196+ ),
 197+ array(
 198+ 'portrait-rotated.jpg',
 199+ 'image/jpeg',
 200+ array(
 201+ 'width' => 1024, // since not rotated
 202+ 'height' => 768, // since not rotated
 203+ ),
 204+ array(
 205+ '800x600px' => array( 800, 600 ),
 206+ '9999x800px' => array( 1067, 800 ),
 207+ '800px' => array( 800, 600 ),
 208+ '600px' => array( 600, 450 ),
 209+ )
 210+ )
 211+ );
 212+ }
113213
114214
115215 const TEST_WIDTH = 100;

Follow-up revisions

RevisionCommit summaryAuthorDate
r102792Follow-up r102751 - I think this test was intermitently failing because it wa...bawolff15:33, 11 November 2011
r103029REL1_18 MFT r99236, r102301, r102303, r102498, r102710, r102751, r102951, r10...reedy20:58, 14 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99910Per r97671, add $wgEnableAutoRotation setting that can be used to explicitly ...btongminh20:30, 15 October 2011

Comments

#Comment by Bawolff (talk | contribs)   05:31, 11 November 2011

This briefly caused unit tests on jenkins to fail, but then the didn't fail next time jenkins was run - so I don't know what's up with that. [1]

#Comment by Catrope (talk | contribs)   13:16, 11 November 2011

They've been failing intermittently since then.

Status & tagging log