If iiprop=badfile is set, expose the wfIsBadImage() status as a boolean.
This is mainly intended for use by Parsoid, but could be useful for
other API users too. The context title can be set by using the
badfilecontextitle parameter.
Also be a little more paranoid and make sure wfIsBadImage() always
returns a boolean.
Bug: T148343
Change-Id: I3432ead92b8d2a17de5243285f2760fc39b501ae
# Run the extension hook
$bad = false;
if ( !Hooks::run( 'BadImage', [ $name, &$bad ] ) ) {
- return $bad;
+ return (bool)$bad;
}
$cache = ObjectCache::getLocalServerInstance( 'hash' );
'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
ApiBase::PARAM_DFLT => '',
ApiBase::PARAM_TYPE => 'string',
],
+ 'badfilecontexttitle' => [
+ ApiBase::PARAM_TYPE => 'string',
+ ],
'continue' => [
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
],
'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 )
);
"apihelp-query+imageinfo-paramvalue-prop-archivename": "Adds the filename of the archive version for non-latest versions.",
"apihelp-query+imageinfo-paramvalue-prop-bitdepth": "Adds the bit depth of the version.",
"apihelp-query+imageinfo-paramvalue-prop-uploadwarning": "Used by the Special:Upload page to get information about an existing file. Not intended for use outside MediaWiki core.",
+ "apihelp-query+imageinfo-paramvalue-prop-badfile": "Adds whether the file is on the [[MediaWiki:Bad image list]]",
"apihelp-query+imageinfo-param-limit": "How many file revisions to return per file.",
"apihelp-query+imageinfo-param-start": "Timestamp to start listing from.",
"apihelp-query+imageinfo-param-end": "Timestamp to stop listing at.",
"apihelp-query+imageinfo-param-extmetadatamultilang": "If translations for extmetadata property are available, fetch all of them.",
"apihelp-query+imageinfo-param-extmetadatafilter": "If specified and non-empty, only these keys will be returned for $1prop=extmetadata.",
"apihelp-query+imageinfo-param-urlparam": "A handler specific parameter string. For example, PDFs might use <kbd>page15-100px</kbd>. <var>$1urlwidth</var> must be used and be consistent with <var>$1urlparam</var>.",
+ "apihelp-query+imageinfo-param-badfilecontexttitle": "If <kbd>$2prop=badfile</kbd> is set, this is the page title used when evaluting the [[MediaWiki:Bad image list]]",
"apihelp-query+imageinfo-param-localonly": "Look only for files in the local repository.",
"apihelp-query+imageinfo-example-simple": "Fetch information about the current version of [[:File:Albert Einstein Head.jpg]].",
"apihelp-query+imageinfo-example-dated": "Fetch information about versions of [[:File:Test.jpg]] from 2008 and later.",
"apihelp-query+imageinfo-paramvalue-prop-archivename": "{{doc-apihelp-paramvalue|query+imageinfo|prop|archivename}}",
"apihelp-query+imageinfo-paramvalue-prop-bitdepth": "{{doc-apihelp-paramvalue|query+imageinfo|prop|bitdepth}}",
"apihelp-query+imageinfo-paramvalue-prop-uploadwarning": "{{doc-apihelp-paramvalue|query+imageinfo|prop|uploadwarning}}",
+ "apihelp-query+imageinfo-paramvalue-prop-badfile": "{{doc-apihelp-paramvalue|query+imageinfo|prop|badfile}}",
"apihelp-query+imageinfo-param-limit": "{{doc-apihelp-param|query+imageinfo|limit}}",
"apihelp-query+imageinfo-param-start": "{{doc-apihelp-param|query+imageinfo|start}}",
"apihelp-query+imageinfo-param-end": "{{doc-apihelp-param|query+imageinfo|end}}",
"apihelp-query+imageinfo-param-extmetadatamultilang": "{{doc-apihelp-param|query+imageinfo|extmetadatamultilang}}",
"apihelp-query+imageinfo-param-extmetadatafilter": "{{doc-apihelp-param|query+imageinfo|extmetadatafilter}}",
"apihelp-query+imageinfo-param-urlparam": "{{doc-apihelp-param|query+imageinfo|urlparam}}",
+ "apihelp-query+imageinfo-param-badfilecontexttitle": "{{doc-apihelp-param|query+imageinfo|badfilecontexttitle}}",
"apihelp-query+imageinfo-param-localonly": "{{doc-apihelp-param|query+imageinfo|localonly}}",
"apihelp-query+imageinfo-example-simple": "{{doc-apihelp-example|query+imageinfo}}",
"apihelp-query+imageinfo-example-dated": "{{doc-apihelp-example|query+imageinfo}}",