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