MediaWiki master
ApiQueryImageInfo.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Api;
10
26use Wikimedia\Timestamp\TimestampFormat as TS;
27
34 public const TRANSFORM_LIMIT = 50;
36 private static $transformCount = 0;
37
38 private RepoGroup $repoGroup;
39 private Language $contentLanguage;
40 private BadFileLookup $badFileLookup;
41
50 public function __construct(
51 ApiQuery $query,
52 string $moduleName,
53 $prefixOrRepoGroup = null,
54 $repoGroupOrContentLanguage = null,
55 $contentLanguageOrBadFileLookup = null,
56 $badFileLookupOrUnused = null
57 ) {
58 // We allow a subclass to override the prefix, to create a related API module.
59 // The ObjectFactory is injecting the services without the prefix.
60 if ( !is_string( $prefixOrRepoGroup ) ) {
61 $prefix = 'ii';
62 $repoGroup = $prefixOrRepoGroup;
63 $contentLanguage = $repoGroupOrContentLanguage;
64 $badFileLookup = $contentLanguageOrBadFileLookup;
65 // $badFileLookupOrUnused is null in this case
66 } else {
67 $prefix = $prefixOrRepoGroup;
68 $repoGroup = $repoGroupOrContentLanguage;
69 $contentLanguage = $contentLanguageOrBadFileLookup;
70 $badFileLookup = $badFileLookupOrUnused;
71 }
72 parent::__construct( $query, $moduleName, $prefix );
73 // This class is extended and therefor fallback to global state - T259960
75 $this->repoGroup = $repoGroup ?? $services->getRepoGroup();
76 $this->contentLanguage = $contentLanguage ?? $services->getContentLanguage();
77 $this->badFileLookup = $badFileLookup ?? $services->getBadFileLookup();
78 }
79
80 public function execute() {
81 $params = $this->extractRequestParams();
82
84 $prop = array_fill_keys( $params['prop'], true );
85
86 $scale = $this->getScale( $params );
87
88 $opts = [
89 'version' => $params['metadataversion'],
90 'language' => $params['extmetadatalanguage'],
91 'multilang' => $params['extmetadatamultilang'],
92 'extmetadatafilter' => $params['extmetadatafilter'],
93 'revdelUser' => $this->getAuthority(),
94 ];
95
96 if ( isset( $params['badfilecontexttitle'] ) ) {
97 $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
98 if ( !$badFileContextTitle || $badFileContextTitle->isExternal() ) {
99 $p = $this->getModulePrefix();
100 $this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
101 }
102 } else {
103 $badFileContextTitle = null;
104 }
105
106 $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
107 if ( !empty( $pageIds[NS_FILE] ) ) {
108 $titles = array_keys( $pageIds[NS_FILE] );
109 asort( $titles ); // Ensure the order is always the same
110
111 $fromTitle = null;
112 if ( $params['continue'] !== null ) {
113 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string', 'string' ] );
114 $fromTitle = $cont[0];
115 $fromTimestamp = $cont[1];
116 // Filter out any titles before $fromTitle
117 foreach ( $titles as $key => $title ) {
118 if ( $title < $fromTitle ) {
119 unset( $titles[$key] );
120 } else {
121 break;
122 }
123 }
124 }
125
126 $performer = $this->getAuthority();
127 $findTitles = array_map( static function ( $title ) use ( $performer ) {
128 return [
129 'title' => $title,
130 'private' => $performer,
131 ];
132 }, $titles );
133
134 if ( $params['localonly'] ) {
135 $images = $this->repoGroup->getLocalRepo()->findFiles( $findTitles );
136 } else {
137 $images = $this->repoGroup->findFiles( $findTitles );
138 }
139
140 $result = $this->getResult();
141 foreach ( $titles as $title ) {
142 $info = [];
143 $pageId = $pageIds[NS_FILE][$title];
144 // @phan-suppress-next-next-line PhanPossiblyUndeclaredVariable
145 // $fromTimestamp declared when $fromTitle notnull
146 $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
147
148 if ( !isset( $images[$title] ) ) {
149 if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
150 // uploadwarning and badfile need info about non-existing files
151 $images[$title] = $this->repoGroup->getLocalRepo()->newFile( $title );
152 // Doesn't exist, so set an empty image repository
153 $info['imagerepository'] = '';
154 } else {
155 $result->addValue(
156 [ 'query', 'pages', (int)$pageId ],
157 'imagerepository', ''
158 );
159 // The above can't fail because it doesn't increase the result size
160 continue;
161 }
162 }
163
165 $img = $images[$title];
166
167 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
168 if ( count( $pageIds[NS_FILE] ) == 1 ) {
169 // See the 'the user is screwed' comment below
170 $this->setContinueEnumParameter( 'start',
171 $start ?? wfTimestamp( TS::ISO_8601, $img->getTimestamp() )
172 );
173 } else {
174 $this->setContinueEnumParameter( 'continue',
175 $this->getContinueStr( $img, $start ) );
176 }
177 break;
178 }
179
180 if ( !isset( $info['imagerepository'] ) ) {
181 $info['imagerepository'] = $img->getRepoName();
182 }
183 if ( isset( $prop['badfile'] ) ) {
184 $info['badfile'] = (bool)$this->badFileLookup->isBadFile( $title, $badFileContextTitle );
185 }
186
187 // Use ApiResult::IGNORE_CONFLICT_KEYS, the module is extended and the value can be set twice (T402438)
188 $fit = $result->addValue( [ 'query', 'pages' ], (int)$pageId, $info, ApiResult::IGNORE_CONFLICT_KEYS );
189 if ( !$fit ) {
190 if ( count( $pageIds[NS_FILE] ) == 1 ) {
191 // The user is screwed. imageinfo can't be solely
192 // responsible for exceeding the limit in this case,
193 // so set a query-continue that just returns the same
194 // thing again. When the violating queries have been
195 // out-continued, the result will get through
196 $this->setContinueEnumParameter( 'start',
197 $start ?? wfTimestamp( TS::ISO_8601, $img->getTimestamp() )
198 );
199 } else {
200 $this->setContinueEnumParameter( 'continue',
201 $this->getContinueStr( $img, $start ) );
202 }
203 break;
204 }
205
206 // Check if we can make the requested thumbnail, and get transform parameters.
207 $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
208
209 // Parser::makeImage always sets a targetlang, usually based on the language
210 // the content is in. To support Parsoid's standalone mode, overload the badfilecontexttitle
211 // to also set the targetlang based on the page language. Don't add this unless we're
212 // already scaling since a set $finalThumbParams usually expects a width.
213 if ( $badFileContextTitle && $finalThumbParams ) {
214 $finalThumbParams['targetlang'] = $badFileContextTitle->getPageLanguage()->getCode();
215 }
216
217 // Get information about the current version first
218 // Check that the current version is within the start-end boundaries
219 $gotOne = false;
220 if (
221 ( $start === null || $img->getTimestamp() <= $start ) &&
222 ( $params['end'] === null || $img->getTimestamp() >= $params['end'] )
223 ) {
224 $gotOne = true;
225
226 $fit = $this->addPageSubItem( $pageId,
227 static::getInfo( $img, $prop, $result,
228 $finalThumbParams, $opts
229 )
230 );
231 if ( !$fit ) {
232 if ( count( $pageIds[NS_FILE] ) == 1 ) {
233 // See the 'the user is screwed' comment above
234 $this->setContinueEnumParameter( 'start',
235 wfTimestamp( TS::ISO_8601, $img->getTimestamp() ) );
236 } else {
237 $this->setContinueEnumParameter( 'continue',
238 $this->getContinueStr( $img ) );
239 }
240 break;
241 }
242 }
243
244 // Now get the old revisions
245 // Get one more to facilitate query-continue functionality
246 $count = ( $gotOne ? 1 : 0 );
247 $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
249 foreach ( $oldies as $oldie ) {
250 if ( ++$count > $params['limit'] ) {
251 // We've reached the extra one which shows that there are
252 // additional pages to be had. Stop here...
253 // Only set a query-continue if there was only one title
254 if ( count( $pageIds[NS_FILE] ) == 1 ) {
255 $this->setContinueEnumParameter( 'start',
256 wfTimestamp( TS::ISO_8601, $oldie->getTimestamp() ) );
257 }
258 break;
259 }
260 $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
261 $this->addPageSubItem( $pageId,
262 static::getInfo( $oldie, $prop, $result,
263 $finalThumbParams, $opts
264 )
265 );
266 if ( !$fit ) {
267 if ( count( $pageIds[NS_FILE] ) == 1 ) {
268 $this->setContinueEnumParameter( 'start',
269 wfTimestamp( TS::ISO_8601, $oldie->getTimestamp() ) );
270 } else {
271 $this->setContinueEnumParameter( 'continue',
272 $this->getContinueStr( $oldie ) );
273 }
274 break;
275 }
276 }
277 if ( !$fit ) {
278 break;
279 }
280 }
281 }
282 }
283
289 public function getScale( $params ) {
290 if ( $params['urlwidth'] != -1 ) {
291 return [ 'width' => $params['urlwidth'], 'height' => $params['urlheight'] ];
292 } elseif ( $params['urlheight'] != -1 ) {
293 // Height is specified but width isn't
294 // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
295 return [ 'height' => $params['urlheight'] ];
296 } elseif ( $params['urlparam'] ) {
297 // Audio files might not have a width/height.
298 return [];
299 } else {
300 return null;
301 }
302 }
303
313 protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
314 if ( $thumbParams === null ) {
315 // No scaling requested
316 return null;
317 }
318 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
319 // We want to limit only by height in this situation, so pass the
320 // image's full width as the limiting width. But some file types
321 // don't have a width of their own, or are scalable, so pick
322 // something arbitrary so thumbnailing the default icon works.
323 if ( $image->getWidth() <= 0 || $image->isVectorized() ) {
324 $thumbParams['width'] =
325 max( $this->getConfig()->get( MainConfigNames::ThumbLimits ) );
326 } else {
327 $thumbParams['width'] = $image->getWidth();
328 }
329 }
330
331 if ( !$otherParams ) {
332 $this->checkParameterNormalise( $image, $thumbParams );
333 return $thumbParams;
334 }
335 $p = $this->getModulePrefix();
336
337 $h = $image->getHandler();
338 if ( !$h ) {
339 $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
340
341 return $thumbParams;
342 }
343
344 $paramList = $h->parseParamString( $otherParams );
345 if ( !$paramList ) {
346 // Just set a warning (instead of dieWithError), as in many cases
347 // we could still render the image using width and height parameters,
348 // and this type of thing could happen between different versions of
349 // handlers.
350 $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
351 $this->checkParameterNormalise( $image, $thumbParams );
352 return $thumbParams;
353 }
354
355 if (
356 isset( $paramList['width'] ) && isset( $thumbParams['width'] ) &&
357 (int)$paramList['width'] != (int)$thumbParams['width']
358 ) {
359 $this->addWarning(
360 [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
361 );
362 }
363
364 foreach ( $paramList as $name => $value ) {
365 if ( !$h->validateParam( $name, $value ) ) {
366 $this->dieWithError(
367 [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
368 );
369 }
370 }
371
372 $finalParams = $thumbParams + $paramList;
373 $this->checkParameterNormalise( $image, $finalParams );
374 return $finalParams;
375 }
376
388 protected function checkParameterNormalise( $image, $finalParams ) {
389 $h = $image->getHandler();
390 if ( !$h ) {
391 return;
392 }
393 // Note: normaliseParams modifies the array in place, but we aren't interested
394 // in the actual normalised version, only if we can actually normalise them,
395 // so we use the functions scope to throw away the normalisations.
396 if ( !$h->normaliseParams( $image, $finalParams ) ) {
397 $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
398 }
399 }
400
416 public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
417 $anyHidden = false;
418
419 $services = MediaWikiServices::getInstance();
420
421 if ( !$opts || is_string( $opts ) ) {
422 $opts = [
423 'version' => $opts ?: 'latest',
424 'language' => $services->getContentLanguage(),
425 'multilang' => false,
426 'extmetadatafilter' => [],
427 'revdelUser' => null,
428 ];
429 }
430 $version = $opts['version'];
431 $vals = [
432 ApiResult::META_TYPE => 'assoc',
433 ];
434
435 // Some information will be unavailable if the file does not exist. T221812
436 $exists = $file->exists();
437
438 // A file may have DB metadata even when the storage blob is missing
439 // (e.g. old file revisions with empty archive names). T221812 T239213 T426802
440 $hasDbMetadata = $exists
441 || ( $file instanceof OldLocalFile && $file->hasDbRecord() );
442
443 // Timestamp is shown even if the file is revdelete'd in interface
444 // so do same here.
445 if ( isset( $prop['timestamp'] ) && $hasDbMetadata ) {
446 $vals['timestamp'] = wfTimestamp( TS::ISO_8601, $file->getTimestamp() );
447 }
448
449 // Handle external callers who don't pass revdelUser
450 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
451 $revdelUser = $opts['revdelUser'];
452 $canShowField = static function ( $field ) use ( $file, $revdelUser ) {
453 return $file->userCan( $field, $revdelUser );
454 };
455 } else {
456 $canShowField = static function ( $field ) use ( $file ) {
457 return !$file->isDeleted( $field );
458 };
459 }
460
461 $user = isset( $prop['user'] );
462 $userid = isset( $prop['userid'] );
463
464 if ( ( $user || $userid ) && $hasDbMetadata ) {
465 if ( $file->isDeleted( File::DELETED_USER ) ) {
466 $vals['userhidden'] = true;
467 $anyHidden = true;
468 }
469 if ( $canShowField( File::DELETED_USER ) ) {
470 // Already checked if the field can be show
471 $uploader = $file->getUploader( File::RAW );
472 if ( $user ) {
473 $vals['user'] = $uploader ? $uploader->getName() : '';
474 }
475 if ( $userid ) {
476 $vals['userid'] = $uploader ? $uploader->getId() : 0;
477 }
478 if ( $uploader && $services->getUserNameUtils()->isTemp( $uploader->getName() ) ) {
479 $vals['temp'] = true;
480 }
481 if ( $uploader && !$uploader->isRegistered() ) {
482 $vals['anon'] = true;
483 }
484 }
485 }
486
487 // This is shown even if the file is revdelete'd in interface
488 // so do same here.
489 if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $hasDbMetadata ) {
490 $vals['size'] = (int)$file->getSize();
491 $vals['width'] = (int)$file->getWidth();
492 $vals['height'] = (int)$file->getHeight();
493
494 // pageCount and duration require the file handler which may
495 // access the file blob, so they need the file to exist. T221812
496 if ( $exists ) {
497 $pageCount = $file->pageCount();
498 if ( $pageCount !== false ) {
499 $vals['pagecount'] = $pageCount;
500 }
501
502 // length as in how many seconds long a video is.
503 $length = $file->getLength();
504 if ( $length ) {
505 // Call it duration, because "length" can be ambiguous.
506 $vals['duration'] = (float)$length;
507 }
508 }
509 }
510
511 $pcomment = isset( $prop['parsedcomment'] );
512 $comment = isset( $prop['comment'] );
513
514 if ( ( $pcomment || $comment ) && $hasDbMetadata ) {
515 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
516 $vals['commenthidden'] = true;
517 $anyHidden = true;
518 }
519 if ( $canShowField( File::DELETED_COMMENT ) ) {
520 if ( $pcomment ) {
521 $vals['parsedcomment'] = $services->getCommentFormatter()->format(
522 $file->getDescription( File::RAW ), $file->getTitle() );
523 }
524 if ( $comment ) {
525 $vals['comment'] = $file->getDescription( File::RAW );
526 }
527 }
528 }
529
530 $canonicaltitle = isset( $prop['canonicaltitle'] );
531 $url = isset( $prop['url'] );
532 $sha1 = isset( $prop['sha1'] );
533 $meta = isset( $prop['metadata'] );
534 $extmetadata = isset( $prop['extmetadata'] );
535 $commonmeta = isset( $prop['commonmetadata'] );
536 $mime = isset( $prop['mime'] );
537 $mediatype = isset( $prop['mediatype'] );
538 $archive = isset( $prop['archivename'] );
539 $bitdepth = isset( $prop['bitdepth'] );
540 $uploadwarning = isset( $prop['uploadwarning'] );
541
542 if ( $uploadwarning ) {
543 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
544 }
545
546 if ( $file->isDeleted( File::DELETED_FILE ) ) {
547 $vals['filehidden'] = true;
548 $anyHidden = true;
549 }
550
551 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
552 $vals['suppressed'] = true;
553 }
554
555 // Early return, tidier than indenting all following things one level
556 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser']
557 && !$file->userCan( File::DELETED_FILE, $opts['revdelUser'] )
558 ) {
559 return $vals;
560 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
561 return $vals;
562 }
563
564 if ( $canonicaltitle ) {
565 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
566 }
567
568 if ( $url ) {
569 $urlUtils = $services->getUrlUtils();
570
571 if ( $exists ) {
572 if ( $thumbParams !== null ) {
573 $thumbParams['requestProvenance'] = 'imageinfo';
574 $mto = $file->transform( $thumbParams );
575 self::$transformCount++;
576 if ( $mto && !$mto->isError() ) {
577 $vals['thumburl'] = (string)$urlUtils->expand( $mto->getUrl(), PROTO_CURRENT );
578
579 // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
580 // thumbnail sizes for the thumbnail actual size
581 if ( $mto->getUrl() !== $file->getUrl() ) {
582 $vals['thumbwidth'] = (int)$mto->getWidth();
583 $vals['thumbheight'] = (int)$mto->getHeight();
584 } else {
585 $vals['thumbwidth'] = (int)$file->getWidth();
586 $vals['thumbheight'] = (int)$file->getHeight();
587 }
588
589 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
590 [ , $mime ] = $file->getHandler()->getThumbType(
591 $mto->getExtension(), $file->getMimeType(), $thumbParams );
592 $vals['thumbmime'] = $mime;
593 }
594 // Report srcset parameters
595 Linker::processResponsiveImages( $file, $mto, [
596 'width' => $vals['thumbwidth'],
597 'height' => $vals['thumbheight']
598 ] + $thumbParams );
599 foreach ( $mto->responsiveUrls as $density => $url ) {
600 $vals['responsiveUrls'][$density] = (string)$urlUtils->expand( $url, PROTO_CURRENT );
601 }
602 } elseif ( $mto && $mto->isError() ) {
604 '@phan-var MediaTransformError $mto';
605 $vals['thumberror'] = $mto->toText();
606 }
607 }
608 $vals['url'] = (string)$urlUtils->expand( $file->appendRequestProvenance( $file->getFullUrl(), [
609 'format' => 'original',
610 'generator' => 'imageinfo',
611 ] ), PROTO_CURRENT );
612 }
613 $vals['descriptionurl'] = (string)$urlUtils->expand( $file->getDescriptionUrl(), PROTO_CURRENT );
614
615 $shortDescriptionUrl = $file->getDescriptionShortUrl();
616 if ( $shortDescriptionUrl !== null ) {
617 $vals['descriptionshorturl'] = (string)$urlUtils->expand( $shortDescriptionUrl, PROTO_CURRENT );
618 }
619 }
620
621 if ( !$exists ) {
622 $vals['filemissing'] = true;
623 }
624
625 if ( $sha1 && $exists ) {
626 $vals['sha1'] = \Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
627 }
628
629 if ( $meta && $exists ) {
630 $metadata = $file->getMetadataArray();
631 if ( $metadata && $version !== 'latest' ) {
632 $metadata = $file->convertMetadataVersion( $metadata, $version );
633 }
634 $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
635 }
636 if ( $commonmeta && $exists ) {
637 $metaArray = $file->getCommonMetaArray();
638 $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
639 }
640
641 if ( $extmetadata && $exists ) {
642 // Note, this should return an array where all the keys
643 // start with a letter, and all the values are strings.
644 // Thus there should be no issue with format=xml.
645 $format = new FormatMetadata;
646 $format->setSingleLanguage( !$opts['multilang'] );
647 // @phan-suppress-next-line PhanUndeclaredMethod
648 $format->getContext()->setLanguage( $opts['language'] );
649 $extmetaArray = $format->fetchExtendedMetadata( $file );
650 if ( $opts['extmetadatafilter'] ) {
651 $extmetaArray = array_intersect_key(
652 $extmetaArray, array_fill_keys( $opts['extmetadatafilter'], true )
653 );
654 }
655 $vals['extmetadata'] = $extmetaArray;
656 }
657
658 if ( $mime && $exists ) {
659 $vals['mime'] = $file->getMimeType();
660 }
661
662 if ( $mediatype && $exists ) {
663 $vals['mediatype'] = $file->getMediaType();
664 }
665
666 if ( $archive && $file->isOld() ) {
668 '@phan-var OldLocalFile $file';
669 $vals['archivename'] = $file->getArchiveName();
670 }
671
672 if ( $bitdepth && $exists ) {
673 $vals['bitdepth'] = $file->getBitDepth();
674 }
675
676 return $vals;
677 }
678
686 protected static function getTransformCount() {
687 return self::$transformCount;
688 }
689
695 public static function processMetaData( $metadata, $result ) {
696 $retval = [];
697 if ( is_array( $metadata ) ) {
698 foreach ( $metadata as $key => $value ) {
699 $r = [
700 'name' => $key,
701 ApiResult::META_BC_BOOLS => [ 'value' ],
702 ];
703 if ( is_array( $value ) ) {
704 $r['value'] = static::processMetaData( $value, $result );
705 } else {
706 $r['value'] = $value;
707 }
708 $retval[] = $r;
709 }
710 }
711 ApiResult::setIndexedTagName( $retval, 'metadata' );
712
713 return $retval;
714 }
715
717 public function getCacheMode( $params ) {
718 if ( $this->userCanSeeRevDel() ) {
719 return 'private';
720 }
721
722 return 'public';
723 }
724
730 protected function getContinueStr( $img, $start = null ) {
731 return $img->getOriginalTitle()->getDBkey() . '|' . ( $start ?? $img->getTimestamp() );
732 }
733
735 public function getAllowedParams() {
736 return [
737 'prop' => [
738 ParamValidator::PARAM_ISMULTI => true,
739 ParamValidator::PARAM_DEFAULT => 'timestamp|user',
740 ParamValidator::PARAM_TYPE => static::getPropertyNames(),
741 ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
742 ],
743 'limit' => [
744 ParamValidator::PARAM_TYPE => 'limit',
745 ParamValidator::PARAM_DEFAULT => 1,
746 IntegerDef::PARAM_MIN => 1,
747 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
748 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
749 ],
750 'start' => [
751 ParamValidator::PARAM_TYPE => 'timestamp'
752 ],
753 'end' => [
754 ParamValidator::PARAM_TYPE => 'timestamp'
755 ],
756 'urlwidth' => [
757 ParamValidator::PARAM_TYPE => 'integer',
758 ParamValidator::PARAM_DEFAULT => -1,
760 'apihelp-query+imageinfo-param-urlwidth',
762 ],
763 ],
764 'urlheight' => [
765 ParamValidator::PARAM_TYPE => 'integer',
766 ParamValidator::PARAM_DEFAULT => -1
767 ],
768 'metadataversion' => [
769 ParamValidator::PARAM_TYPE => 'string',
770 ParamValidator::PARAM_DEFAULT => '1',
771 ],
772 'extmetadatalanguage' => [
773 ParamValidator::PARAM_TYPE => 'string',
774 ParamValidator::PARAM_DEFAULT =>
775 $this->contentLanguage->getCode(),
776 ],
777 'extmetadatamultilang' => [
778 ParamValidator::PARAM_TYPE => 'boolean',
779 ParamValidator::PARAM_DEFAULT => false,
780 ],
781 'extmetadatafilter' => [
782 ParamValidator::PARAM_TYPE => 'string',
783 ParamValidator::PARAM_ISMULTI => true,
784 ],
785 'urlparam' => [
786 ParamValidator::PARAM_DEFAULT => '',
787 ParamValidator::PARAM_TYPE => 'string',
788 ],
789 'badfilecontexttitle' => [
790 ParamValidator::PARAM_TYPE => 'string',
791 ],
792 'continue' => [
793 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
794 ],
795 'localonly' => [
796 ParamValidator::PARAM_TYPE => 'boolean',
797 ParamValidator::PARAM_DEFAULT => false,
798 ],
799 ];
800 }
801
808 public static function getPropertyNames( $filter = [] ) {
809 return array_keys( static::getPropertyMessages( $filter ) );
810 }
811
818 public static function getPropertyMessages( $filter = [] ) {
819 return array_diff_key(
820 [
821 'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
822 'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
823 'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
824 'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
825 'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
826 'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
827 'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
828 'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
829 'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
830 'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
831 'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
832 'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
833 'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
834 'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
835 'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
836 'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
837 'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
838 'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
839 'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
840 'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
841 ],
842 array_fill_keys( $filter, true )
843 );
844 }
845
847 protected function getExamplesMessages() {
848 return [
849 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
850 => 'apihelp-query+imageinfo-example-simple',
851 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
852 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
853 => 'apihelp-query+imageinfo-example-dated',
854 ];
855 }
856
858 public function getHelpUrls() {
859 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
860 }
861}
862
864class_alias( ApiQueryImageInfo::class, 'ApiQueryImageInfo' );
const NS_FILE
Definition Defines.php:57
const PROTO_CURRENT
Definition Defines.php:222
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1522
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:566
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1707
getResult()
Get the result object.
Definition ApiBase.php:696
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:206
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1439
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:166
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:233
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:837
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:231
This is a base class for all Query modules.
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.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
A query action to get image information and upload history.
checkParameterNormalise( $image, $finalParams)
Verify that the final image parameters can be normalised.
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
static processMetaData( $metadata, $result)
__construct(ApiQuery $query, string $moduleName, $prefixOrRepoGroup=null, $repoGroupOrContentLanguage=null, $contentLanguageOrBadFileLookup=null, $badFileLookupOrUnused=null)
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
getScale( $params)
From parameters, construct a 'scale' array.
static getTransformCount()
Get the count of image transformations performed.
getCacheMode( $params)
Get the cache mode for the data generated by this module.Override this in the module subclass....
This is the main query class.
Definition ApiQuery.php:36
const IGNORE_CONFLICT_KEYS
For addValue(), setValue() and similar functions, do allow override of conflicting keys.
Definition ApiResult.php:72
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
const META_TYPE
Key for the 'type' metadata item.
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:80
Old file in the oldimage table.
hasDbRecord()
Whether this file has a database record in the file metadata tables.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Base class for language-specific code.
Definition Language.php:65
Some internal bits split of from Skin.php.
Definition Linker.php:48
A class containing constants representing the names of configuration variables.
const ThumbLimits
Name constant for the ThumbLimits setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Format Image metadata values into a human readable form.
setSingleLanguage( $val)
Trigger only outputting single language for multilanguage fields.
Basic media transform error class.
Form for uploading media files.
static getExistsWarning( $exists)
Functions for formatting warnings.
Represents a title within MediaWiki.
Definition Title.php:69
UploadBase and subclasses are the backend of MediaWiki's file uploads.
Service for formatting and validating API parameters.
Type definition for integer types.