Remove X-Content-Dimensions header
authorGilles Dubuc <gilles@wikimedia.org>
Thu, 8 Jun 2017 20:30:07 +0000 (22:30 +0200)
committerKrinkle <krinklemail@gmail.com>
Mon, 12 Jun 2017 18:07:28 +0000 (18:07 +0000)
Reverts 84e4d7508893, and parts of cdfe08439c3b and 4511f6fa9fa0.

Bug: T150741
Bug: T167034
Change-Id: I39cfcf2cb231b6dfef569968fba6f473da258916

RELEASE-NOTES-1.30
includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php
includes/libs/filebackend/FileBackendStore.php
includes/media/DjVu.php
includes/media/MediaHandler.php
maintenance/importImages.php
tests/phpunit/includes/media/MediaHandlerTest.php
tests/phpunit/includes/media/XContentDimensionsTest.php [deleted file]

index 343c296..7595d23 100644 (file)
@@ -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.
 
index 53211fe..9aa2b18 100644 (file)
@@ -2173,7 +2173,7 @@ abstract class File implements IDBAccessObject {
                                $metadata = [];
                        }
 
-                       return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() );
+                       return $handler->getContentHeaders( $metadata );
                }
 
                return [];
index a90156f..8d715e8 100644 (file)
@@ -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'] = [];
                }
index e2f7886..039bd42 100644 (file)
@@ -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 = [];
index f260850..aae66d3 100644 (file)
@@ -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 ];
-       }
 }
index ec4d372..8896264 100644 (file)
@@ -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 [];
        }
 }
index d396703..b3866c1 100644 (file)
@@ -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'] = [];
                                        }
index 530afa0..7a052f6 100644 (file)
@@ -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 (file)
index dddcc98..0000000
+++ /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' ],
-               ];
-       }
-}