37 private static $transformCount = 0;
43 private $contentLanguage;
46 private $badFileLookup;
59 $prefixOrRepoGroup =
null,
60 $repoGroupOrContentLanguage =
null,
61 $contentLanguageOrBadFileLookup =
null,
62 $badFileLookupOrUnused =
null
66 if ( !is_string( $prefixOrRepoGroup ) ) {
68 $repoGroup = $prefixOrRepoGroup;
69 $contentLanguage = $repoGroupOrContentLanguage;
70 $badFileLookup = $contentLanguageOrBadFileLookup;
73 $prefix = $prefixOrRepoGroup;
74 $repoGroup = $repoGroupOrContentLanguage;
75 $contentLanguage = $contentLanguageOrBadFileLookup;
76 $badFileLookup = $badFileLookupOrUnused;
78 parent::__construct( $query, $moduleName, $prefix );
80 $services = MediaWikiServices::getInstance();
81 $this->repoGroup = $repoGroup ?? $services->getRepoGroup();
82 $this->contentLanguage = $contentLanguage ?? $services->getContentLanguage();
83 $this->badFileLookup = $badFileLookup ?? $services->getBadFileLookup();
89 $prop = array_fill_keys( $params[
'prop'],
true );
94 'version' => $params[
'metadataversion'],
95 'language' => $params[
'extmetadatalanguage'],
96 'multilang' => $params[
'extmetadatamultilang'],
97 'extmetadatafilter' => $params[
'extmetadatafilter'],
101 if ( isset( $params[
'badfilecontexttitle'] ) ) {
103 if ( !$badFileContextTitle || $badFileContextTitle->isExternal() ) {
105 $this->
dieWithError( [
'apierror-bad-badfilecontexttitle', $p ],
'invalid-title' );
108 $badFileContextTitle =
null;
111 $pageIds = $this->
getPageSet()->getGoodAndMissingTitlesByNamespace();
112 if ( !empty( $pageIds[
NS_FILE] ) ) {
113 $titles = array_keys( $pageIds[
NS_FILE] );
117 if ( $params[
'continue'] !==
null ) {
119 $fromTitle = $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 );
365 isset( $paramList[
'width'] ) && isset( $thumbParams[
'width'] ) &&
366 (
int)$paramList[
'width'] != (
int)$thumbParams[
'width']
369 [
'apiwarn-urlparamwidth', $p, $paramList[
'width'], $thumbParams[
'width'] ]
373 foreach ( $paramList as $name => $value ) {
374 if ( !$h->validateParam( $name, $value ) ) {
381 $finalParams = $thumbParams + $paramList;
398 $h = $image->getHandler();
405 if ( !$h->normaliseParams( $image, $finalParams ) ) {
425 public static function getInfo(
$file, $prop, $result, $thumbParams =
null, $opts =
false ) {
428 if ( !$opts || is_string( $opts ) ) {
430 'version' => $opts ?:
'latest',
431 'language' => MediaWikiServices::getInstance()->getContentLanguage(),
432 'multilang' =>
false,
433 'extmetadatafilter' => [],
434 'revdelUser' =>
null,
437 $version = $opts[
'version'];
443 $exists =
$file->exists();
447 if ( isset( $prop[
'timestamp'] ) && $exists ) {
452 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser'] ) {
453 $revdelUser = $opts[
'revdelUser'];
454 $canShowField =
static function ( $field ) use (
$file, $revdelUser ) {
455 return $file->userCan( $field, $revdelUser );
458 $canShowField =
static function ( $field ) use (
$file ) {
459 return !
$file->isDeleted( $field );
463 $user = isset( $prop[
'user'] );
464 $userid = isset( $prop[
'userid'] );
466 if ( ( $user || $userid ) && $exists ) {
468 $vals[
'userhidden'] =
true;
475 $vals[
'user'] = $uploader ? $uploader->getName() :
'';
478 $vals[
'userid'] = $uploader ? $uploader->getId() : 0;
480 if ( $uploader && !$uploader->isRegistered() ) {
481 $vals[
'anon'] =
true;
488 if ( ( isset( $prop[
'size'] ) || isset( $prop[
'dimensions'] ) ) && $exists ) {
489 $vals[
'size'] = (int)
$file->getSize();
490 $vals[
'width'] = (int)
$file->getWidth();
491 $vals[
'height'] = (int)
$file->getHeight();
493 $pageCount =
$file->pageCount();
494 if ( $pageCount !==
false ) {
495 $vals[
'pagecount'] = $pageCount;
499 $length =
$file->getLength();
502 $vals[
'duration'] = (float)$length;
506 $pcomment = isset( $prop[
'parsedcomment'] );
507 $comment = isset( $prop[
'comment'] );
509 if ( ( $pcomment || $comment ) && $exists ) {
511 $vals[
'commenthidden'] =
true;
516 $vals[
'parsedcomment'] = MediaWikiServices::getInstance()->getCommentFormatter()->format(
525 $canonicaltitle = isset( $prop[
'canonicaltitle'] );
526 $url = isset( $prop[
'url'] );
527 $sha1 = isset( $prop[
'sha1'] );
528 $meta = isset( $prop[
'metadata'] );
529 $extmetadata = isset( $prop[
'extmetadata'] );
530 $commonmeta = isset( $prop[
'commonmetadata'] );
531 $mime = isset( $prop[
'mime'] );
532 $mediatype = isset( $prop[
'mediatype'] );
533 $archive = isset( $prop[
'archivename'] );
534 $bitdepth = isset( $prop[
'bitdepth'] );
535 $uploadwarning = isset( $prop[
'uploadwarning'] );
537 if ( $uploadwarning ) {
542 $vals[
'filehidden'] =
true;
547 $vals[
'suppressed'] =
true;
551 if ( isset( $opts[
'revdelUser'] ) && $opts[
'revdelUser']
559 if ( $canonicaltitle ) {
560 $vals[
'canonicaltitle'] =
$file->getTitle()->getPrefixedText();
565 if ( $thumbParams !==
null ) {
566 $mto =
$file->transform( $thumbParams );
567 self::$transformCount++;
568 if ( $mto && !$mto->isError() ) {
573 if ( $mto->getUrl() !==
$file->getUrl() ) {
574 $vals[
'thumbwidth'] = (int)$mto->getWidth();
575 $vals[
'thumbheight'] = (int)$mto->getHeight();
577 $vals[
'thumbwidth'] = (int)
$file->getWidth();
578 $vals[
'thumbheight'] = (int)
$file->getHeight();
581 if ( isset( $prop[
'thumbmime'] ) &&
$file->getHandler() ) {
582 [ ,
$mime ] =
$file->getHandler()->getThumbType(
583 $mto->getExtension(),
$file->getMimeType(), $thumbParams );
584 $vals[
'thumbmime'] =
$mime;
587 Linker::processResponsiveImages(
$file, $mto, [
588 'width' => $vals[
'thumbwidth'],
589 'height' => $vals[
'thumbheight']
591 foreach ( $mto->responsiveUrls as $density => $url ) {
594 } elseif ( $mto && $mto->isError() ) {
596 '@phan-var MediaTransformError $mto';
597 $vals[
'thumberror'] = $mto->toText();
604 $shortDescriptionUrl =
$file->getDescriptionShortUrl();
605 if ( $shortDescriptionUrl !==
null ) {
611 $vals[
'filemissing'] =
true;
614 if ( $sha1 && $exists ) {
615 $vals[
'sha1'] = Wikimedia\base_convert(
$file->getSha1(), 36, 16, 40 );
618 if ( $meta && $exists ) {
619 $metadata =
$file->getMetadataArray();
620 if ( $metadata && $version !==
'latest' ) {
621 $metadata =
$file->convertMetadataVersion( $metadata, $version );
623 $vals[
'metadata'] = $metadata ? static::processMetaData( $metadata, $result ) :
null;
625 if ( $commonmeta && $exists ) {
626 $metaArray =
$file->getCommonMetaArray();
627 $vals[
'commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
630 if ( $extmetadata && $exists ) {
637 $format->getContext()->setLanguage( $opts[
'language'] );
638 $extmetaArray = $format->fetchExtendedMetadata(
$file );
639 if ( $opts[
'extmetadatafilter'] ) {
640 $extmetaArray = array_intersect_key(
641 $extmetaArray, array_fill_keys( $opts[
'extmetadatafilter'],
true )
644 $vals[
'extmetadata'] = $extmetaArray;
647 if (
$mime && $exists ) {
648 $vals[
'mime'] =
$file->getMimeType();
651 if ( $mediatype && $exists ) {
652 $vals[
'mediatype'] =
$file->getMediaType();
655 if ( $archive &&
$file->isOld() ) {
657 '@phan-var OldLocalFile $file';
658 $vals[
'archivename'] =
$file->getArchiveName();
661 if ( $bitdepth && $exists ) {
662 $vals[
'bitdepth'] =
$file->getBitDepth();
676 return self::$transformCount;
686 if ( is_array( $metadata ) ) {
687 foreach ( $metadata as $key => $value ) {
692 if ( is_array( $value ) ) {
693 $r[
'value'] = static::processMetaData( $value, $result );
695 $r[
'value'] = $value;
719 return $img->getOriginalTitle()->getDBkey() .
'|' . ( $start ?? $img->getTimestamp() );
725 ParamValidator::PARAM_ISMULTI =>
true,
726 ParamValidator::PARAM_DEFAULT =>
'timestamp|user',
727 ParamValidator::PARAM_TYPE => static::getPropertyNames(),
731 ParamValidator::PARAM_TYPE =>
'limit',
732 ParamValidator::PARAM_DEFAULT => 1,
733 IntegerDef::PARAM_MIN => 1,
738 ParamValidator::PARAM_TYPE =>
'timestamp'
741 ParamValidator::PARAM_TYPE =>
'timestamp'
744 ParamValidator::PARAM_TYPE =>
'integer',
745 ParamValidator::PARAM_DEFAULT => -1,
747 'apihelp-query+imageinfo-param-urlwidth',
752 ParamValidator::PARAM_TYPE =>
'integer',
753 ParamValidator::PARAM_DEFAULT => -1
755 'metadataversion' => [
756 ParamValidator::PARAM_TYPE =>
'string',
757 ParamValidator::PARAM_DEFAULT =>
'1',
759 'extmetadatalanguage' => [
760 ParamValidator::PARAM_TYPE =>
'string',
761 ParamValidator::PARAM_DEFAULT =>
762 $this->contentLanguage->getCode(),
764 'extmetadatamultilang' => [
765 ParamValidator::PARAM_TYPE =>
'boolean',
766 ParamValidator::PARAM_DEFAULT =>
false,
768 'extmetadatafilter' => [
769 ParamValidator::PARAM_TYPE =>
'string',
770 ParamValidator::PARAM_ISMULTI =>
true,
773 ParamValidator::PARAM_DEFAULT =>
'',
774 ParamValidator::PARAM_TYPE =>
'string',
776 'badfilecontexttitle' => [
777 ParamValidator::PARAM_TYPE =>
'string',
783 ParamValidator::PARAM_TYPE =>
'boolean',
784 ParamValidator::PARAM_DEFAULT =>
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).
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
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.
__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.
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.
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.