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 // Timestamp is shown even if the file is revdelete'd in interface
439 // so do same here.
440 if ( isset( $prop['timestamp'] ) && $exists ) {
441 $vals['timestamp'] = wfTimestamp( TS::ISO_8601, $file->getTimestamp() );
442 }
443
444 // Handle external callers who don't pass revdelUser
445 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
446 $revdelUser = $opts['revdelUser'];
447 $canShowField = static function ( $field ) use ( $file, $revdelUser ) {
448 return $file->userCan( $field, $revdelUser );
449 };
450 } else {
451 $canShowField = static function ( $field ) use ( $file ) {
452 return !$file->isDeleted( $field );
453 };
454 }
455
456 $user = isset( $prop['user'] );
457 $userid = isset( $prop['userid'] );
458
459 if ( ( $user || $userid ) && $exists ) {
460 if ( $file->isDeleted( File::DELETED_USER ) ) {
461 $vals['userhidden'] = true;
462 $anyHidden = true;
463 }
464 if ( $canShowField( File::DELETED_USER ) ) {
465 // Already checked if the field can be show
466 $uploader = $file->getUploader( File::RAW );
467 if ( $user ) {
468 $vals['user'] = $uploader ? $uploader->getName() : '';
469 }
470 if ( $userid ) {
471 $vals['userid'] = $uploader ? $uploader->getId() : 0;
472 }
473 if ( $uploader && $services->getUserNameUtils()->isTemp( $uploader->getName() ) ) {
474 $vals['temp'] = true;
475 }
476 if ( $uploader && !$uploader->isRegistered() ) {
477 $vals['anon'] = true;
478 }
479 }
480 }
481
482 // This is shown even if the file is revdelete'd in interface
483 // so do same here.
484 if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
485 $vals['size'] = (int)$file->getSize();
486 $vals['width'] = (int)$file->getWidth();
487 $vals['height'] = (int)$file->getHeight();
488
489 $pageCount = $file->pageCount();
490 if ( $pageCount !== false ) {
491 $vals['pagecount'] = $pageCount;
492 }
493
494 // length as in how many seconds long a video is.
495 $length = $file->getLength();
496 if ( $length ) {
497 // Call it duration, because "length" can be ambiguous.
498 $vals['duration'] = (float)$length;
499 }
500 }
501
502 $pcomment = isset( $prop['parsedcomment'] );
503 $comment = isset( $prop['comment'] );
504
505 if ( ( $pcomment || $comment ) && $exists ) {
506 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
507 $vals['commenthidden'] = true;
508 $anyHidden = true;
509 }
510 if ( $canShowField( File::DELETED_COMMENT ) ) {
511 if ( $pcomment ) {
512 $vals['parsedcomment'] = $services->getCommentFormatter()->format(
513 $file->getDescription( File::RAW ), $file->getTitle() );
514 }
515 if ( $comment ) {
516 $vals['comment'] = $file->getDescription( File::RAW );
517 }
518 }
519 }
520
521 $canonicaltitle = isset( $prop['canonicaltitle'] );
522 $url = isset( $prop['url'] );
523 $sha1 = isset( $prop['sha1'] );
524 $meta = isset( $prop['metadata'] );
525 $extmetadata = isset( $prop['extmetadata'] );
526 $commonmeta = isset( $prop['commonmetadata'] );
527 $mime = isset( $prop['mime'] );
528 $mediatype = isset( $prop['mediatype'] );
529 $archive = isset( $prop['archivename'] );
530 $bitdepth = isset( $prop['bitdepth'] );
531 $uploadwarning = isset( $prop['uploadwarning'] );
532
533 if ( $uploadwarning ) {
534 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
535 }
536
537 if ( $file->isDeleted( File::DELETED_FILE ) ) {
538 $vals['filehidden'] = true;
539 $anyHidden = true;
540 }
541
542 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
543 $vals['suppressed'] = true;
544 }
545
546 // Early return, tidier than indenting all following things one level
547 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser']
548 && !$file->userCan( File::DELETED_FILE, $opts['revdelUser'] )
549 ) {
550 return $vals;
551 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
552 return $vals;
553 }
554
555 if ( $canonicaltitle ) {
556 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
557 }
558
559 if ( $url ) {
560 $urlUtils = $services->getUrlUtils();
561
562 if ( $exists ) {
563 if ( $thumbParams !== null ) {
564 $mto = $file->transform( $thumbParams );
565 self::$transformCount++;
566 if ( $mto && !$mto->isError() ) {
567 $vals['thumburl'] = (string)$urlUtils->expand( $mto->getUrl(), PROTO_CURRENT );
568
569 // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
570 // thumbnail sizes for the thumbnail actual size
571 if ( $mto->getUrl() !== $file->getUrl() ) {
572 $vals['thumbwidth'] = (int)$mto->getWidth();
573 $vals['thumbheight'] = (int)$mto->getHeight();
574 } else {
575 $vals['thumbwidth'] = (int)$file->getWidth();
576 $vals['thumbheight'] = (int)$file->getHeight();
577 }
578
579 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
580 [ , $mime ] = $file->getHandler()->getThumbType(
581 $mto->getExtension(), $file->getMimeType(), $thumbParams );
582 $vals['thumbmime'] = $mime;
583 }
584 // Report srcset parameters
585 Linker::processResponsiveImages( $file, $mto, [
586 'width' => $vals['thumbwidth'],
587 'height' => $vals['thumbheight']
588 ] + $thumbParams );
589 foreach ( $mto->responsiveUrls as $density => $url ) {
590 $vals['responsiveUrls'][$density] = (string)$urlUtils->expand( $url, PROTO_CURRENT );
591 }
592 } elseif ( $mto && $mto->isError() ) {
594 '@phan-var MediaTransformError $mto';
595 $vals['thumberror'] = $mto->toText();
596 }
597 }
598 $vals['url'] = (string)$urlUtils->expand( $file->getFullUrl(), PROTO_CURRENT );
599 }
600 $vals['descriptionurl'] = (string)$urlUtils->expand( $file->getDescriptionUrl(), PROTO_CURRENT );
601
602 $shortDescriptionUrl = $file->getDescriptionShortUrl();
603 if ( $shortDescriptionUrl !== null ) {
604 $vals['descriptionshorturl'] = (string)$urlUtils->expand( $shortDescriptionUrl, PROTO_CURRENT );
605 }
606 }
607
608 if ( !$exists ) {
609 $vals['filemissing'] = true;
610 }
611
612 if ( $sha1 && $exists ) {
613 $vals['sha1'] = \Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
614 }
615
616 if ( $meta && $exists ) {
617 $metadata = $file->getMetadataArray();
618 if ( $metadata && $version !== 'latest' ) {
619 $metadata = $file->convertMetadataVersion( $metadata, $version );
620 }
621 $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
622 }
623 if ( $commonmeta && $exists ) {
624 $metaArray = $file->getCommonMetaArray();
625 $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
626 }
627
628 if ( $extmetadata && $exists ) {
629 // Note, this should return an array where all the keys
630 // start with a letter, and all the values are strings.
631 // Thus there should be no issue with format=xml.
632 $format = new FormatMetadata;
633 $format->setSingleLanguage( !$opts['multilang'] );
634 // @phan-suppress-next-line PhanUndeclaredMethod
635 $format->getContext()->setLanguage( $opts['language'] );
636 $extmetaArray = $format->fetchExtendedMetadata( $file );
637 if ( $opts['extmetadatafilter'] ) {
638 $extmetaArray = array_intersect_key(
639 $extmetaArray, array_fill_keys( $opts['extmetadatafilter'], true )
640 );
641 }
642 $vals['extmetadata'] = $extmetaArray;
643 }
644
645 if ( $mime && $exists ) {
646 $vals['mime'] = $file->getMimeType();
647 }
648
649 if ( $mediatype && $exists ) {
650 $vals['mediatype'] = $file->getMediaType();
651 }
652
653 if ( $archive && $file->isOld() ) {
655 '@phan-var OldLocalFile $file';
656 $vals['archivename'] = $file->getArchiveName();
657 }
658
659 if ( $bitdepth && $exists ) {
660 $vals['bitdepth'] = $file->getBitDepth();
661 }
662
663 return $vals;
664 }
665
673 protected static function getTransformCount() {
674 return self::$transformCount;
675 }
676
682 public static function processMetaData( $metadata, $result ) {
683 $retval = [];
684 if ( is_array( $metadata ) ) {
685 foreach ( $metadata as $key => $value ) {
686 $r = [
687 'name' => $key,
688 ApiResult::META_BC_BOOLS => [ 'value' ],
689 ];
690 if ( is_array( $value ) ) {
691 $r['value'] = static::processMetaData( $value, $result );
692 } else {
693 $r['value'] = $value;
694 }
695 $retval[] = $r;
696 }
697 }
698 ApiResult::setIndexedTagName( $retval, 'metadata' );
699
700 return $retval;
701 }
702
704 public function getCacheMode( $params ) {
705 if ( $this->userCanSeeRevDel() ) {
706 return 'private';
707 }
708
709 return 'public';
710 }
711
717 protected function getContinueStr( $img, $start = null ) {
718 return $img->getOriginalTitle()->getDBkey() . '|' . ( $start ?? $img->getTimestamp() );
719 }
720
722 public function getAllowedParams() {
723 return [
724 'prop' => [
725 ParamValidator::PARAM_ISMULTI => true,
726 ParamValidator::PARAM_DEFAULT => 'timestamp|user',
727 ParamValidator::PARAM_TYPE => static::getPropertyNames(),
728 ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
729 ],
730 'limit' => [
731 ParamValidator::PARAM_TYPE => 'limit',
732 ParamValidator::PARAM_DEFAULT => 1,
733 IntegerDef::PARAM_MIN => 1,
734 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
735 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
736 ],
737 'start' => [
738 ParamValidator::PARAM_TYPE => 'timestamp'
739 ],
740 'end' => [
741 ParamValidator::PARAM_TYPE => 'timestamp'
742 ],
743 'urlwidth' => [
744 ParamValidator::PARAM_TYPE => 'integer',
745 ParamValidator::PARAM_DEFAULT => -1,
747 'apihelp-query+imageinfo-param-urlwidth',
749 ],
750 ],
751 'urlheight' => [
752 ParamValidator::PARAM_TYPE => 'integer',
753 ParamValidator::PARAM_DEFAULT => -1
754 ],
755 'metadataversion' => [
756 ParamValidator::PARAM_TYPE => 'string',
757 ParamValidator::PARAM_DEFAULT => '1',
758 ],
759 'extmetadatalanguage' => [
760 ParamValidator::PARAM_TYPE => 'string',
761 ParamValidator::PARAM_DEFAULT =>
762 $this->contentLanguage->getCode(),
763 ],
764 'extmetadatamultilang' => [
765 ParamValidator::PARAM_TYPE => 'boolean',
766 ParamValidator::PARAM_DEFAULT => false,
767 ],
768 'extmetadatafilter' => [
769 ParamValidator::PARAM_TYPE => 'string',
770 ParamValidator::PARAM_ISMULTI => true,
771 ],
772 'urlparam' => [
773 ParamValidator::PARAM_DEFAULT => '',
774 ParamValidator::PARAM_TYPE => 'string',
775 ],
776 'badfilecontexttitle' => [
777 ParamValidator::PARAM_TYPE => 'string',
778 ],
779 'continue' => [
780 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
781 ],
782 'localonly' => [
783 ParamValidator::PARAM_TYPE => 'boolean',
784 ParamValidator::PARAM_DEFAULT => false,
785 ],
786 ];
787 }
788
795 public static function getPropertyNames( $filter = [] ) {
796 return array_keys( static::getPropertyMessages( $filter ) );
797 }
798
805 public static function getPropertyMessages( $filter = [] ) {
806 return array_diff_key(
807 [
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',
828 ],
829 array_fill_keys( $filter, true )
830 );
831 }
832
834 protected function getExamplesMessages() {
835 return [
836 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
837 => 'apihelp-query+imageinfo-example-simple',
838 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
839 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
840 => 'apihelp-query+imageinfo-example-dated',
841 ];
842 }
843
845 public function getHelpUrls() {
846 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
847 }
848}
849
851class_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:1507
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:552
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1692
getResult()
Get the result object.
Definition ApiBase.php:682
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:207
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1425
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:167
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:234
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:823
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:232
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:79
Old file in the oldimage table.
Prioritized list of file repositories.
Definition RepoGroup.php:30
Base class for language-specific code.
Definition Language.php:68
Some internal bits split of from Skin.php.
Definition Linker.php:47
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.