jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/357895 )
Change subject: Remove X-Content-Dimensions header ...................................................................... Remove X-Content-Dimensions header Reverts 84e4d7508893, and parts of cdfe08439c3b and 4511f6fa9fa0. Bug: T150741 Bug: T167034 Change-Id: I39cfcf2cb231b6dfef569968fba6f473da258916 --- M RELEASE-NOTES-1.30 M includes/filerepo/file/File.php M includes/filerepo/file/LocalFile.php M includes/libs/filebackend/FileBackendStore.php M includes/media/DjVu.php M includes/media/MediaHandler.php M maintenance/importImages.php M tests/phpunit/includes/media/MediaHandlerTest.php D tests/phpunit/includes/media/XContentDimensionsTest.php 9 files changed, 6 insertions(+), 128 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index 343c296..7595d23 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -34,9 +34,6 @@ 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 53211fe..9aa2b18 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2173,7 +2173,7 @@ $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 a90156f..8d715e8 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1206,9 +1206,7 @@ $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 e2f7886..039bd42 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1250,7 +1250,7 @@ * @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 f260850a..aae66d3 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -461,43 +461,4 @@ 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 ec4d372..8896264 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -916,32 +916,10 @@ /** * 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 d396703..b3866c1 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -309,9 +309,7 @@ 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 530afa0..7a052f6 100644 --- a/tests/phpunit/includes/media/MediaHandlerTest.php +++ b/tests/phpunit/includes/media/MediaHandlerTest.php @@ -65,27 +65,4 @@ } 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 dddcc98..0000000 --- a/tests/phpunit/includes/media/XContentDimensionsTest.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -/** - * @group Media - */ -class XContentDimensionsTest extends MediaWikiMediaTestCase { - /** - * @param string $filename - * @param string $expectedXContentDimensions - * @dataProvider provideGetContentHeaders - * @covers File::getContentHeaders - */ - public function testGetContentHeaders( $filename, $expectedXContentDimensions ) { - $file = $this->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' ], - ]; - } -} -- To view, visit https://gerrit.wikimedia.org/r/357895 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I39cfcf2cb231b6dfef569968fba6f473da258916 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Filippo Giunchedi <fgiunch...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com> Gerrit-Reviewer: TTO <at.li...@live.com.au> Gerrit-Reviewer: Tpt <thoma...@hotmail.fr> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits