X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryImageInfo.php;h=333b7693b41ac012aa60ee0a70b61eb55af6d6df;hb=4691389fa46f79cbeaf2daffda407cf7daa66fd4;hp=177b248b9dd9c18441d5abc67a892044b76932cd;hpb=af363e85a0de038a4349de5f5bef22fc06cc998b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 177b248b9d..333b7693b4 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -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; @@ -112,7 +115,7 @@ class ApiQueryImageInfo extends ApiQueryBase { $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 @@ -127,7 +130,7 @@ class ApiQueryImageInfo extends ApiQueryBase { if ( count( $pageIds[NS_FILE] ) == 1 ) { // See the 'the user is screwed' comment below $this->setContinueEnumParameter( 'start', - $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) + $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) ); } else { $this->setContinueEnumParameter( 'continue', @@ -143,7 +146,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 @@ -152,7 +155,7 @@ class ApiQueryImageInfo extends ApiQueryBase { // thing again. When the violating queries have been // out-continued, the result will get through $this->setContinueEnumParameter( 'start', - $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) + $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) ); } else { $this->setContinueEnumParameter( 'continue', @@ -299,7 +302,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 +312,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 +372,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 +429,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 +510,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 +651,6 @@ class ApiQueryImageInfo extends ApiQueryBase { } public function getAllowedParams() { - global $wgContLang; - return [ 'prop' => [ ApiBase::PARAM_ISMULTI => true, @@ -690,7 +689,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',