'revdelUser' => $this->getUser(),
];
+ if ( isset( $params['badfilecontexttitle'] ) ) {
+ $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
+ if ( !$badFileContextTitle ) {
+ $this->dieUsage( 'Invalid title in badfilecontexttitle parameter', 'invalid-title' );
+ }
+ } else {
+ $badFileContextTitle = false;
+ }
+
$pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
if ( !empty( $pageIds[NS_FILE] ) ) {
$titles = array_keys( $pageIds[NS_FILE] );
$result = $this->getResult();
foreach ( $titles as $title ) {
+ $info = [];
$pageId = $pageIds[NS_FILE][$title];
$start = $title === $fromTitle ? $fromTimestamp : $params['start'];
if ( !isset( $images[$title] ) ) {
- if ( isset( $prop['uploadwarning'] ) ) {
- // Uploadwarning needs info about non-existing files
+ if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
+ // uploadwarning and badfile need info about non-existing files
$images[$title] = wfLocalFile( $title );
+ // Doesn't exist, so set an empty image repository
+ $info['imagerepository'] = '';
} else {
$result->addValue(
[ 'query', 'pages', intval( $pageId ) ],
break;
}
- $fit = $result->addValue(
- [ 'query', 'pages', intval( $pageId ) ],
- 'imagerepository', $img->getRepoName()
- );
+ if ( !isset( $info['imagerepository'] ) ) {
+ $info['imagerepository'] = $img->getRepoName();
+ }
+ if ( isset( $prop['badfile'] ) ) {
+ $info['badfile'] = (bool)wfIsBadImage( $title, $badFileContextTitle );
+ }
+
+ $fit = $result->addValue( [ 'query', 'pages' ], intval( $pageId ), $info );
if ( !$fit ) {
if ( count( $pageIds[NS_FILE] ) == 1 ) {
// The user is screwed. imageinfo can't be solely
$gotOne = true;
$fit = $this->addPageSubItem( $pageId,
- self::getInfo( $img, $prop, $result,
+ static::getInfo( $img, $prop, $result,
$finalThumbParams, $opts
)
);
}
$fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
$this->addPageSubItem( $pageId,
- self::getInfo( $oldie, $prop, $result,
+ static::getInfo( $oldie, $prop, $result,
$finalThumbParams, $opts
)
);
$h = $image->getHandler();
if ( !$h ) {
- $this->setWarning( 'Could not create thumbnail because ' .
- $image->getName() . ' does not have an associated image handler' );
+ $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
return $thumbParams;
}
// we could still render the image using width and height parameters,
// and this type of thing could happen between different versions of
// handlers.
- $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
- . '. Using only width and height' );
+ $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
$this->checkParameterNormalise( $image, $thumbParams );
return $thumbParams;
}
if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
- $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
- . "in favor of width value derived from {$p}urlwidth/{$p}urlheight "
- . "({$thumbParams['width']})" );
+ $this->addWarning(
+ [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
+ );
}
}
foreach ( $paramList as $name => $value ) {
if ( !$h->validateParam( $name, $value ) ) {
- $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", 'urlparam' );
+ $this->dieWithError(
+ [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
+ );
}
}
* allows us to catch certain error conditions early (such as missing
* required parameter).
*
- * @param $image File
- * @param $finalParams array List of parameters to transform image with
+ * @param File $image
+ * @param array $finalParams List of parameters to transform image with
*/
protected function checkParameterNormalise( $image, $finalParams ) {
$h = $image->getHandler();
// in the actual normalised version, only if we can actually normalise them,
// so we use the functions scope to throw away the normalisations.
if ( !$h->normaliseParams( $image, $finalParams ) ) {
- $this->dieUsage( 'Could not normalise image parameters for ' .
- $image->getName(), 'urlparamnormal' );
+ $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
}
}
if ( $mto && !$mto->isError() ) {
$vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
- // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
+ // 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() );
if ( $metadata && $version !== 'latest' ) {
$metadata = $file->convertMetadataVersion( $metadata, $version );
}
- $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
+ $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
}
if ( $commonmeta ) {
$metaArray = $file->getCommonMetaArray();
- $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : [];
+ $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
}
if ( $extmetadata ) {
ApiResult::META_BC_BOOLS => [ 'value' ],
];
if ( is_array( $value ) ) {
- $r['value'] = self::processMetaData( $value, $result );
+ $r['value'] = static::processMetaData( $value, $result );
} else {
$r['value'] = $value;
}
'prop' => [
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_DFLT => 'timestamp|user',
- ApiBase::PARAM_TYPE => self::getPropertyNames(),
- ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages(),
+ ApiBase::PARAM_TYPE => static::getPropertyNames(),
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
],
'limit' => [
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_DFLT => '',
ApiBase::PARAM_TYPE => 'string',
],
+ 'badfilecontexttitle' => [
+ ApiBase::PARAM_TYPE => 'string',
+ ],
'continue' => [
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
],
* @return array
*/
public static function getPropertyNames( $filter = [] ) {
- return array_keys( self::getPropertyMessages( $filter ) );
+ return array_keys( static::getPropertyMessages( $filter ) );
}
/**
'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
+ 'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
],
array_flip( $filter )
);
public static function getPropertyDescriptions( $filter = [], $modulePrefix = '' ) {
return array_merge(
[ 'What image information to get:' ],
- array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
+ array_values( array_diff_key( static::getProperties( $modulePrefix ), array_flip( $filter ) ) )
);
}
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Imageinfo';
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
}
}