58 $prefixOrRepoGroup =
null,
59 $repoGroupOrContentLanguage =
null,
60 $contentLanguageOrBadFileLookup =
null,
61 $badFileLookupOrUnused =
null
65 if ( !is_string( $prefixOrRepoGroup ) ) {
72 $prefix = $prefixOrRepoGroup;
77 parent::__construct( $query, $moduleName, $prefix );
79 $services = MediaWikiServices::getInstance();
80 $this->repoGroup =
$repoGroup ?? $services->getRepoGroup();
81 $this->contentLanguage =
$contentLanguage ?? $services->getContentLanguage();
82 $this->badFileLookup =
$badFileLookup ?? $services->getBadFileLookup();
88 $prop = array_fill_keys( $params[
'prop'],
true );
93 'version' => $params[
'metadataversion'],
94 'language' => $params[
'extmetadatalanguage'],
95 'multilang' => $params[
'extmetadatamultilang'],
96 'extmetadatafilter' => $params[
'extmetadatafilter'],
100 if ( isset( $params[
'badfilecontexttitle'] ) ) {
102 if ( !$badFileContextTitle ) {
104 $this->
dieWithError( [
'apierror-bad-badfilecontexttitle', $p ],
'invalid-title' );
107 $badFileContextTitle =
null;
110 $pageIds = $this->
getPageSet()->getGoodAndMissingTitlesByNamespace();
111 if ( !empty( $pageIds[
NS_FILE] ) ) {
112 $titles = array_keys( $pageIds[
NS_FILE] );
116 if ( $params[
'continue'] !==
null ) {
117 $cont = explode(
'|', $params[
'continue'] );
119 $fromTitle = strval( $cont[0] );
120 $fromTimestamp = $cont[1];
122 foreach ( $titles as $key =>
$title ) {
123 if (
$title < $fromTitle ) {
124 unset( $titles[$key] );
132 $findTitles = array_map(
static function (
$title ) use ( $performer ) {
135 'private' => $performer,
139 if ( $params[
'localonly'] ) {
140 $images = $this->repoGroup->getLocalRepo()->findFiles( $findTitles );
142 $images = $this->repoGroup->findFiles( $findTitles );
146 foreach ( $titles as
$title ) {
151 $start =
$title === $fromTitle ? $fromTimestamp : $params[
'start'];
153 if ( !isset( $images[
$title] ) ) {
154 if ( isset( $prop[
'uploadwarning'] ) || isset( $prop[
'badfile'] ) ) {
156 $images[
$title] = $this->repoGroup->getLocalRepo()->newFile(
$title );
158 $info[
'imagerepository'] =
'';
161 [
'query',
'pages', (
int)$pageId ],
162 'imagerepository',
''
172 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
173 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
176 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
185 if ( !isset( $info[
'imagerepository'] ) ) {
186 $info[
'imagerepository'] = $img->getRepoName();
188 if ( isset( $prop[
'badfile'] ) ) {
189 $info[
'badfile'] = (bool)$this->badFileLookup->isBadFile(
$title, $badFileContextTitle );
192 $fit = $result->addValue( [
'query',
'pages' ], (
int)$pageId, $info );
194 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
201 $start ??
wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
211 $finalThumbParams = $this->
mergeThumbParams( $img, $scale, $params[
'urlparam'] );
217 if ( $badFileContextTitle && $finalThumbParams ) {
218 $finalThumbParams[
'targetlang'] = $badFileContextTitle->getPageLanguage()->getCode();
225 ( $start ===
null || $img->getTimestamp() <= $start ) &&
226 ( $params[
'end'] ===
null || $img->getTimestamp() >= $params[
'end'] )
231 static::getInfo( $img, $prop, $result,
232 $finalThumbParams, $opts
236 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
239 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
250 $count = ( $gotOne ? 1 : 0 );
251 $oldies = $img->getHistory( $params[
'limit'] - $count + 1, $start, $params[
'end'] );
253 foreach ( $oldies as $oldie ) {
254 if ( ++$count > $params[
'limit'] ) {
258 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
260 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
266 static::getInfo( $oldie, $prop, $result,
267 $finalThumbParams, $opts
271 if ( count( $pageIds[
NS_FILE] ) == 1 ) {
273 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
294 if ( $params[
'urlwidth'] != -1 ) {
296 $scale[
'width'] = $params[
'urlwidth'];
297 $scale[
'height'] = $params[
'urlheight'];
298 } elseif ( $params[
'urlheight'] != -1 ) {
302 $scale[
'height'] = $params[
'urlheight'];
303 } elseif ( $params[
'urlparam'] ) {
323 if ( $thumbParams ===
null ) {
327 if ( !isset( $thumbParams[
'width'] ) && isset( $thumbParams[
'height'] ) ) {
332 if ( $image->getWidth() <= 0 ) {
333 $thumbParams[
'width'] =
334 max( $this->
getConfig()->
get( MainConfigNames::ThumbLimits ) );
336 $thumbParams[
'width'] = $image->getWidth();
340 if ( !$otherParams ) {
346 $h = $image->getHandler();
353 $paramList = $h->parseParamString( $otherParams );
364 if ( isset( $paramList[
'width'] ) && isset( $thumbParams[
'width'] ) ) {
365 if ( (
int)$paramList[
'width'] != (
int)$thumbParams[
'width'] ) {
367 [
'apiwarn-urlparamwidth', $p, $paramList[
'width'], $thumbParams[
'width'] ]
372 foreach ( $paramList as $name => $value ) {
373 if ( !$h->validateParam( $name, $value ) ) {
380 $finalParams = $thumbParams + $paramList;
397 $h = $image->getHandler();
404 if ( !$h->normaliseParams( $image, $finalParams ) ) {
424 public static function getInfo(
$file, $prop, $result, $thumbParams =
null, $opts =
false ) {
427 if ( !$opts || is_string( $opts ) ) {
429 'version' => $opts ?:
'latest',
430 'language' => MediaWikiServices::getInstance()->getContentLanguage(),
431 'multilang' =>
false,
432 'extmetadatafilter' => [],
433 'revdelUser' =>
null,
436 $version = $opts[
'version'];
442 $exists =
$file->exists();
446 if ( isset( $prop[
'timestamp'] ) && $exists ) {
451 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser'] ) {
452 $revdelUser = $opts[
'revdelUser'];
453 $canShowField =
static function ( $field ) use (
$file, $revdelUser ) {
454 return $file->userCan( $field, $revdelUser );
457 $canShowField =
static function ( $field ) use (
$file ) {
458 return !
$file->isDeleted( $field );
462 $user = isset( $prop[
'user'] );
463 $userid = isset( $prop[
'userid'] );
465 if ( ( $user || $userid ) && $exists ) {
467 $vals[
'userhidden'] =
true;
474 $vals[
'user'] = $uploader ? $uploader->getName() :
'';
477 $vals[
'userid'] = $uploader ? $uploader->getId() : 0;
479 if ( $uploader && !$uploader->isRegistered() ) {
480 $vals[
'anon'] =
true;
487 if ( ( isset( $prop[
'size'] ) || isset( $prop[
'dimensions'] ) ) && $exists ) {
488 $vals[
'size'] = (int)
$file->getSize();
489 $vals[
'width'] = (int)
$file->getWidth();
490 $vals[
'height'] = (int)
$file->getHeight();
492 $pageCount =
$file->pageCount();
493 if ( $pageCount !==
false ) {
494 $vals[
'pagecount'] = $pageCount;
498 $length =
$file->getLength();
501 $vals[
'duration'] = (float)$length;
505 $pcomment = isset( $prop[
'parsedcomment'] );
506 $comment = isset( $prop[
'comment'] );
508 if ( ( $pcomment || $comment ) && $exists ) {
510 $vals[
'commenthidden'] =
true;
524 $canonicaltitle = isset( $prop[
'canonicaltitle'] );
525 $url = isset( $prop[
'url'] );
526 $sha1 = isset( $prop[
'sha1'] );
527 $meta = isset( $prop[
'metadata'] );
528 $extmetadata = isset( $prop[
'extmetadata'] );
529 $commonmeta = isset( $prop[
'commonmetadata'] );
530 $mime = isset( $prop[
'mime'] );
531 $mediatype = isset( $prop[
'mediatype'] );
532 $archive = isset( $prop[
'archivename'] );
533 $bitdepth = isset( $prop[
'bitdepth'] );
534 $uploadwarning = isset( $prop[
'uploadwarning'] );
536 if ( $uploadwarning ) {
541 $vals[
'filehidden'] =
true;
546 $vals[
'suppressed'] =
true;
550 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser']
558 if ( $canonicaltitle ) {
559 $vals[
'canonicaltitle'] =
$file->getTitle()->getPrefixedText();
564 if ( $thumbParams !==
null ) {
565 $mto =
$file->transform( $thumbParams );
566 self::$transformCount++;
567 if ( $mto && !$mto->isError() ) {
572 if ( $mto->getUrl() !==
$file->getUrl() ) {
573 $vals[
'thumbwidth'] = (int)$mto->getWidth();
574 $vals[
'thumbheight'] = (int)$mto->getHeight();
576 $vals[
'thumbwidth'] = (int)
$file->getWidth();
577 $vals[
'thumbheight'] = (int)
$file->getHeight();
580 if ( isset( $prop[
'thumbmime'] ) &&
$file->getHandler() ) {
581 list( ,
$mime ) =
$file->getHandler()->getThumbType(
582 $mto->getExtension(),
$file->getMimeType(), $thumbParams );
583 $vals[
'thumbmime'] =
$mime;
587 'width' => $vals[
'thumbwidth'],
588 'height' => $vals[
'thumbheight']
590 foreach ( $mto->responsiveUrls as $density => $url ) {
593 } elseif ( $mto && $mto->isError() ) {
595 '@phan-var MediaTransformError $mto';
596 $vals[
'thumberror'] = $mto->toText();
603 $shortDescriptionUrl =
$file->getDescriptionShortUrl();
604 if ( $shortDescriptionUrl !==
null ) {
610 $vals[
'filemissing'] =
true;
613 if ( $sha1 && $exists ) {
614 $vals[
'sha1'] = Wikimedia\base_convert(
$file->getSha1(), 36, 16, 40 );
617 if ( $meta && $exists ) {
618 $metadata =
$file->getMetadataArray();
619 if ( $metadata && $version !==
'latest' ) {
620 $metadata =
$file->convertMetadataVersion( $metadata, $version );
622 $vals[
'metadata'] = $metadata ? static::processMetaData( $metadata, $result ) :
null;
624 if ( $commonmeta && $exists ) {
625 $metaArray =
$file->getCommonMetaArray();
626 $vals[
'commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
629 if ( $extmetadata && $exists ) {
636 $format->getContext()->setLanguage( $opts[
'language'] );
637 $extmetaArray = $format->fetchExtendedMetadata(
$file );
638 if ( $opts[
'extmetadatafilter'] ) {
639 $extmetaArray = array_intersect_key(
640 $extmetaArray, array_fill_keys( $opts[
'extmetadatafilter'],
true )
643 $vals[
'extmetadata'] = $extmetaArray;
646 if (
$mime && $exists ) {
647 $vals[
'mime'] =
$file->getMimeType();
650 if ( $mediatype && $exists ) {
651 $vals[
'mediatype'] =
$file->getMediaType();
654 if ( $archive &&
$file->isOld() ) {
656 '@phan-var OldLocalFile $file';
657 $vals[
'archivename'] =
$file->getArchiveName();
660 if ( $bitdepth && $exists ) {
661 $vals[
'bitdepth'] =
$file->getBitDepth();
685 if ( is_array( $metadata ) ) {
686 foreach ( $metadata as $key => $value ) {
691 if ( is_array( $value ) ) {
692 $r[
'value'] = static::processMetaData( $value, $result );
694 $r[
'value'] = $value;
718 if ( $start ===
null ) {
719 $start = $img->getTimestamp();
722 return $img->getOriginalTitle()->getDBkey() .
'|' . $start;
728 ParamValidator::PARAM_ISMULTI =>
true,
729 ParamValidator::PARAM_DEFAULT =>
'timestamp|user',
730 ParamValidator::PARAM_TYPE => static::getPropertyNames(),
734 ParamValidator::PARAM_TYPE =>
'limit',
735 ParamValidator::PARAM_DEFAULT => 1,
736 IntegerDef::PARAM_MIN => 1,
741 ParamValidator::PARAM_TYPE =>
'timestamp'
744 ParamValidator::PARAM_TYPE =>
'timestamp'
747 ParamValidator::PARAM_TYPE =>
'integer',
748 ParamValidator::PARAM_DEFAULT => -1,
750 'apihelp-query+imageinfo-param-urlwidth',
755 ParamValidator::PARAM_TYPE =>
'integer',
756 ParamValidator::PARAM_DEFAULT => -1
758 'metadataversion' => [
759 ParamValidator::PARAM_TYPE =>
'string',
760 ParamValidator::PARAM_DEFAULT =>
'1',
762 'extmetadatalanguage' => [
763 ParamValidator::PARAM_TYPE =>
'string',
764 ParamValidator::PARAM_DEFAULT =>
765 $this->contentLanguage->getCode(),
767 'extmetadatamultilang' => [
768 ParamValidator::PARAM_TYPE =>
'boolean',
769 ParamValidator::PARAM_DEFAULT =>
false,
771 'extmetadatafilter' => [
772 ParamValidator::PARAM_TYPE =>
'string',
773 ParamValidator::PARAM_ISMULTI =>
true,
776 ParamValidator::PARAM_DEFAULT =>
'',
777 ParamValidator::PARAM_TYPE =>
'string',
779 'badfilecontexttitle' => [
780 ParamValidator::PARAM_TYPE =>
'string',
785 'localonly' =>
false,
796 return array_keys( static::getPropertyMessages( $filter ) );
806 return array_diff_key(
808 'timestamp' =>
'apihelp-query+imageinfo-paramvalue-prop-timestamp',
809 'user' =>
'apihelp-query+imageinfo-paramvalue-prop-user',
810 'userid' =>
'apihelp-query+imageinfo-paramvalue-prop-userid',
811 'comment' =>
'apihelp-query+imageinfo-paramvalue-prop-comment',
812 'parsedcomment' =>
'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
813 'canonicaltitle' =>
'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
814 'url' =>
'apihelp-query+imageinfo-paramvalue-prop-url',
815 'size' =>
'apihelp-query+imageinfo-paramvalue-prop-size',
816 'dimensions' =>
'apihelp-query+imageinfo-paramvalue-prop-dimensions',
817 'sha1' =>
'apihelp-query+imageinfo-paramvalue-prop-sha1',
818 'mime' =>
'apihelp-query+imageinfo-paramvalue-prop-mime',
819 'thumbmime' =>
'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
820 'mediatype' =>
'apihelp-query+imageinfo-paramvalue-prop-mediatype',
821 'metadata' =>
'apihelp-query+imageinfo-paramvalue-prop-metadata',
822 'commonmetadata' =>
'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
823 'extmetadata' =>
'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
824 'archivename' =>
'apihelp-query+imageinfo-paramvalue-prop-archivename',
825 'bitdepth' =>
'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
826 'uploadwarning' =>
'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
827 'badfile' =>
'apihelp-query+imageinfo-paramvalue-prop-badfile',
829 array_fill_keys( $filter,
true )
835 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
836 =>
'apihelp-query+imageinfo-example-simple',
837 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
838 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
839 =>
'apihelp-query+imageinfo-example-dated',
844 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
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.
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.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getScale( $params)
From parameters, construct a 'scale' array.
BadFileLookup $badFileLookup
__construct(ApiQuery $query, $moduleName, $prefixOrRepoGroup=null, $repoGroupOrContentLanguage=null, $contentLanguageOrBadFileLookup=null, $badFileLookupOrUnused=null)
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.
Language $contentLanguage
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.
const META_TYPE
Key for the 'type' metadata item.
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
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...
A class containing constants representing the names of configuration variables.
static getExistsWarning( $exists)
Functions for formatting warnings.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
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.