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 
42  private $contentLanguage;
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 || $badFileContextTitle->isExternal() ) {
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 (
365  isset( $paramList['width'] ) && isset( $thumbParams['width'] ) &&
366  (int)$paramList['width'] != (int)$thumbParams['width']
367  ) {
368  $this->addWarning(
369  [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
370  );
371  }
372 
373  foreach ( $paramList as $name => $value ) {
374  if ( !$h->validateParam( $name, $value ) ) {
375  $this->dieWithError(
376  [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
377  );
378  }
379  }
380 
381  $finalParams = $thumbParams + $paramList;
382  $this->checkParameterNormalise( $image, $finalParams );
383  return $finalParams;
384  }
385 
397  protected function checkParameterNormalise( $image, $finalParams ) {
398  $h = $image->getHandler();
399  if ( !$h ) {
400  return;
401  }
402  // Note: normaliseParams modifies the array in place, but we aren't interested
403  // in the actual normalised version, only if we can actually normalise them,
404  // so we use the functions scope to throw away the normalisations.
405  if ( !$h->normaliseParams( $image, $finalParams ) ) {
406  $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
407  }
408  }
409 
425  public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
426  $anyHidden = false;
427 
428  if ( !$opts || is_string( $opts ) ) {
429  $opts = [
430  'version' => $opts ?: 'latest',
431  'language' => MediaWikiServices::getInstance()->getContentLanguage(),
432  'multilang' => false,
433  'extmetadatafilter' => [],
434  'revdelUser' => null,
435  ];
436  }
437  $version = $opts['version'];
438  $vals = [
439  ApiResult::META_TYPE => 'assoc',
440  ];
441 
442  // Some information will be unavailable if the file does not exist. T221812
443  $exists = $file->exists();
444 
445  // Timestamp is shown even if the file is revdelete'd in interface
446  // so do same here.
447  if ( isset( $prop['timestamp'] ) && $exists ) {
448  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
449  }
450 
451  // Handle external callers who don't pass revdelUser
452  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
453  $revdelUser = $opts['revdelUser'];
454  $canShowField = static function ( $field ) use ( $file, $revdelUser ) {
455  return $file->userCan( $field, $revdelUser );
456  };
457  } else {
458  $canShowField = static function ( $field ) use ( $file ) {
459  return !$file->isDeleted( $field );
460  };
461  }
462 
463  $user = isset( $prop['user'] );
464  $userid = isset( $prop['userid'] );
465 
466  if ( ( $user || $userid ) && $exists ) {
467  if ( $file->isDeleted( File::DELETED_USER ) ) {
468  $vals['userhidden'] = true;
469  $anyHidden = true;
470  }
471  if ( $canShowField( File::DELETED_USER ) ) {
472  // Already checked if the field can be show
473  $uploader = $file->getUploader( File::RAW );
474  if ( $user ) {
475  $vals['user'] = $uploader ? $uploader->getName() : '';
476  }
477  if ( $userid ) {
478  $vals['userid'] = $uploader ? $uploader->getId() : 0;
479  }
480  if ( $uploader && !$uploader->isRegistered() ) {
481  $vals['anon'] = true;
482  }
483  }
484  }
485 
486  // This is shown even if the file is revdelete'd in interface
487  // so do same here.
488  if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
489  $vals['size'] = (int)$file->getSize();
490  $vals['width'] = (int)$file->getWidth();
491  $vals['height'] = (int)$file->getHeight();
492 
493  $pageCount = $file->pageCount();
494  if ( $pageCount !== false ) {
495  $vals['pagecount'] = $pageCount;
496  }
497 
498  // length as in how many seconds long a video is.
499  $length = $file->getLength();
500  if ( $length ) {
501  // Call it duration, because "length" can be ambiguous.
502  $vals['duration'] = (float)$length;
503  }
504  }
505 
506  $pcomment = isset( $prop['parsedcomment'] );
507  $comment = isset( $prop['comment'] );
508 
509  if ( ( $pcomment || $comment ) && $exists ) {
510  if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
511  $vals['commenthidden'] = true;
512  $anyHidden = true;
513  }
514  if ( $canShowField( File::DELETED_COMMENT ) ) {
515  if ( $pcomment ) {
516  $vals['parsedcomment'] = Linker::formatComment(
517  $file->getDescription( File::RAW ), $file->getTitle() );
518  }
519  if ( $comment ) {
520  $vals['comment'] = $file->getDescription( File::RAW );
521  }
522  }
523  }
524 
525  $canonicaltitle = isset( $prop['canonicaltitle'] );
526  $url = isset( $prop['url'] );
527  $sha1 = isset( $prop['sha1'] );
528  $meta = isset( $prop['metadata'] );
529  $extmetadata = isset( $prop['extmetadata'] );
530  $commonmeta = isset( $prop['commonmetadata'] );
531  $mime = isset( $prop['mime'] );
532  $mediatype = isset( $prop['mediatype'] );
533  $archive = isset( $prop['archivename'] );
534  $bitdepth = isset( $prop['bitdepth'] );
535  $uploadwarning = isset( $prop['uploadwarning'] );
536 
537  if ( $uploadwarning ) {
539  }
540 
541  if ( $file->isDeleted( File::DELETED_FILE ) ) {
542  $vals['filehidden'] = true;
543  $anyHidden = true;
544  }
545 
546  if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
547  $vals['suppressed'] = true;
548  }
549 
550  // Early return, tidier than indenting all following things one level
551  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser']
552  && !$file->userCan( File::DELETED_FILE, $opts['revdelUser'] )
553  ) {
554  return $vals;
555  } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
556  return $vals;
557  }
558 
559  if ( $canonicaltitle ) {
560  $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
561  }
562 
563  if ( $url ) {
564  if ( $exists ) {
565  if ( $thumbParams !== null ) {
566  $mto = $file->transform( $thumbParams );
567  self::$transformCount++;
568  if ( $mto && !$mto->isError() ) {
569  $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
570 
571  // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
572  // thumbnail sizes for the thumbnail actual size
573  if ( $mto->getUrl() !== $file->getUrl() ) {
574  $vals['thumbwidth'] = (int)$mto->getWidth();
575  $vals['thumbheight'] = (int)$mto->getHeight();
576  } else {
577  $vals['thumbwidth'] = (int)$file->getWidth();
578  $vals['thumbheight'] = (int)$file->getHeight();
579  }
580 
581  if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
582  list( , $mime ) = $file->getHandler()->getThumbType(
583  $mto->getExtension(), $file->getMimeType(), $thumbParams );
584  $vals['thumbmime'] = $mime;
585  }
586  // Report srcset parameters
588  'width' => $vals['thumbwidth'],
589  'height' => $vals['thumbheight']
590  ] + $thumbParams );
591  foreach ( $mto->responsiveUrls as $density => $url ) {
592  $vals['responsiveUrls'][$density] = wfExpandUrl( $url, PROTO_CURRENT );
593  }
594  } elseif ( $mto && $mto->isError() ) {
596  '@phan-var MediaTransformError $mto';
597  $vals['thumberror'] = $mto->toText();
598  }
599  }
600  $vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
601  }
602  $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
603 
604  $shortDescriptionUrl = $file->getDescriptionShortUrl();
605  if ( $shortDescriptionUrl !== null ) {
606  $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
607  }
608  }
609 
610  if ( !$exists ) {
611  $vals['filemissing'] = true;
612  }
613 
614  if ( $sha1 && $exists ) {
615  $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
616  }
617 
618  if ( $meta && $exists ) {
619  $metadata = $file->getMetadataArray();
620  if ( $metadata && $version !== 'latest' ) {
621  $metadata = $file->convertMetadataVersion( $metadata, $version );
622  }
623  $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
624  }
625  if ( $commonmeta && $exists ) {
626  $metaArray = $file->getCommonMetaArray();
627  $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
628  }
629 
630  if ( $extmetadata && $exists ) {
631  // Note, this should return an array where all the keys
632  // start with a letter, and all the values are strings.
633  // Thus there should be no issue with format=xml.
634  $format = new FormatMetadata;
635  $format->setSingleLanguage( !$opts['multilang'] );
636  // @phan-suppress-next-line PhanUndeclaredMethod
637  $format->getContext()->setLanguage( $opts['language'] );
638  $extmetaArray = $format->fetchExtendedMetadata( $file );
639  if ( $opts['extmetadatafilter'] ) {
640  $extmetaArray = array_intersect_key(
641  $extmetaArray, array_fill_keys( $opts['extmetadatafilter'], true )
642  );
643  }
644  $vals['extmetadata'] = $extmetaArray;
645  }
646 
647  if ( $mime && $exists ) {
648  $vals['mime'] = $file->getMimeType();
649  }
650 
651  if ( $mediatype && $exists ) {
652  $vals['mediatype'] = $file->getMediaType();
653  }
654 
655  if ( $archive && $file->isOld() ) {
657  '@phan-var OldLocalFile $file';
658  $vals['archivename'] = $file->getArchiveName();
659  }
660 
661  if ( $bitdepth && $exists ) {
662  $vals['bitdepth'] = $file->getBitDepth();
663  }
664 
665  return $vals;
666  }
667 
675  protected static function getTransformCount() {
676  return self::$transformCount;
677  }
678 
684  public static function processMetaData( $metadata, $result ) {
685  $retval = [];
686  if ( is_array( $metadata ) ) {
687  foreach ( $metadata as $key => $value ) {
688  $r = [
689  'name' => $key,
690  ApiResult::META_BC_BOOLS => [ 'value' ],
691  ];
692  if ( is_array( $value ) ) {
693  $r['value'] = static::processMetaData( $value, $result );
694  } else {
695  $r['value'] = $value;
696  }
697  $retval[] = $r;
698  }
699  }
700  ApiResult::setIndexedTagName( $retval, 'metadata' );
701 
702  return $retval;
703  }
704 
705  public function getCacheMode( $params ) {
706  if ( $this->userCanSeeRevDel() ) {
707  return 'private';
708  }
709 
710  return 'public';
711  }
712 
718  protected function getContinueStr( $img, $start = null ) {
719  if ( $start === null ) {
720  $start = $img->getTimestamp();
721  }
722 
723  return $img->getOriginalTitle()->getDBkey() . '|' . $start;
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: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:1453
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:1645
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:1371
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.
__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:791
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:1405
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