mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PdfHandler
synced 2024-11-24 08:14:37 +00:00
Store original media dimensions as additional header
For storage repos that support headers (such as Swift), this will store the original media dimensions as an extra custom header, X-Content-Dimensions. The header is formatted to minimize its length when dealing with multipage documents, by expressing the information as page ranges keyed by dimensions. Example for a multipage documents with some pages of different sizes: X-Content-Dimensions: 1903x899:1-9,11/1903x873:10 Example for a single page document: X-Content-Dimensions: 800x600:1 Bug: T150741 Change-Id: If4c58ad7048c8233ef2b0f64a252c16f84dcecde Depends-On: Ic4c6a86557b3705cf75d074753e9ce2ee070a6df
This commit is contained in:
parent
6766ffc58b
commit
b8699d160b
|
@ -433,4 +433,28 @@ class PdfHandler extends ImageHandler {
|
|||
'messages' => array_values( self::$messages ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return array
|
||||
*/
|
||||
public function getContentHeaders( $metadata ) {
|
||||
$pagesByDimensions = [];
|
||||
$count = intval( $metadata['Pages'] );
|
||||
for ( $i = 1; $i <= $count; $i++ ) {
|
||||
$dimensions = PdfImage::getPageSize( $metadata, $i );
|
||||
$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 ];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue