MediaWiki 1.41.2
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() {
84 $params = $this->extractRequestParams();
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 && !$uploader->isRegistered() ) {
480 $vals['anon'] = true;
481 }
482 }
483 }
484
485 // This is shown even if the file is revdelete'd in interface
486 // so do same here.
487 if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
488 $vals['size'] = (int)$file->getSize();
489 $vals['width'] = (int)$file->getWidth();
490 $vals['height'] = (int)$file->getHeight();
491
492 $pageCount = $file->pageCount();
493 if ( $pageCount !== false ) {
494 $vals['pagecount'] = $pageCount;
495 }
496
497 // length as in how many seconds long a video is.
498 $length = $file->getLength();
499 if ( $length ) {
500 // Call it duration, because "length" can be ambiguous.
501 $vals['duration'] = (float)$length;
502 }
503 }
504
505 $pcomment = isset( $prop['parsedcomment'] );
506 $comment = isset( $prop['comment'] );
507
508 if ( ( $pcomment || $comment ) && $exists ) {
509 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
510 $vals['commenthidden'] = true;
511 $anyHidden = true;
512 }
513 if ( $canShowField( File::DELETED_COMMENT ) ) {
514 if ( $pcomment ) {
515 $vals['parsedcomment'] = $services->getCommentFormatter()->format(
516 $file->getDescription( File::RAW ), $file->getTitle() );
517 }
518 if ( $comment ) {
519 $vals['comment'] = $file->getDescription( File::RAW );
520 }
521 }
522 }
523
524 $canonicaltitle = isset( $prop['canonicaltitle'] );
525 $url = isset( $prop['url'] );
526 $sha1 = isset( $prop['sha1'] );
527 $meta = isset( $prop['metadata'] );
528 $extmetadata = isset( $prop['extmetadata'] );
529 $commonmeta = isset( $prop['commonmetadata'] );
530 $mime = isset( $prop['mime'] );
531 $mediatype = isset( $prop['mediatype'] );
532 $archive = isset( $prop['archivename'] );
533 $bitdepth = isset( $prop['bitdepth'] );
534 $uploadwarning = isset( $prop['uploadwarning'] );
535
536 if ( $uploadwarning ) {
537 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
538 }
539
540 if ( $file->isDeleted( File::DELETED_FILE ) ) {
541 $vals['filehidden'] = true;
542 $anyHidden = true;
543 }
544
545 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
546 $vals['suppressed'] = true;
547 }
548
549 // Early return, tidier than indenting all following things one level
550 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser']
551 && !$file->userCan( File::DELETED_FILE, $opts['revdelUser'] )
552 ) {
553 return $vals;
554 } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
555 return $vals;
556 }
557
558 if ( $canonicaltitle ) {
559 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
560 }
561
562 if ( $url ) {
563 $urlUtils = $services->getUrlUtils();
564
565 if ( $exists ) {
566 if ( $thumbParams !== null ) {
567 $mto = $file->transform( $thumbParams );
568 self::$transformCount++;
569 if ( $mto && !$mto->isError() ) {
570 $vals['thumburl'] = (string)$urlUtils->expand( $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] = (string)$urlUtils->expand( $url, PROTO_CURRENT );
594 }
595 } elseif ( $mto && $mto->isError() ) {
597 '@phan-var MediaTransformError $mto';
598 $vals['thumberror'] = $mto->toText();
599 }
600 }
601 $vals['url'] = (string)$urlUtils->expand( $file->getFullUrl(), PROTO_CURRENT );
602 }
603 $vals['descriptionurl'] = (string)$urlUtils->expand( $file->getDescriptionUrl(), PROTO_CURRENT );
604
605 $shortDescriptionUrl = $file->getDescriptionShortUrl();
606 if ( $shortDescriptionUrl !== null ) {
607 $vals['descriptionshorturl'] = (string)$urlUtils->expand( $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:196
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:1515
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:537
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1706
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:209
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:234
getResult()
Get the result object.
Definition ApiBase.php:667
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:807
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:169
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1433
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:236
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:70
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:76
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