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'] ) ) {
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'] ) {
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'];
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 ) {
417 $vals[
'userhidden'] =
true;
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 ) {
458 $vals[
'commenthidden'] =
true;
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 ) {
489 $vals[
'filehidden'] =
true;
494 $vals[
'suppressed'] =
true;
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 ) {
630 if ( is_array( $value ) ) {
631 $r[
'value'] = static::processMetaData( $value, $result );
633 $r[
'value'] = $value;
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';