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