Gilles has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353112 )

Change subject: Store original media dimensions as additional header
......................................................................

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: Iefeff3caceb317513ce69534ee56927b94c8ce79
Depends-On: Ic4c6a86557b3705cf75d074753e9ce2ee070a6df
---
M handlers/OggHandler/OggHandler.php
M handlers/WebMHandler/WebMHandler.php
2 files changed, 41 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/12/353112/1

diff --git a/handlers/OggHandler/OggHandler.php 
b/handlers/OggHandler/OggHandler.php
index 990fc39..83a3263 100644
--- a/handlers/OggHandler/OggHandler.php
+++ b/handlers/OggHandler/OggHandler.php
@@ -179,12 +179,13 @@
         * @param $metadata
         * @return bool|mixed
         */
-       function unpackMetadata( $metadata ) {
-               wfSuppressWarnings();
-               $unser = unserialize( $metadata );
-               wfRestoreWarnings();
-               if ( isset( $unser['version'] ) && $unser['version'] == 
self::METADATA_VERSION ) {
-                       return $unser;
+       function unpackMetadata( $metadata, $unserialize = true ) {
+               if ( $unserialize ) {
+                       $metadata = MediaWiki\quietCall( 'unserialize', 
$metadata );
+               }
+
+               if ( isset( $metadata['version'] ) && $metadata['version'] == 
self::METADATA_VERSION ) {
+                       return $metadata;
                } else {
                        return false;
                }
@@ -254,15 +255,28 @@
 
        /**
        * Get useful response headers for GET/HEAD requests for a file with the 
given metadata
-       * @param $metadata mixed Result this handlers getMetadata() for a file
+       * @param $metadata Array Contains this handler's unserialized 
getMetadata() for a file
        * @return Array
        */
-       public function getStreamHeaders( $metadata ) {
-               $metadata = $this->unpackMetadata( $metadata );
+       public function getContentHeaders( $metadata ) {
+               $packedMetadata = $metadata;
+               $result = [];
+               $metadata = $this->unpackMetadata( $metadata, false );
+
                if ( $metadata && !isset( $metadata['error'] ) && isset( 
$metadata['length'] ) ) {
-                       return [ 'X-Content-Duration' => floatval( $metadata[ 
'length' ] ) ];
+                       $result = [ 'X-Content-Duration' => floatval( 
$metadata[ 'length' ] ) ];
                }
-               return [];
+
+               $dimensions = $this->getImageSize( null, null, $packedMetadata 
);
+
+               if ( !$dimensions || !$dimensions[0] || !$dimensions[1] ) {
+                       $dimensionsHeaders = [];
+               } else {
+                       $dimensionsMetadata = [ 'width' => $dimensions[0], 
'height' => $dimensions[1] ];
+                       $dimensionsHeaders = parent::getContentHeaders( 
$dimensionsMetadata );
+               }
+
+               return array_merge( $result, $dimensionsHeaders );
        }
 
        /**
diff --git a/handlers/WebMHandler/WebMHandler.php 
b/handlers/WebMHandler/WebMHandler.php
index ce30043..f7b89cb 100644
--- a/handlers/WebMHandler/WebMHandler.php
+++ b/handlers/WebMHandler/WebMHandler.php
@@ -170,4 +170,20 @@
                        )->text();
        }
 
+       /**
+       * 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 ) {
+               $dimensions = $this->getImageSize( null, null,  $metadata );
+
+               if ( !$dimensions || !$dimensions[0] || !$dimensions[1] ) {
+                       return [];
+               }
+
+               $dimensionsMetadata = [ 'width' => $dimensions[0], 'height' => 
$dimensions[1] ];
+
+               return parent::getContentHeaders( $dimensionsMetadata );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/353112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefeff3caceb317513ce69534ee56927b94c8ce79
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: wmf/1.30.0-wmf.1
Gerrit-Owner: Gilles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to