38 if ( $prefix ===
null ) {
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 ( $params[
'continue'] !==
null ) {
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 $services = MediaWikiServices::getInstance();
99 $repoGroup = $services->getRepoGroup();
100 if ( $params[
'localonly'] ) {
101 $images = $repoGroup->getLocalRepo()->findFiles( $findTitles );
103 $images = $repoGroup->findFiles( $findTitles );
107 foreach ( $titles as
$title ) {
110 $start =
$title === $fromTitle ? $fromTimestamp : $params[
'start'];
112 if ( !isset( $images[
$title] ) ) {
113 if ( isset( $prop[
'uploadwarning'] ) || isset( $prop[
'badfile'] ) ) {
115 $images[
$title] = $repoGroup->getLocalRepo()->newFile(
$title );
117 $info[
'imagerepository'] =
'';
120 [
'query',
'pages', (
int)$pageId ],
121 'imagerepository',
''
131 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
132 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
135 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
144 if ( !isset( $info[
'imagerepository'] ) ) {
145 $info[
'imagerepository'] = $img->getRepoName();
147 if ( isset( $prop[
'badfile'] ) ) {
148 $info[
'badfile'] = (bool)$services->getBadFileLookup()
149 ->isBadFile(
$title, $badFileContextTitle );
152 $fit = $result->addValue( [
'query',
'pages' ], (
int)$pageId, $info );
154 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
161 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
171 $finalThumbParams = $this->
mergeThumbParams( $img, $scale, $params[
'urlparam'] );
177 ( $start ===
null || $img->getTimestamp() <= $start ) &&
178 ( $params[
'end'] ===
null || $img->getTimestamp() >= $params[
'end'] )
183 static::getInfo( $img, $prop, $result,
184 $finalThumbParams, $opts
188 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
191 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
202 $count = ( $gotOne ? 1 : 0 );
203 $oldies = $img->getHistory( $params[
'limit'] - $count + 1, $start, $params[
'end'] );
205 foreach ( $oldies as $oldie ) {
206 if ( ++$count > $params[
'limit'] ) {
210 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
212 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
218 static::getInfo( $oldie, $prop, $result,
219 $finalThumbParams, $opts
223 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
225 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
246 if ( $params[
'urlwidth'] != -1 ) {
248 $scale[
'width'] = $params[
'urlwidth'];
249 $scale[
'height'] = $params[
'urlheight'];
250 } elseif ( $params[
'urlheight'] != -1 ) {
254 $scale[
'height'] = $params[
'urlheight'];
255 } elseif ( $params[
'urlparam'] ) {
275 if ( $thumbParams ===
null ) {
279 if ( !isset( $thumbParams[
'width'] ) && isset( $thumbParams[
'height'] ) ) {
284 if ( $image->getWidth() <= 0 ) {
285 $thumbParams[
'width'] = max( $this->
getConfig()->
get(
'ThumbLimits' ) );
287 $thumbParams[
'width'] = $image->getWidth();
291 if ( !$otherParams ) {
297 $h = $image->getHandler();
304 $paramList = $h->parseParamString( $otherParams );
315 if ( isset( $paramList[
'width'] ) && isset( $thumbParams[
'width'] ) ) {
316 if ( (
int)$paramList[
'width'] != (
int)$thumbParams[
'width'] ) {
318 [
'apiwarn-urlparamwidth', $p, $paramList[
'width'], $thumbParams[
'width'] ]
323 foreach ( $paramList as $name => $value ) {
324 if ( !$h->validateParam( $name, $value ) ) {
331 $finalParams = $thumbParams + $paramList;
348 $h = $image->getHandler();
355 if ( !$h->normaliseParams( $image, $finalParams ) ) {
375 public static function getInfo(
$file, $prop, $result, $thumbParams =
null, $opts =
false ) {
378 if ( !$opts || is_string( $opts ) ) {
380 'version' => $opts ?:
'latest',
381 'language' => MediaWikiServices::getInstance()->getContentLanguage(),
382 'multilang' =>
false,
383 'extmetadatafilter' => [],
384 'revdelUser' =>
null,
387 $version = $opts[
'version'];
389 ApiResult::META_TYPE =>
'assoc',
393 $exists =
$file->exists();
397 if ( isset( $prop[
'timestamp'] ) && $exists ) {
402 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser'] ) {
403 $revdelUser = $opts[
'revdelUser'];
404 $canShowField =
function ( $field ) use (
$file, $revdelUser ) {
405 return $file->userCan( $field, $revdelUser );
408 $canShowField =
function ( $field ) use (
$file ) {
409 return !
$file->isDeleted( $field );
413 $user = isset( $prop[
'user'] );
414 $userid = isset( $prop[
'userid'] );
416 if ( ( $user || $userid ) && $exists ) {
417 if (
$file->isDeleted( File::DELETED_USER ) ) {
418 $vals[
'userhidden'] =
true;
421 if ( $canShowField( File::DELETED_USER ) ) {
423 $vals[
'user'] =
$file->getUser();
426 $vals[
'userid'] =
$file->getUser(
'id' );
428 if ( !
$file->getUser(
'id' ) ) {
429 $vals[
'anon'] =
true;
436 if ( ( isset( $prop[
'size'] ) || isset( $prop[
'dimensions'] ) ) && $exists ) {
437 $vals[
'size'] = (int)
$file->getSize();
438 $vals[
'width'] = (int)
$file->getWidth();
439 $vals[
'height'] = (int)
$file->getHeight();
441 $pageCount =
$file->pageCount();
442 if ( $pageCount !==
false ) {
443 $vals[
'pagecount'] = $pageCount;
447 $length =
$file->getLength();
450 $vals[
'duration'] = (float)$length;
454 $pcomment = isset( $prop[
'parsedcomment'] );
455 $comment = isset( $prop[
'comment'] );
457 if ( ( $pcomment || $comment ) && $exists ) {
458 if (
$file->isDeleted( File::DELETED_COMMENT ) ) {
459 $vals[
'commenthidden'] =
true;
462 if ( $canShowField( File::DELETED_COMMENT ) ) {
465 $file->getDescription( File::RAW ),
$file->getTitle() );
468 $vals[
'comment'] =
$file->getDescription( File::RAW );
473 $canonicaltitle = isset( $prop[
'canonicaltitle'] );
474 $url = isset( $prop[
'url'] );
475 $sha1 = isset( $prop[
'sha1'] );
476 $meta = isset( $prop[
'metadata'] );
477 $extmetadata = isset( $prop[
'extmetadata'] );
478 $commonmeta = isset( $prop[
'commonmetadata'] );
479 $mime = isset( $prop[
'mime'] );
480 $mediatype = isset( $prop[
'mediatype'] );
481 $archive = isset( $prop[
'archivename'] );
482 $bitdepth = isset( $prop[
'bitdepth'] );
483 $uploadwarning = isset( $prop[
'uploadwarning'] );
485 if ( $uploadwarning ) {
486 $vals[
'html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning(
$file ) );
489 if (
$file->isDeleted( File::DELETED_FILE ) ) {
490 $vals[
'filehidden'] =
true;
494 if ( $anyHidden &&
$file->isDeleted( File::DELETED_RESTRICTED ) ) {
495 $vals[
'suppressed'] =
true;
498 if ( !$canShowField( File::DELETED_FILE ) ) {
503 if ( $canonicaltitle ) {
504 $vals[
'canonicaltitle'] =
$file->getTitle()->getPrefixedText();
509 if ( $thumbParams !==
null ) {
510 $mto =
$file->transform( $thumbParams );
511 self::$transformCount++;
512 if ( $mto && !$mto->isError() ) {
517 if ( $mto->getUrl() !==
$file->getUrl() ) {
518 $vals[
'thumbwidth'] = (int)$mto->getWidth();
519 $vals[
'thumbheight'] = (int)$mto->getHeight();
521 $vals[
'thumbwidth'] = (int)
$file->getWidth();
522 $vals[
'thumbheight'] = (int)
$file->getHeight();
525 if ( isset( $prop[
'thumbmime'] ) &&
$file->getHandler() ) {
526 list( ,
$mime ) =
$file->getHandler()->getThumbType(
527 $mto->getExtension(),
$file->getMimeType(), $thumbParams );
528 $vals[
'thumbmime'] =
$mime;
530 } elseif ( $mto && $mto->isError() ) {
532 '@phan-var MediaTransformError $mto';
533 $vals[
'thumberror'] = $mto->toText();
540 $shortDescriptionUrl =
$file->getDescriptionShortUrl();
541 if ( $shortDescriptionUrl !==
null ) {
547 $vals[
'filemissing'] =
true;
550 if ( $sha1 && $exists ) {
551 $vals[
'sha1'] = Wikimedia\base_convert(
$file->getSha1(), 36, 16, 40 );
554 if ( $meta && $exists ) {
555 Wikimedia\suppressWarnings();
557 Wikimedia\restoreWarnings();
558 if ( $metadata && $version !==
'latest' ) {
559 $metadata =
$file->convertMetadataVersion( $metadata, $version );
561 $vals[
'metadata'] = $metadata ? static::processMetaData( $metadata, $result ) :
null;
563 if ( $commonmeta && $exists ) {
564 $metaArray =
$file->getCommonMetaArray();
565 $vals[
'commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
568 if ( $extmetadata && $exists ) {
575 $format->getContext()->setLanguage( $opts[
'language'] );
576 $extmetaArray = $format->fetchExtendedMetadata(
$file );
577 if ( $opts[
'extmetadatafilter'] ) {
578 $extmetaArray = array_intersect_key(
579 $extmetaArray, array_flip( $opts[
'extmetadatafilter'] )
582 $vals[
'extmetadata'] = $extmetaArray;
585 if (
$mime && $exists ) {
586 $vals[
'mime'] =
$file->getMimeType();
589 if ( $mediatype && $exists ) {
590 $vals[
'mediatype'] =
$file->getMediaType();
593 if ( $archive &&
$file->isOld() ) {
595 '@phan-var OldLocalFile $file';
596 $vals[
'archivename'] =
$file->getArchiveName();
599 if ( $bitdepth && $exists ) {
600 $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',
768 array_flip( $filter )
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,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
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 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.
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 Stable to override.
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')
Stable to call.
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.
getUser()
Stable to override.
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...
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.