Remove ApiQueryImageInfo::(getProperties|getPropertyDescriptions)
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
index 8994e06..0791426 100644 (file)
@@ -20,6 +20,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A query action to get image information and upload history.
  *
@@ -57,7 +59,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
                if ( isset( $params['badfilecontexttitle'] ) ) {
                        $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
                        if ( !$badFileContextTitle ) {
-                               $this->dieUsage( 'Invalid title in badfilecontexttitle parameter', 'invalid-title' );
+                               $p = $this->getModulePrefix();
+                               $this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
                        }
                } else {
                        $badFileContextTitle = false;
@@ -107,12 +110,13 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                if ( !isset( $images[$title] ) ) {
                                        if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
                                                // uploadwarning and badfile need info about non-existing files
-                                               $images[$title] = wfLocalFile( $title );
+                                               $images[$title] = MediaWikiServices::getInstance()->getRepoGroup()
+                                                       ->getLocalRepo()->newFile( $title );
                                                // Doesn't exist, so set an empty image repository
                                                $info['imagerepository'] = '';
                                        } else {
                                                $result->addValue(
-                                                       [ 'query', 'pages', intval( $pageId ) ],
+                                                       [ 'query', 'pages', (int)$pageId ],
                                                        'imagerepository', ''
                                                );
                                                // The above can't fail because it doesn't increase the result size
@@ -143,7 +147,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                        $info['badfile'] = (bool)wfIsBadImage( $title, $badFileContextTitle );
                                }
 
-                               $fit = $result->addValue( [ 'query', 'pages' ], intval( $pageId ), $info );
+                               $fit = $result->addValue( [ 'query', 'pages' ], (int)$pageId, $info );
                                if ( !$fit ) {
                                        if ( count( $pageIds[NS_FILE] ) == 1 ) {
                                                // The user is screwed. imageinfo can't be solely
@@ -246,13 +250,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
                        $scale = [];
                        $scale['height'] = $params['urlheight'];
+               } elseif ( $params['urlparam'] ) {
+                       // Audio files might not have a width/height.
+                       $scale = [];
                } else {
-                       if ( $params['urlparam'] ) {
-                               // Audio files might not have a width/height.
-                               $scale = [];
-                       } else {
-                               $scale = null;
-                       }
+                       $scale = null;
                }
 
                return $scale;
@@ -299,7 +301,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
 
                $paramList = $h->parseParamString( $otherParams );
                if ( !$paramList ) {
-                       // Just set a warning (instead of dieUsage), as in many cases
+                       // Just set a warning (instead of dieWithError), as in many cases
                        // we could still render the image using width and height parameters,
                        // and this type of thing could happen between different versions of
                        // handlers.
@@ -309,7 +311,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
                }
 
                if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
-                       if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
+                       if ( (int)$paramList['width'] != (int)$thumbParams['width'] ) {
                                $this->addWarning(
                                        [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
                                );
@@ -369,14 +371,12 @@ class ApiQueryImageInfo extends ApiQueryBase {
         * @return array Result array
         */
        public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
-               global $wgContLang;
-
                $anyHidden = false;
 
                if ( !$opts || is_string( $opts ) ) {
                        $opts = [
                                'version' => $opts ?: 'latest',
-                               'language' => $wgContLang,
+                               'language' => MediaWikiServices::getInstance()->getContentLanguage(),
                                'multilang' => false,
                                'extmetadatafilter' => [],
                                'revdelUser' => null,
@@ -428,9 +428,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
                // This is shown even if the file is revdelete'd in interface
                // so do same here.
                if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
-                       $vals['size'] = intval( $file->getSize() );
-                       $vals['width'] = intval( $file->getWidth() );
-                       $vals['height'] = intval( $file->getHeight() );
+                       $vals['size'] = (int)$file->getSize();
+                       $vals['width'] = (int)$file->getWidth();
+                       $vals['height'] = (int)$file->getHeight();
 
                        $pageCount = $file->pageCount();
                        if ( $pageCount !== false ) {
@@ -509,11 +509,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
                                                // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
                                                // thumbnail sizes for the thumbnail actual size
                                                if ( $mto->getUrl() !== $file->getUrl() ) {
-                                                       $vals['thumbwidth'] = intval( $mto->getWidth() );
-                                                       $vals['thumbheight'] = intval( $mto->getHeight() );
+                                                       $vals['thumbwidth'] = (int)$mto->getWidth();
+                                                       $vals['thumbheight'] = (int)$mto->getHeight();
                                                } else {
-                                                       $vals['thumbwidth'] = intval( $file->getWidth() );
-                                                       $vals['thumbheight'] = intval( $file->getHeight() );
+                                                       $vals['thumbwidth'] = (int)$file->getWidth();
+                                                       $vals['thumbheight'] = (int)$file->getHeight();
                                                }
 
                                                if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
@@ -650,8 +650,6 @@ class ApiQueryImageInfo extends ApiQueryBase {
        }
 
        public function getAllowedParams() {
-               global $wgContLang;
-
                return [
                        'prop' => [
                                ApiBase::PARAM_ISMULTI => true,
@@ -690,7 +688,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
                        ],
                        'extmetadatalanguage' => [
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_DFLT => $wgContLang->getCode(),
+                               ApiBase::PARAM_DFLT =>
+                                       MediaWikiServices::getInstance()->getContentLanguage()->getCode(),
                        ],
                        'extmetadatamultilang' => [
                                ApiBase::PARAM_TYPE => 'boolean',
@@ -758,58 +757,6 @@ class ApiQueryImageInfo extends ApiQueryBase {
                );
        }
 
-       /**
-        * Returns array key value pairs of properties and their descriptions
-        *
-        * @deprecated since 1.25
-        * @param string $modulePrefix
-        * @return array
-        */
-       private static function getProperties( $modulePrefix = '' ) {
-               return [
-                       'timestamp' => ' timestamp     - Adds timestamp for the uploaded version',
-                       'user' => ' user          - Adds the user who uploaded the image version',
-                       'userid' => ' userid        - Add the user ID that uploaded the image version',
-                       'comment' => ' comment       - Comment on the version',
-                       'parsedcomment' => ' parsedcomment - Parse the comment on the version',
-                       'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
-                       'url' => ' url           - Gives URL to the image and the description page',
-                       'size' => ' size          - Adds the size of the image in bytes, ' .
-                               'its height and its width. Page count and duration are added if applicable',
-                       'dimensions' => ' dimensions    - Alias for size', // B/C with Allimages
-                       'sha1' => ' sha1          - Adds SHA-1 hash for the image',
-                       'mime' => ' mime          - Adds MIME type of the image',
-                       'thumbmime' => ' thumbmime     - Adds MIME type of the image thumbnail' .
-                               ' (requires url and param ' . $modulePrefix . 'urlwidth)',
-                       'mediatype' => ' mediatype     - Adds the media type of the image',
-                       'metadata' => ' metadata      - Lists Exif metadata for the version of the image',
-                       'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
-                               'for the version of the image',
-                       'extmetadata' => ' extmetadata   - Lists formatted metadata combined ' .
-                               'from multiple sources. Results are HTML formatted.',
-                       'archivename' => ' archivename   - Adds the file name of the archive ' .
-                               'version for non-latest versions',
-                       'bitdepth' => ' bitdepth      - Adds the bit depth of the version',
-                       'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
-                               'get information about an existing file. Not intended for use outside MediaWiki core',
-               ];
-       }
-
-       /**
-        * Returns the descriptions for the properties provided by getPropertyNames()
-        *
-        * @deprecated since 1.25
-        * @param array $filter List of properties to filter out
-        * @param string $modulePrefix
-        * @return array
-        */
-       public static function getPropertyDescriptions( $filter = [], $modulePrefix = '' ) {
-               return array_merge(
-                       [ 'What image information to get:' ],
-                       array_values( array_diff_key( static::getProperties( $modulePrefix ), array_flip( $filter ) ) )
-               );
-       }
-
        protected function getExamplesMessages() {
                return [
                        'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'