Replace deprecated Context::getStats() with MWServices::getStatsdDataFactory()
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index 9188cd9..e367812 100644 (file)
@@ -5,6 +5,7 @@
  *
  * Represents files in a repository.
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Base code for files.
@@ -127,7 +128,7 @@ abstract class File implements IDBAccessObject {
        /** @var string Relative path including trailing slash */
        protected $hashPath;
 
-       /** @var string Number of pages of a multipage document, or false for
+       /** @var string|false Number of pages of a multipage document, or false for
         *    documents which aren't multipage documents
         */
        protected $pageCount;
@@ -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 ) {
@@ -535,7 +536,7 @@ abstract class File implements IDBAccessObject {
        /**
         * Get the duration of a media file in seconds
         *
-        * @return int
+        * @return float|int
         */
        public function getLength() {
                $handler = $this->getHandler();
@@ -909,7 +910,7 @@ abstract class File implements IDBAccessObject {
         *
         * @param array $handlerParams
         *
-        * @return string
+        * @return ThumbnailImage|MediaTransformOutput|bool False on failure
         */
        function getUnscaledThumb( $handlerParams = [] ) {
                $hp =& $handlerParams;
@@ -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' );
        }
 
        /**
@@ -1792,7 +1793,7 @@ abstract class File implements IDBAccessObject {
 
        /**
         * Move or copy a file to its public location. If a file exists at the
-        * destination, move it to an archive. Returns a FileRepoStatus object with
+        * destination, move it to an archive. Returns a Status object with
         * the archive name in the "value" member on success.
         *
         * The archive name should be passed through to recordUpload for database
@@ -1963,7 +1964,7 @@ abstract class File implements IDBAccessObject {
         * Returns the number of pages of a multipage document, or false for
         * documents which aren't multipage documents
         *
-        * @return bool|int
+        * @return string|bool|int
         */
        function pageCount() {
                if ( !isset( $this->pageCount ) ) {
@@ -1991,7 +1992,7 @@ abstract class File implements IDBAccessObject {
                if ( $srcWidth == 0 ) {
                        return 0;
                } else {
-                       return round( $srcHeight * $dstWidth / $srcWidth );
+                       return (int)round( $srcHeight * $dstWidth / $srcWidth );
                }
        }
 
@@ -2003,7 +2004,7 @@ abstract class File implements IDBAccessObject {
         *  a good reason. This method skips all caches.
         *
         * @param string $filePath The path to the file (e.g. From getLocalPathRef() )
-        * @return array The width, followed by height, with optionally more things after
+        * @return array|false The width, followed by height, with optionally more things after
         */
        function getImageSize( $filePath ) {
                if ( !$this->getHandler() ) {
@@ -2031,7 +2032,7 @@ abstract class File implements IDBAccessObject {
         * Get the HTML text of the description page, if available
         *
         * @param bool|Language $lang Optional language to fetch description in
-        * @return string
+        * @return string|false
         */
        function getDescriptionText( $lang = false ) {
                global $wgLang;
@@ -2122,7 +2123,7 @@ abstract class File implements IDBAccessObject {
        /**
         * Get the deletion archive key, "<sha1>.<ext>"
         *
-        * @return string
+        * @return string|false
         */
        function getStorageKey() {
                $hash = $this->getSha1();