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