Merge "API: Expose wfIsBadImage() in prop=imageinfo"
This commit is contained in:
commit
30f2850124
4 changed files with 31 additions and 7 deletions
|
|
@ -3518,7 +3518,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
|
|||
# Run the extension hook
|
||||
$bad = false;
|
||||
if ( !Hooks::run( 'BadImage', [ $name, &$bad ] ) ) {
|
||||
return $bad;
|
||||
return (bool)$bad;
|
||||
}
|
||||
|
||||
$cache = ObjectCache::getLocalServerInstance( 'hash' );
|
||||
|
|
|
|||
|
|
@ -58,6 +58,15 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
'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] );
|
||||
|
|
@ -95,13 +104,16 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
|
||||
$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 ) ],
|
||||
|
|
@ -128,10 +140,14 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
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
|
||||
|
|
@ -688,6 +704,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
ApiBase::PARAM_DFLT => '',
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
],
|
||||
'badfilecontexttitle' => [
|
||||
ApiBase::PARAM_TYPE => 'string',
|
||||
],
|
||||
'continue' => [
|
||||
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
||||
],
|
||||
|
|
@ -733,6 +752,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
|
|||
'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 )
|
||||
);
|
||||
|
|
|
|||
|
|
@ -808,6 +808,7 @@
|
|||
"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.",
|
||||
|
|
@ -818,6 +819,7 @@
|
|||
"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.",
|
||||
|
|
|
|||
|
|
@ -756,6 +756,7 @@
|
|||
"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}}",
|
||||
|
|
@ -766,6 +767,7 @@
|
|||
"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}}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue