Process content headers when metadata is empty
authorGilles Dubuc <gilles@wikimedia.org>
Tue, 30 May 2017 11:19:49 +0000 (13:19 +0200)
committerGilles Dubuc <gilles@wikimedia.org>
Fri, 2 Jun 2017 15:12:09 +0000 (17:12 +0200)
The new width/height override means that files without
any metadata can get content headers.

Bug: T150741
Change-Id: I92199a4aa9e0408572ebf7d8e4c04cd0196f0d0a

includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php
includes/media/DjVu.php

index 0ad0527..53211fe 100644 (file)
@@ -2165,13 +2165,15 @@ abstract class File implements IDBAccessObject {
                if ( $handler ) {
                        $metadata = $this->getMetadata();
 
-                       if ( $metadata ) {
-                               if ( is_string( $metadata ) ) {
-                                       $metadata = MediaWiki\quietCall( 'unserialize', $metadata );
-                               }
+                       if ( is_string( $metadata ) ) {
+                               $metadata = MediaWiki\quietCall( 'unserialize', $metadata );
+                       }
 
-                               return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() );
+                       if ( !is_array( $metadata ) ) {
+                               $metadata = [];
                        }
+
+                       return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() );
                }
 
                return [];
index 8514cc8..a90156f 100644 (file)
@@ -1202,6 +1202,10 @@ class LocalFile extends File {
                if ( $handler ) {
                        $metadata = MediaWiki\quietCall( 'unserialize', $props['metadata'] );
 
+                       if ( !is_array( $metadata ) ) {
+                               $metadata = [];
+                       }
+
                        $options['headers'] = $handler->getContentHeaders(
                                $metadata, $props['width'], $props['height']
                        );
index dcd276c..f260850 100644 (file)
@@ -471,7 +471,7 @@ class DjVuHandler extends ImageHandler {
        * @since 1.30
        */
        public function getContentHeaders( $metadata, $fallbackWidth = null, $fallbackHeight = null ) {
-               if ( !is_array( $metadata ) || !isset( $metadata['xml'] ) ) {
+               if ( !isset( $metadata['xml'] ) ) {
                        return [];
                }