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.
$metadata = [];
}
- return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() );
+ return $handler->getContentHeaders( $metadata );
}
return [];
$metadata = [];
}
- $options['headers'] = $handler->getContentHeaders(
- $metadata, $props['width'], $props['height']
- );
+ $options['headers'] = $handler->getContentHeaders( $metadata );
} else {
$options['headers'] = [];
}
* @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 = [];
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 ];
- }
}
/**
* 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 [];
}
}
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'] = [];
}
}
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'
- ],
- ];
- }
}
+++ /dev/null
-<?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' ],
- ];
- }
-}