From c2ea52a545090e187ece796b474d010484d208e9 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Thu, 8 Jun 2017 22:30:07 +0200 Subject: [PATCH] Remove X-Content-Dimensions header Reverts 84e4d7508893, and parts of cdfe08439c3b and 4511f6fa9fa0. Bug: T150741 Bug: T167034 Change-Id: I39cfcf2cb231b6dfef569968fba6f473da258916 --- RELEASE-NOTES-1.30 | 3 -- includes/filerepo/file/File.php | 2 +- includes/filerepo/file/LocalFile.php | 4 +- .../libs/filebackend/FileBackendStore.php | 2 +- includes/media/DjVu.php | 39 ------------------- includes/media/MediaHandler.php | 26 +------------ maintenance/importImages.php | 4 +- .../includes/media/MediaHandlerTest.php | 23 ----------- .../includes/media/XContentDimensionsTest.php | 31 --------------- 9 files changed, 6 insertions(+), 128 deletions(-) delete mode 100644 tests/phpunit/includes/media/XContentDimensionsTest.php diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index 343c296c81..7595d2379c 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -34,9 +34,6 @@ production. ParserOptions::setWrapOutputClass(). * Added 'ChangeTagsAllowedAdd' hook, enabling extensions to allow software- specific tags to be added by users. -* File storage backends that supports headers (eg. Swift) now store an - X-Content-Dimensions header for originals that contain the media's dimensions - as page ranges keyed by dimensions. * Added a 'ParserOptionsRegister' hook to allow extensions to register additional parser options. diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 53211febab..9aa2b186e5 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2173,7 +2173,7 @@ abstract class File implements IDBAccessObject { $metadata = []; } - return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() ); + return $handler->getContentHeaders( $metadata ); } return []; diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index a90156fad1..8d715e824a 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1206,9 +1206,7 @@ class LocalFile extends File { $metadata = []; } - $options['headers'] = $handler->getContentHeaders( - $metadata, $props['width'], $props['height'] - ); + $options['headers'] = $handler->getContentHeaders( $metadata ); } else { $options['headers'] = []; } diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index e2f7886c1a..039bd42508 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1250,7 +1250,7 @@ abstract class FileBackendStore extends FileBackend { * @return array */ protected function sanitizeOpHeaders( array $op ) { - static $longs = [ 'content-disposition', 'x-content-dimensions' ]; + static $longs = [ 'content-disposition' ]; if ( isset( $op['headers'] ) ) { // op sets HTTP headers $newHeaders = []; diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index f260850acc..aae66d37e0 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -461,43 +461,4 @@ class DjVuHandler extends ImageHandler { return false; } } - - /** - * Get useful response headers for GET/HEAD requests for a file with the given metadata - * @param $metadata Array Contains this handler's unserialized getMetadata() for a file - * @param $fallbackWidth int|null Width to fall back to if metadata doesn't have any - * @param $fallbackHeight int|null Height to fall back to if metadata doesn't have any - * @return Array - * @since 1.30 - */ - public function getContentHeaders( $metadata, $fallbackWidth = null, $fallbackHeight = null ) { - if ( !isset( $metadata['xml'] ) ) { - return []; - } - - $trees = $this->extractTreesFromMetadata( $metadata['xml'] ); - $dimensionInfo = $this->getDimensionInfoFromMetaTree( $trees['MetaTree'] ); - - if ( !$dimensionInfo ) { - return []; - } - - $pagesByDimensions = []; - $count = $dimensionInfo['pageCount']; - - for ( $i = 1; $i <= $count; $i++ ) { - $dimensions = $dimensionInfo['dimensionsByPage'][ $i - 1 ]; - $dimensionString = $dimensions['width'] . 'x' . $dimensions['height']; - - if ( isset ( $pagesByDimensions[ $dimensionString ] ) ) { - $pagesByDimensions[ $dimensionString ][] = $i; - } else { - $pagesByDimensions[ $dimensionString ] = [ $i ]; - } - } - - $pageRangesByDimensions = MediaHandler::getPageRangesByDimensions( $pagesByDimensions ); - - return [ 'X-Content-Dimensions' => $pageRangesByDimensions ]; - } } diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index ec4d372927..88962642e5 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -916,32 +916,10 @@ abstract class MediaHandler { /** * Get useful response headers for GET/HEAD requests for a file with the given metadata * @param $metadata Array Contains this handler's unserialized getMetadata() for a file - * @param $fallbackWidth int|null Width to fall back to if metadata doesn't have any - * @param $fallbackHeight int|null Height to fall back to if metadata doesn't have any * @return Array * @since 1.30 */ - public function getContentHeaders( $metadata, $fallbackWidth = null, $fallbackHeight = null ) { - if ( !isset( $metadata['width'] ) ) { - if ( is_null( $fallbackWidth ) ) { - return []; - } - - $metadata['width'] = $fallbackWidth; - } - - if ( !isset( $metadata['height'] ) ) { - if ( is_null( $fallbackHeight ) ) { - return []; - } - - $metadata['height'] = $fallbackHeight; - } - - $dimensionString = $metadata['width'] . 'x' . $metadata['height']; - $pagesByDimensions = [ $dimensionString => [ 1 ] ]; - $pageRangesByDimensions = MediaHandler::getPageRangesByDimensions( $pagesByDimensions ); - - return [ 'X-Content-Dimensions' => $pageRangesByDimensions ]; + public function getContentHeaders( $metadata ) { + return []; } } diff --git a/maintenance/importImages.php b/maintenance/importImages.php index d3967037c6..b3866c13a2 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -309,9 +309,7 @@ class ImportImages extends Maintenance { if ( $handler ) { $metadata = MediaWiki\quietCall( 'unserialize', $props['metadata'] ); - $publishOptions['headers'] = $handler->getContentHeaders( - $metadata, $props['width'], $props['height'] - ); + $publishOptions['headers'] = $handler->getContentHeaders( $metadata ); } else { $publishOptions['headers'] = []; } diff --git a/tests/phpunit/includes/media/MediaHandlerTest.php b/tests/phpunit/includes/media/MediaHandlerTest.php index 530afa0ce9..7a052f6035 100644 --- a/tests/phpunit/includes/media/MediaHandlerTest.php +++ b/tests/phpunit/includes/media/MediaHandlerTest.php @@ -65,27 +65,4 @@ class MediaHandlerTest extends MediaWikiTestCase { } return $result; } - - /** - * @covers MediaHandler::getPageRangesByDimensions - * - * @dataProvider provideTestGetPageRangesByDimensions - */ - public function testGetPageRangesByDimensions( $pagesByDimensions, $expected ) { - $this->assertEquals( $expected, MediaHandler::getPageRangesByDimensions( $pagesByDimensions ) ); - } - - public static function provideTestGetPageRangesByDimensions() { - return [ - [ [ '123x456' => [ 1 ] ], '123x456:1' ], - [ [ '123x456' => [ 1, 2 ] ], '123x456:1-2' ], - [ [ '123x456' => [ 1, 2, 3 ] ], '123x456:1-3' ], - [ [ '123x456' => [ 1, 2, 3, 5 ] ], '123x456:1-3,5' ], - [ [ '123x456' => [ 1, 3 ] ], '123x456:1,3' ], - [ [ '123x456' => [ 1, 2, 3, 5, 6, 7 ] ], '123x456:1-3,5-7' ], - [ [ '123x456' => [ 1, 2, 3, 5, 6, 7 ], - '789x789' => [ 4, 8, 9 ] ], '123x456:1-3,5-7/789x789:4,8-9' - ], - ]; - } } diff --git a/tests/phpunit/includes/media/XContentDimensionsTest.php b/tests/phpunit/includes/media/XContentDimensionsTest.php deleted file mode 100644 index dddcc98829..0000000000 --- a/tests/phpunit/includes/media/XContentDimensionsTest.php +++ /dev/null @@ -1,31 +0,0 @@ -dataFile( $filename ); - $headers = $file->getContentHeaders(); - $this->assertEquals( true, isset( $headers['X-Content-Dimensions'] ) ); - $this->assertEquals( $headers['X-Content-Dimensions'], $expectedXContentDimensions ); - } - - public static function provideGetContentHeaders() { - return [ - [ '80x60-2layers.xcf', '80x60:1' ], - [ 'animated.gif', '45x30:1' ], - [ 'landscape-plain.jpg', '1024x768:1' ], - [ 'portrait-rotated.jpg', '768x1024:1' ], - [ 'Wikimedia-logo.svg', '1024x1024:1' ], - [ 'webp_animated.webp', '300x225:1' ], - [ 'test.tiff', '20x20:1' ], - ]; - } -} -- 2.20.1