Store original media dimensions as additional header
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index be78462..7116c22 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Represents files in a repository.
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Base code for files.
@@ -436,7 +437,7 @@ abstract class File implements IDBAccessObject {
                        $this->fsFile = $this->repo->getLocalReference( $this->getPath() );
 
                        $statTiming = microtime( true ) - $starttime;
-                       RequestContext::getMain()->getStats()->timing(
+                       MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
                                'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
 
                        if ( !$this->fsFile ) {
@@ -919,7 +920,7 @@ abstract class File implements IDBAccessObject {
                        return $this->iconThumb();
                }
                $hp['width'] = $width;
-               // be sure to ignore any height specification as well (bug 62258)
+               // be sure to ignore any height specification as well (T64258)
                unset( $hp['height'] );
 
                return $this->transform( $hp );
@@ -1039,7 +1040,7 @@ abstract class File implements IDBAccessObject {
                                break; // not a bitmap or renderable image, don't try
                        }
 
-                       // Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
+                       // Get the descriptionUrl to embed it as comment into the thumbnail. T21791.
                        $descriptionUrl = $this->getDescriptionUrl();
                        if ( $descriptionUrl ) {
                                $params['descriptionUrl'] = wfExpandUrl( $descriptionUrl, PROTO_CANONICAL );
@@ -1117,7 +1118,7 @@ abstract class File implements IDBAccessObject {
        public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
                global $wgIgnoreImageErrors;
 
-               $stats = RequestContext::getMain()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
 
                $handler = $this->getHandler();
 
@@ -1227,7 +1228,7 @@ abstract class File implements IDBAccessObject {
                // this object exists
                $tmpFile->bind( $this );
 
-               RequestContext::getMain()->getStats()->timing(
+               MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
                        'media.thumbnail.generate.bucket', 1000 * $buckettime );
 
                return true;
@@ -1766,7 +1767,7 @@ abstract class File implements IDBAccessObject {
         * @throws MWException
         */
        function readOnlyError() {
-               throw new MWException( get_class( $this ) . ': write operations are not supported' );
+               throw new MWException( static::class . ': write operations are not supported' );
        }
 
        /**
@@ -2148,15 +2149,32 @@ abstract class File implements IDBAccessObject {
        }
 
        /**
-        * @return array HTTP header name/value map to use for HEAD/GET request responses
+        * @deprecated since 1.30, use File::getContentHeaders instead
         */
        function getStreamHeaders() {
+               wfDeprecated( __METHOD__, '1.30' );
+               return $this->getContentHeaders();
+       }
+
+       /**
+        * @return array HTTP header name/value map to use for HEAD/GET request responses
+        * @since 1.30
+        */
+       function getContentHeaders() {
                $handler = $this->getHandler();
                if ( $handler ) {
-                       return $handler->getStreamHeaders( $this->getMetadata() );
-               } else {
-                       return [];
+                       $metadata = $this->getMetadata();
+
+                       if ( $metadata ) {
+                               if ( is_string( $metadata ) ) {
+                                       $metadata = MediaWiki\quietCall( 'unserialize', $metadata );
+                               }
+
+                               return $handler->getContentHeaders( $metadata );
+                       }
                }
+
+               return [];
        }
 
        /**