38 if ( is_null( $prefix ) ) {
41 parent::__construct( $query, $moduleName, $prefix );
47 $prop = array_flip( $params[
'prop'] );
52 'version' => $params[
'metadataversion'],
53 'language' => $params[
'extmetadatalanguage'],
54 'multilang' => $params[
'extmetadatamultilang'],
55 'extmetadatafilter' => $params[
'extmetadatafilter'],
56 'revdelUser' => $this->
getUser(),
59 if ( isset( $params[
'badfilecontexttitle'] ) ) {
60 $badFileContextTitle = Title::newFromText( $params[
'badfilecontexttitle'] );
61 if ( !$badFileContextTitle ) {
63 $this->
dieWithError( [
'apierror-bad-badfilecontexttitle', $p ],
'invalid-title' );
66 $badFileContextTitle =
null;
69 $pageIds = $this->
getPageSet()->getGoodAndMissingTitlesByNamespace();
70 if ( !empty( $pageIds[
NS_FILE] ) ) {
71 $titles = array_keys( $pageIds[
NS_FILE] );
75 if ( !is_null( $params[
'continue'] ) ) {
76 $cont = explode(
'|', $params[
'continue'] );
78 $fromTitle = strval( $cont[0] );
79 $fromTimestamp = $cont[1];
81 foreach ( $titles as $key =>
$title ) {
82 if (
$title < $fromTitle ) {
83 unset( $titles[$key] );
91 $findTitles = array_map(
function (
$title ) use ( $user ) {
98 if ( $params[
'localonly'] ) {
99 $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
101 $images = RepoGroup::singleton()->findFiles( $findTitles );
105 foreach ( $titles as
$title ) {
108 $start =
$title === $fromTitle ? $fromTimestamp : $params[
'start'];
110 if ( !isset( $images[
$title] ) ) {
111 if ( isset( $prop[
'uploadwarning'] ) || isset( $prop[
'badfile'] ) ) {
113 $images[
$title] = MediaWikiServices::getInstance()->getRepoGroup()
114 ->getLocalRepo()->newFile(
$title );
116 $info[
'imagerepository'] =
'';
119 [
'query',
'pages', (
int)$pageId ],
120 'imagerepository',
''
130 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
131 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
134 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
143 if ( !isset( $info[
'imagerepository'] ) ) {
144 $info[
'imagerepository'] = $img->getRepoName();
146 if ( isset( $prop[
'badfile'] ) ) {
147 $info[
'badfile'] = (bool)MediaWikiServices::getInstance()->getBadFileLookup()
148 ->isBadFile(
$title, $badFileContextTitle );
151 $fit = $result->addValue( [
'query',
'pages' ], (
int)$pageId, $info );
153 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
160 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
170 $finalThumbParams = $this->
mergeThumbParams( $img, $scale, $params[
'urlparam'] );
176 ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
177 ( is_null( $params[
'end'] ) || $img->getTimestamp() >= $params[
'end'] )
182 static::getInfo( $img, $prop, $result,
183 $finalThumbParams, $opts
187 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
190 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
201 $count = ( $gotOne ? 1 : 0 );
202 $oldies = $img->getHistory( $params[
'limit'] - $count + 1, $start, $params[
'end'] );
204 foreach ( $oldies as $oldie ) {
205 if ( ++$count > $params[
'limit'] ) {
209 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
211 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
217 static::getInfo( $oldie, $prop, $result,
218 $finalThumbParams, $opts
222 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
224 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
245 if ( $params[
'urlwidth'] != -1 ) {
247 $scale[
'width'] = $params[
'urlwidth'];
248 $scale[
'height'] = $params[
'urlheight'];
249 } elseif ( $params[
'urlheight'] != -1 ) {
253 $scale[
'height'] = $params[
'urlheight'];
254 } elseif ( $params[
'urlparam'] ) {
274 if ( $thumbParams ===
null ) {
278 if ( !isset( $thumbParams[
'width'] ) && isset( $thumbParams[
'height'] ) ) {
283 if ( $image->getWidth() <= 0 ) {
284 $thumbParams[
'width'] = max( $this->
getConfig()->
get(
'ThumbLimits' ) );
286 $thumbParams[
'width'] = $image->getWidth();
290 if ( !$otherParams ) {
296 $h = $image->getHandler();
303 $paramList = $h->parseParamString( $otherParams );
314 if ( isset( $paramList[
'width'] ) && isset( $thumbParams[
'width'] ) ) {
315 if ( (
int)$paramList[
'width'] != (
int)$thumbParams[
'width'] ) {
317 [
'apiwarn-urlparamwidth', $p, $paramList[
'width'], $thumbParams[
'width'] ]
322 foreach ( $paramList as $name => $value ) {
323 if ( !$h->validateParam( $name, $value ) ) {
330 $finalParams = $thumbParams + $paramList;
347 $h = $image->getHandler();
354 if ( !$h->normaliseParams( $image, $finalParams ) ) {
374 public static function getInfo(
$file, $prop, $result, $thumbParams =
null, $opts =
false ) {
377 if ( !$opts || is_string( $opts ) ) {
379 'version' => $opts ?:
'latest',
380 'language' => MediaWikiServices::getInstance()->getContentLanguage(),
381 'multilang' =>
false,
382 'extmetadatafilter' => [],
383 'revdelUser' =>
null,
386 $version = $opts[
'version'];
388 ApiResult::META_TYPE =>
'assoc',
392 $exists =
$file->exists();
396 if ( isset( $prop[
'timestamp'] ) && $exists ) {
401 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser'] ) {
402 $revdelUser = $opts[
'revdelUser'];
403 $canShowField =
function ( $field ) use (
$file, $revdelUser ) {
404 return $file->userCan( $field, $revdelUser );
407 $canShowField =
function ( $field ) use (
$file ) {
408 return !
$file->isDeleted( $field );
412 $user = isset( $prop[
'user'] );
413 $userid = isset( $prop[
'userid'] );
415 if ( ( $user || $userid ) && $exists ) {
416 if (
$file->isDeleted( File::DELETED_USER ) ) {
417 $vals[
'userhidden'] =
true;
420 if ( $canShowField( File::DELETED_USER ) ) {
422 $vals[
'user'] =
$file->getUser();
425 $vals[
'userid'] =
$file->getUser(
'id' );
427 if ( !
$file->getUser(
'id' ) ) {
428 $vals[
'anon'] =
true;
435 if ( ( isset( $prop[
'size'] ) || isset( $prop[
'dimensions'] ) ) && $exists ) {
436 $vals[
'size'] = (int)
$file->getSize();
437 $vals[
'width'] = (int)
$file->getWidth();
438 $vals[
'height'] = (int)
$file->getHeight();
440 $pageCount =
$file->pageCount();
441 if ( $pageCount !==
false ) {
442 $vals[
'pagecount'] = $pageCount;
446 $length =
$file->getLength();
449 $vals[
'duration'] = (float)$length;
453 $pcomment = isset( $prop[
'parsedcomment'] );
454 $comment = isset( $prop[
'comment'] );
456 if ( ( $pcomment || $comment ) && $exists ) {
457 if (
$file->isDeleted( File::DELETED_COMMENT ) ) {
458 $vals[
'commenthidden'] =
true;
461 if ( $canShowField( File::DELETED_COMMENT ) ) {
464 $file->getDescription( File::RAW ),
$file->getTitle() );
467 $vals[
'comment'] =
$file->getDescription( File::RAW );
472 $canonicaltitle = isset( $prop[
'canonicaltitle'] );
473 $url = isset( $prop[
'url'] );
474 $sha1 = isset( $prop[
'sha1'] );
475 $meta = isset( $prop[
'metadata'] );
476 $extmetadata = isset( $prop[
'extmetadata'] );
477 $commonmeta = isset( $prop[
'commonmetadata'] );
478 $mime = isset( $prop[
'mime'] );
479 $mediatype = isset( $prop[
'mediatype'] );
480 $archive = isset( $prop[
'archivename'] );
481 $bitdepth = isset( $prop[
'bitdepth'] );
482 $uploadwarning = isset( $prop[
'uploadwarning'] );
484 if ( $uploadwarning ) {
488 if (
$file->isDeleted( File::DELETED_FILE ) ) {
489 $vals[
'filehidden'] =
true;
493 if ( $anyHidden &&
$file->isDeleted( File::DELETED_RESTRICTED ) ) {
494 $vals[
'suppressed'] =
true;
497 if ( !$canShowField( File::DELETED_FILE ) ) {
502 if ( $canonicaltitle ) {
503 $vals[
'canonicaltitle'] =
$file->getTitle()->getPrefixedText();
508 if ( !is_null( $thumbParams ) ) {
509 $mto =
$file->transform( $thumbParams );
510 self::$transformCount++;
511 if ( $mto && !$mto->isError() ) {
516 if ( $mto->getUrl() !==
$file->getUrl() ) {
517 $vals[
'thumbwidth'] = (int)$mto->getWidth();
518 $vals[
'thumbheight'] = (int)$mto->getHeight();
520 $vals[
'thumbwidth'] = (int)
$file->getWidth();
521 $vals[
'thumbheight'] = (int)
$file->getHeight();
524 if ( isset( $prop[
'thumbmime'] ) &&
$file->getHandler() ) {
525 list( , $mime ) =
$file->getHandler()->getThumbType(
526 $mto->getExtension(),
$file->getMimeType(), $thumbParams );
527 $vals[
'thumbmime'] = $mime;
529 } elseif ( $mto && $mto->isError() ) {
531 '@phan-var MediaTransformError $mto';
532 $vals[
'thumberror'] = $mto->toText();
539 $shortDescriptionUrl =
$file->getDescriptionShortUrl();
540 if ( $shortDescriptionUrl !==
null ) {
546 $vals[
'filemissing'] =
true;
549 if ( $sha1 && $exists ) {
550 $vals[
'sha1'] = Wikimedia\base_convert(
$file->getSha1(), 36, 16, 40 );
553 if ( $meta && $exists ) {
554 Wikimedia\suppressWarnings();
556 Wikimedia\restoreWarnings();
557 if ( $metadata && $version !==
'latest' ) {
558 $metadata =
$file->convertMetadataVersion( $metadata, $version );
560 $vals[
'metadata'] = $metadata ? static::processMetaData( $metadata, $result ) :
null;
562 if ( $commonmeta && $exists ) {
563 $metaArray =
$file->getCommonMetaArray();
564 $vals[
'commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
567 if ( $extmetadata && $exists ) {
574 $format->getContext()->setLanguage( $opts[
'language'] );
575 $extmetaArray = $format->fetchExtendedMetadata(
$file );
576 if ( $opts[
'extmetadatafilter'] ) {
577 $extmetaArray = array_intersect_key(
578 $extmetaArray, array_flip( $opts[
'extmetadatafilter'] )
581 $vals[
'extmetadata'] = $extmetaArray;
584 if ( $mime && $exists ) {
585 $vals[
'mime'] =
$file->getMimeType();
588 if ( $mediatype && $exists ) {
589 $vals[
'mediatype'] =
$file->getMediaType();
592 if ( $archive &&
$file->isOld() ) {
594 '@phan-var OldLocalFile $file';
595 $vals[
'archivename'] =
$file->getArchiveName();
598 if ( $bitdepth && $exists ) {
599 $vals[
'bitdepth'] =
$file->getBitDepth();
624 if ( is_array( $metadata ) ) {
625 foreach ( $metadata as $key => $value ) {
628 ApiResult::META_BC_BOOLS => [
'value' ],
630 if ( is_array( $value ) ) {
631 $r[
'value'] = static::processMetaData( $value, $result );
633 $r[
'value'] = $value;
638 ApiResult::setIndexedTagName( $retval,
'metadata' );
657 if ( $start ===
null ) {
658 $start = $img->getTimestamp();
661 return $img->getOriginalTitle()->getDBkey() .
'|' . $start;
689 'apihelp-query+imageinfo-param-urlwidth',
697 'metadataversion' => [
701 'extmetadatalanguage' => [
704 MediaWikiServices::getInstance()->getContentLanguage()->getCode(),
706 'extmetadatamultilang' => [
710 'extmetadatafilter' => [
718 'badfilecontexttitle' => [
724 'localonly' =>
false,
735 return array_keys( static::getPropertyMessages(
$filter ) );
745 return array_diff_key(
747 'timestamp' =>
'apihelp-query+imageinfo-paramvalue-prop-timestamp',
748 'user' =>
'apihelp-query+imageinfo-paramvalue-prop-user',
749 'userid' =>
'apihelp-query+imageinfo-paramvalue-prop-userid',
750 'comment' =>
'apihelp-query+imageinfo-paramvalue-prop-comment',
751 'parsedcomment' =>
'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
752 'canonicaltitle' =>
'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
753 'url' =>
'apihelp-query+imageinfo-paramvalue-prop-url',
754 'size' =>
'apihelp-query+imageinfo-paramvalue-prop-size',
755 'dimensions' =>
'apihelp-query+imageinfo-paramvalue-prop-dimensions',
756 'sha1' =>
'apihelp-query+imageinfo-paramvalue-prop-sha1',
757 'mime' =>
'apihelp-query+imageinfo-paramvalue-prop-mime',
758 'thumbmime' =>
'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
759 'mediatype' =>
'apihelp-query+imageinfo-paramvalue-prop-mediatype',
760 'metadata' =>
'apihelp-query+imageinfo-paramvalue-prop-metadata',
761 'commonmetadata' =>
'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
762 'extmetadata' =>
'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
763 'archivename' =>
'apihelp-query+imageinfo-paramvalue-prop-archivename',
764 'bitdepth' =>
'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
765 'uploadwarning' =>
'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
766 'badfile' =>
'apihelp-query+imageinfo-paramvalue-prop-badfile',
774 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
775 =>
'apihelp-query+imageinfo-example-simple',
776 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
777 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
778 =>
'apihelp-query+imageinfo-example-dated',
783 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
unserialize( $serialized)
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const LIMIT_BIG2
Fast query, apihighlimits limit.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
getPageSet()
Get the PageSet object to work on.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
A query action to get image information and upload history.
checkParameterNormalise( $image, $finalParams)
Verify that the final image parameters can be normalised.
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
__construct(ApiQuery $query, $moduleName, $prefix='ii')
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getScale( $params)
From parameters, construct a 'scale' array.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getContinueStr( $img, $start=null)
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
static getTransformCount()
Get the count of image transformations performed.
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
static processMetaData( $metadata, $result)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Implements some public methods and some protected utility functions which are required by multiple ch...
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
static getExistsWarning( $exists)
Functions for formatting warnings.
static getExistsWarning( $file)
Helper function that does various existence checks for a file.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.