MediaWiki  master
ApiQueryImageInfo.php
Go to the documentation of this file.
1 <?php
28 
35  public const TRANSFORM_LIMIT = 50;
36  private static $transformCount = 0;
37 
39  private $repoGroup;
40 
43 
45  private $badFileLookup;
46 
55  public function __construct(
56  ApiQuery $query,
57  $moduleName,
58  $prefixOrRepoGroup = null,
59  $repoGroupOrContentLanguage = null,
60  $contentLanguageOrBadFileLookup = null,
61  $badFileLookupOrUnused = null
62  ) {
63  // We allow a subclass to override the prefix, to create a related API module.
64  // The ObjectFactory is injecting the services without the prefix.
65  if ( !is_string( $prefixOrRepoGroup ) ) {
66  $prefix = 'ii';
67  $repoGroup = $prefixOrRepoGroup;
68  $contentLanguage = $repoGroupOrContentLanguage;
69  $badFileLookup = $contentLanguageOrBadFileLookup;
70  // $badFileLookupOrUnused is null in this case
71  } else {
72  $prefix = $prefixOrRepoGroup;
73  $repoGroup = $repoGroupOrContentLanguage;
74  $contentLanguage = $contentLanguageOrBadFileLookup;
75  $badFileLookup = $badFileLookupOrUnused;
76  }
77  parent::__construct( $query, $moduleName, $prefix );
78  // This class is extended and therefor fallback to global state - T259960
79  $services = MediaWikiServices::getInstance();
80  $this->repoGroup = $repoGroup ?? $services->getRepoGroup();
81  $this->contentLanguage = $contentLanguage ?? $services->getContentLanguage();
82  $this->badFileLookup = $badFileLookup ?? $services->getBadFileLookup();
83  }
84 
85  public function execute() {
86  $params = $this->extractRequestParams();
87 
88  $prop = array_fill_keys( $params['prop'], true );
89 
90  $scale = $this->getScale( $params );
91 
92  $opts = [
93  'version' => $params['metadataversion'],
94  'language' => $params['extmetadatalanguage'],
95  'multilang' => $params['extmetadatamultilang'],
96  'extmetadatafilter' => $params['extmetadatafilter'],
97  'revdelUser' => $this->getAuthority(),
98  ];
99 
100  if ( isset( $params['badfilecontexttitle'] ) ) {
101  $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
102  if ( !$badFileContextTitle ) {
103  $p = $this->getModulePrefix();
104  $this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
105  }
106  } else {
107  $badFileContextTitle = null;
108  }
109 
110  $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
111  if ( !empty( $pageIds[NS_FILE] ) ) {
112  $titles = array_keys( $pageIds[NS_FILE] );
113  asort( $titles ); // Ensure the order is always the same
114 
115  $fromTitle = null;
116  if ( $params['continue'] !== null ) {
117  $cont = explode( '|', $params['continue'] );
118  $this->dieContinueUsageIf( count( $cont ) != 2 );
119  $fromTitle = strval( $cont[0] );
120  $fromTimestamp = $cont[1];
121  // Filter out any titles before $fromTitle
122  foreach ( $titles as $key => $title ) {
123  if ( $title < $fromTitle ) {
124  unset( $titles[$key] );
125  } else {
126  break;
127  }
128  }
129  }
130 
131  $performer = $this->getAuthority();
132  $findTitles = array_map( static function ( $title ) use ( $performer ) {
133  return [
134  'title' => $title,
135  'private' => $performer,
136  ];
137  }, $titles );
138 
139  if ( $params['localonly'] ) {
140  $images = $this->repoGroup->getLocalRepo()->findFiles( $findTitles );
141  } else {
142  $images = $this->repoGroup->findFiles( $findTitles );
143  }
144 
145  $result = $this->getResult();
146  foreach ( $titles as $title ) {
147  $info = [];
148  $pageId = $pageIds[NS_FILE][$title];
149  // @phan-suppress-next-next-line PhanPossiblyUndeclaredVariable
150  // $fromTimestamp declared when $fromTitle notnull
151  $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
152 
153  if ( !isset( $images[$title] ) ) {
154  if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
155  // uploadwarning and badfile need info about non-existing files
156  $images[$title] = $this->repoGroup->getLocalRepo()->newFile( $title );
157  // Doesn't exist, so set an empty image repository
158  $info['imagerepository'] = '';
159  } else {
160  $result->addValue(
161  [ 'query', 'pages', (int)$pageId ],
162  'imagerepository', ''
163  );
164  // The above can't fail because it doesn't increase the result size
165  continue;
166  }
167  }
168 
170  $img = $images[$title];
171 
172  if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
173  if ( count( $pageIds[NS_FILE] ) == 1 ) {
174  // See the 'the user is screwed' comment below
175  $this->setContinueEnumParameter( 'start',
176  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
177  );
178  } else {
179  $this->setContinueEnumParameter( 'continue',
180  $this->getContinueStr( $img, $start ) );
181  }
182  break;
183  }
184 
185  if ( !isset( $info['imagerepository'] ) ) {
186  $info['imagerepository'] = $img->getRepoName();
187  }
188  if ( isset( $prop['badfile'] ) ) {
189  $info['badfile'] = (bool)$this->badFileLookup->isBadFile( $title, $badFileContextTitle );
190  }
191 
192  $fit = $result->addValue( [ 'query', 'pages' ], (int)$pageId, $info );
193  if ( !$fit ) {
194  if ( count( $pageIds[NS_FILE] ) == 1 ) {
195  // The user is screwed. imageinfo can't be solely
196  // responsible for exceeding the limit in this case,
197  // so set a query-continue that just returns the same
198  // thing again. When the violating queries have been
199  // out-continued, the result will get through
200  $this->setContinueEnumParameter( 'start',
201  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
202  );
203  } else {
204  $this->setContinueEnumParameter( 'continue',
205  $this->getContinueStr( $img, $start ) );
206  }
207  break;
208  }
209 
210  // Check if we can make the requested thumbnail, and get transform parameters.
211  $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
212 
213  // Parser::makeImage always sets a targetlang, usually based on the language
214  // the content is in. To support Parsoid's standalone mode, overload the badfilecontexttitle
215  // to also set the targetlang based on the page language. Don't add this unless we're
216  // already scaling since a set $finalThumbParams usually expects a width.
217  if ( $badFileContextTitle && $finalThumbParams ) {
218  $finalThumbParams['targetlang'] = $badFileContextTitle->getPageLanguage()->getCode();
219  }
220 
221  // Get information about the current version first
222  // Check that the current version is within the start-end boundaries
223  $gotOne = false;
224  if (
225  ( $start === null || $img->getTimestamp() <= $start ) &&
226  ( $params['end'] === null || $img->getTimestamp() >= $params['end'] )
227  ) {
228  $gotOne = true;
229 
230  $fit = $this->addPageSubItem( $pageId,
231  static::getInfo( $img, $prop, $result,
232  $finalThumbParams, $opts
233  )
234  );
235  if ( !$fit ) {
236  if ( count( $pageIds[NS_FILE] ) == 1 ) {
237  // See the 'the user is screwed' comment above
238  $this->setContinueEnumParameter( 'start',
239  wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
240  } else {
241  $this->setContinueEnumParameter( 'continue',
242  $this->getContinueStr( $img ) );
243  }
244  break;
245  }
246  }
247 
248  // Now get the old revisions
249  // Get one more to facilitate query-continue functionality
250  $count = ( $gotOne ? 1 : 0 );
251  $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
253  foreach ( $oldies as $oldie ) {
254  if ( ++$count > $params['limit'] ) {
255  // We've reached the extra one which shows that there are
256  // additional pages to be had. Stop here...
257  // Only set a query-continue if there was only one title
258  if ( count( $pageIds[NS_FILE] ) == 1 ) {
259  $this->setContinueEnumParameter( 'start',
260  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
261  }
262  break;
263  }
264  $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
265  $this->addPageSubItem( $pageId,
266  static::getInfo( $oldie, $prop, $result,
267  $finalThumbParams, $opts
268  )
269  );
270  if ( !$fit ) {
271  if ( count( $pageIds[NS_FILE] ) == 1 ) {
272  $this->setContinueEnumParameter( 'start',
273  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
274  } else {
275  $this->setContinueEnumParameter( 'continue',
276  $this->getContinueStr( $oldie ) );
277  }
278  break;
279  }
280  }
281  if ( !$fit ) {
282  break;
283  }
284  }
285  }
286  }
287 
293  public function getScale( $params ) {
294  if ( $params['urlwidth'] != -1 ) {
295  $scale = [];
296  $scale['width'] = $params['urlwidth'];
297  $scale['height'] = $params['urlheight'];
298  } elseif ( $params['urlheight'] != -1 ) {
299  // Height is specified but width isn't
300  // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
301  $scale = [];
302  $scale['height'] = $params['urlheight'];
303  } elseif ( $params['urlparam'] ) {
304  // Audio files might not have a width/height.
305  $scale = [];
306  } else {
307  $scale = null;
308  }
309 
310  return $scale;
311  }
312 
322  protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
323  if ( $thumbParams === null ) {
324  // No scaling requested
325  return null;
326  }
327  if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
328  // We want to limit only by height in this situation, so pass the
329  // image's full width as the limiting width. But some file types
330  // don't have a width of their own, so pick something arbitrary so
331  // thumbnailing the default icon works.
332  if ( $image->getWidth() <= 0 ) {
333  $thumbParams['width'] =
334  max( $this->getConfig()->get( MainConfigNames::ThumbLimits ) );
335  } else {
336  $thumbParams['width'] = $image->getWidth();
337  }
338  }
339 
340  if ( !$otherParams ) {
341  $this->checkParameterNormalise( $image, $thumbParams );
342  return $thumbParams;
343  }
344  $p = $this->getModulePrefix();
345 
346  $h = $image->getHandler();
347  if ( !$h ) {
348  $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
349 
350  return $thumbParams;
351  }
352 
353  $paramList = $h->parseParamString( $otherParams );
354  if ( !$paramList ) {
355  // Just set a warning (instead of dieWithError), as in many cases
356  // we could still render the image using width and height parameters,
357  // and this type of thing could happen between different versions of
358  // handlers.
359  $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
360  $this->checkParameterNormalise( $image, $thumbParams );
361  return $thumbParams;
362  }
363 
364  if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
365  if ( (int)$paramList['width'] != (int)$thumbParams['width'] ) {
366  $this->addWarning(
367  [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
368  );
369  }
370  }
371 
372  foreach ( $paramList as $name => $value ) {
373  if ( !$h->validateParam( $name, $value ) ) {
374  $this->dieWithError(
375  [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
376  );
377  }
378  }
379 
380  $finalParams = $thumbParams + $paramList;
381  $this->checkParameterNormalise( $image, $finalParams );
382  return $finalParams;
383  }
384 
396  protected function checkParameterNormalise( $image, $finalParams ) {
397  $h = $image->getHandler();
398  if ( !$h ) {
399  return;
400  }
401  // Note: normaliseParams modifies the array in place, but we aren't interested
402  // in the actual normalised version, only if we can actually normalise them,
403  // so we use the functions scope to throw away the normalisations.
404  if ( !$h->normaliseParams( $image, $finalParams ) ) {
405  $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
406  }
407  }
408 
424  public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
425  $anyHidden = false;
426 
427  if ( !$opts || is_string( $opts ) ) {
428  $opts = [
429  'version' => $opts ?: 'latest',
430  'language' => MediaWikiServices::getInstance()->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'] = Linker::formatComment(
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 ) {
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  if ( $exists ) {
564  if ( $thumbParams !== null ) {
565  $mto = $file->transform( $thumbParams );
566  self::$transformCount++;
567  if ( $mto && !$mto->isError() ) {
568  $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
569 
570  // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
571  // thumbnail sizes for the thumbnail actual size
572  if ( $mto->getUrl() !== $file->getUrl() ) {
573  $vals['thumbwidth'] = (int)$mto->getWidth();
574  $vals['thumbheight'] = (int)$mto->getHeight();
575  } else {
576  $vals['thumbwidth'] = (int)$file->getWidth();
577  $vals['thumbheight'] = (int)$file->getHeight();
578  }
579 
580  if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
581  list( , $mime ) = $file->getHandler()->getThumbType(
582  $mto->getExtension(), $file->getMimeType(), $thumbParams );
583  $vals['thumbmime'] = $mime;
584  }
585  // Report srcset parameters
587  'width' => $vals['thumbwidth'],
588  'height' => $vals['thumbheight']
589  ] + $thumbParams );
590  foreach ( $mto->responsiveUrls as $density => $url ) {
591  $vals['responsiveUrls'][$density] = wfExpandUrl( $url, PROTO_CURRENT );
592  }
593  } elseif ( $mto && $mto->isError() ) {
595  '@phan-var MediaTransformError $mto';
596  $vals['thumberror'] = $mto->toText();
597  }
598  }
599  $vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
600  }
601  $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
602 
603  $shortDescriptionUrl = $file->getDescriptionShortUrl();
604  if ( $shortDescriptionUrl !== null ) {
605  $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
606  }
607  }
608 
609  if ( !$exists ) {
610  $vals['filemissing'] = true;
611  }
612 
613  if ( $sha1 && $exists ) {
614  $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
615  }
616 
617  if ( $meta && $exists ) {
618  $metadata = $file->getMetadataArray();
619  if ( $metadata && $version !== 'latest' ) {
620  $metadata = $file->convertMetadataVersion( $metadata, $version );
621  }
622  $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
623  }
624  if ( $commonmeta && $exists ) {
625  $metaArray = $file->getCommonMetaArray();
626  $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
627  }
628 
629  if ( $extmetadata && $exists ) {
630  // Note, this should return an array where all the keys
631  // start with a letter, and all the values are strings.
632  // Thus there should be no issue with format=xml.
633  $format = new FormatMetadata;
634  $format->setSingleLanguage( !$opts['multilang'] );
635  // @phan-suppress-next-line PhanUndeclaredMethod
636  $format->getContext()->setLanguage( $opts['language'] );
637  $extmetaArray = $format->fetchExtendedMetadata( $file );
638  if ( $opts['extmetadatafilter'] ) {
639  $extmetaArray = array_intersect_key(
640  $extmetaArray, array_fill_keys( $opts['extmetadatafilter'], true )
641  );
642  }
643  $vals['extmetadata'] = $extmetaArray;
644  }
645 
646  if ( $mime && $exists ) {
647  $vals['mime'] = $file->getMimeType();
648  }
649 
650  if ( $mediatype && $exists ) {
651  $vals['mediatype'] = $file->getMediaType();
652  }
653 
654  if ( $archive && $file->isOld() ) {
656  '@phan-var OldLocalFile $file';
657  $vals['archivename'] = $file->getArchiveName();
658  }
659 
660  if ( $bitdepth && $exists ) {
661  $vals['bitdepth'] = $file->getBitDepth();
662  }
663 
664  return $vals;
665  }
666 
674  protected static function getTransformCount() {
675  return self::$transformCount;
676  }
677 
683  public static function processMetaData( $metadata, $result ) {
684  $retval = [];
685  if ( is_array( $metadata ) ) {
686  foreach ( $metadata as $key => $value ) {
687  $r = [
688  'name' => $key,
689  ApiResult::META_BC_BOOLS => [ 'value' ],
690  ];
691  if ( is_array( $value ) ) {
692  $r['value'] = static::processMetaData( $value, $result );
693  } else {
694  $r['value'] = $value;
695  }
696  $retval[] = $r;
697  }
698  }
699  ApiResult::setIndexedTagName( $retval, 'metadata' );
700 
701  return $retval;
702  }
703 
704  public function getCacheMode( $params ) {
705  if ( $this->userCanSeeRevDel() ) {
706  return 'private';
707  }
708 
709  return 'public';
710  }
711 
717  protected function getContinueStr( $img, $start = null ) {
718  if ( $start === null ) {
719  $start = $img->getTimestamp();
720  }
721 
722  return $img->getOriginalTitle()->getDBkey() . '|' . $start;
723  }
724 
725  public function getAllowedParams() {
726  return [
727  'prop' => [
728  ParamValidator::PARAM_ISMULTI => true,
729  ParamValidator::PARAM_DEFAULT => 'timestamp|user',
730  ParamValidator::PARAM_TYPE => static::getPropertyNames(),
731  ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
732  ],
733  'limit' => [
734  ParamValidator::PARAM_TYPE => 'limit',
735  ParamValidator::PARAM_DEFAULT => 1,
736  IntegerDef::PARAM_MIN => 1,
737  IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
738  IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
739  ],
740  'start' => [
741  ParamValidator::PARAM_TYPE => 'timestamp'
742  ],
743  'end' => [
744  ParamValidator::PARAM_TYPE => 'timestamp'
745  ],
746  'urlwidth' => [
747  ParamValidator::PARAM_TYPE => 'integer',
748  ParamValidator::PARAM_DEFAULT => -1,
750  'apihelp-query+imageinfo-param-urlwidth',
752  ],
753  ],
754  'urlheight' => [
755  ParamValidator::PARAM_TYPE => 'integer',
756  ParamValidator::PARAM_DEFAULT => -1
757  ],
758  'metadataversion' => [
759  ParamValidator::PARAM_TYPE => 'string',
760  ParamValidator::PARAM_DEFAULT => '1',
761  ],
762  'extmetadatalanguage' => [
763  ParamValidator::PARAM_TYPE => 'string',
764  ParamValidator::PARAM_DEFAULT =>
765  $this->contentLanguage->getCode(),
766  ],
767  'extmetadatamultilang' => [
768  ParamValidator::PARAM_TYPE => 'boolean',
769  ParamValidator::PARAM_DEFAULT => false,
770  ],
771  'extmetadatafilter' => [
772  ParamValidator::PARAM_TYPE => 'string',
773  ParamValidator::PARAM_ISMULTI => true,
774  ],
775  'urlparam' => [
776  ParamValidator::PARAM_DEFAULT => '',
777  ParamValidator::PARAM_TYPE => 'string',
778  ],
779  'badfilecontexttitle' => [
780  ParamValidator::PARAM_TYPE => 'string',
781  ],
782  'continue' => [
783  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
784  ],
785  'localonly' => false,
786  ];
787  }
788 
795  public static function getPropertyNames( $filter = [] ) {
796  return array_keys( static::getPropertyMessages( $filter ) );
797  }
798 
805  public static function getPropertyMessages( $filter = [] ) {
806  return array_diff_key(
807  [
808  'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
809  'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
810  'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
811  'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
812  'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
813  'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
814  'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
815  'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
816  'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
817  'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
818  'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
819  'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
820  'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
821  'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
822  'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
823  'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
824  'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
825  'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
826  'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
827  'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
828  ],
829  array_fill_keys( $filter, true )
830  );
831  }
832 
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 
843  public function getHelpUrls() {
844  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
845  }
846 }
const NS_FILE
Definition: Defines.php:70
const PROTO_CURRENT
Definition: Defines.php:197
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:1458
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:506
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:1650
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition: ApiBase.php:196
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:221
getResult()
Get the result object.
Definition: ApiBase.php:629
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:765
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:163
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1376
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:223
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.
BadFileLookup $badFileLookup
__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:41
const META_TYPE
Key for the 'type' metadata item.
Definition: ApiResult.php:110
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
Definition: ApiResult.php:136
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:604
const DELETED_COMMENT
Definition: File.php:73
const DELETED_RESTRICTED
Definition: File.php:75
const RAW
Definition: File.php:90
const DELETED_FILE
Definition: File.php:72
const DELETED_USER
Definition: File.php:74
Format Image metadata values into a human readable form.
setSingleLanguage( $val)
Trigger only outputting single language for multilanguage fields.
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:789
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1402
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
static getExistsWarning( $exists)
Functions for formatting warnings.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:370
static getExistsWarning( $file)
Helper function that does various existence checks for a file.
Service for formatting and validating API parameters.
Type definition for integer types.
Definition: IntegerDef.php:23
$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