MediaWiki  master
ApiQueryImageInfo.php
Go to the documentation of this file.
1 <?php
24 
31  const TRANSFORM_LIMIT = 50;
32  private static $transformCount = 0;
33 
34  public function __construct( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
35  // We allow a subclass to override the prefix, to create a related API
36  // module. Some other parts of MediaWiki construct this with a null
37  // $prefix, which used to be ignored when this only took two arguments
38  if ( is_null( $prefix ) ) {
39  $prefix = 'ii';
40  }
41  parent::__construct( $query, $moduleName, $prefix );
42  }
43 
44  public function execute() {
45  $params = $this->extractRequestParams();
46 
47  $prop = array_flip( $params['prop'] );
48 
49  $scale = $this->getScale( $params );
50 
51  $opts = [
52  'version' => $params['metadataversion'],
53  'language' => $params['extmetadatalanguage'],
54  'multilang' => $params['extmetadatamultilang'],
55  'extmetadatafilter' => $params['extmetadatafilter'],
56  'revdelUser' => $this->getUser(),
57  ];
58 
59  if ( isset( $params['badfilecontexttitle'] ) ) {
60  $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
61  if ( !$badFileContextTitle ) {
62  $p = $this->getModulePrefix();
63  $this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
64  }
65  } else {
66  $badFileContextTitle = null;
67  }
68 
69  $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
70  if ( !empty( $pageIds[NS_FILE] ) ) {
71  $titles = array_keys( $pageIds[NS_FILE] );
72  asort( $titles ); // Ensure the order is always the same
73 
74  $fromTitle = null;
75  if ( !is_null( $params['continue'] ) ) {
76  $cont = explode( '|', $params['continue'] );
77  $this->dieContinueUsageIf( count( $cont ) != 2 );
78  $fromTitle = strval( $cont[0] );
79  $fromTimestamp = $cont[1];
80  // Filter out any titles before $fromTitle
81  foreach ( $titles as $key => $title ) {
82  if ( $title < $fromTitle ) {
83  unset( $titles[$key] );
84  } else {
85  break;
86  }
87  }
88  }
89 
90  $user = $this->getUser();
91  $findTitles = array_map( function ( $title ) use ( $user ) {
92  return [
93  'title' => $title,
94  'private' => $user,
95  ];
96  }, $titles );
97 
98  if ( $params['localonly'] ) {
99  $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
100  } else {
101  $images = RepoGroup::singleton()->findFiles( $findTitles );
102  }
103 
104  $result = $this->getResult();
105  foreach ( $titles as $title ) {
106  $info = [];
107  $pageId = $pageIds[NS_FILE][$title];
108  $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
109 
110  if ( !isset( $images[$title] ) ) {
111  if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
112  // uploadwarning and badfile need info about non-existing files
113  $images[$title] = MediaWikiServices::getInstance()->getRepoGroup()
114  ->getLocalRepo()->newFile( $title );
115  // Doesn't exist, so set an empty image repository
116  $info['imagerepository'] = '';
117  } else {
118  $result->addValue(
119  [ 'query', 'pages', (int)$pageId ],
120  'imagerepository', ''
121  );
122  // The above can't fail because it doesn't increase the result size
123  continue;
124  }
125  }
126 
128  $img = $images[$title];
129 
130  if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
131  if ( count( $pageIds[NS_FILE] ) == 1 ) {
132  // See the 'the user is screwed' comment below
133  $this->setContinueEnumParameter( 'start',
134  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
135  );
136  } else {
137  $this->setContinueEnumParameter( 'continue',
138  $this->getContinueStr( $img, $start ) );
139  }
140  break;
141  }
142 
143  if ( !isset( $info['imagerepository'] ) ) {
144  $info['imagerepository'] = $img->getRepoName();
145  }
146  if ( isset( $prop['badfile'] ) ) {
147  $info['badfile'] = (bool)MediaWikiServices::getInstance()->getBadFileLookup()
148  ->isBadFile( $title, $badFileContextTitle );
149  }
150 
151  $fit = $result->addValue( [ 'query', 'pages' ], (int)$pageId, $info );
152  if ( !$fit ) {
153  if ( count( $pageIds[NS_FILE] ) == 1 ) {
154  // The user is screwed. imageinfo can't be solely
155  // responsible for exceeding the limit in this case,
156  // so set a query-continue that just returns the same
157  // thing again. When the violating queries have been
158  // out-continued, the result will get through
159  $this->setContinueEnumParameter( 'start',
160  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
161  );
162  } else {
163  $this->setContinueEnumParameter( 'continue',
164  $this->getContinueStr( $img, $start ) );
165  }
166  break;
167  }
168 
169  // Check if we can make the requested thumbnail, and get transform parameters.
170  $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
171 
172  // Get information about the current version first
173  // Check that the current version is within the start-end boundaries
174  $gotOne = false;
175  if (
176  ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
177  ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
178  ) {
179  $gotOne = true;
180 
181  $fit = $this->addPageSubItem( $pageId,
182  static::getInfo( $img, $prop, $result,
183  $finalThumbParams, $opts
184  )
185  );
186  if ( !$fit ) {
187  if ( count( $pageIds[NS_FILE] ) == 1 ) {
188  // See the 'the user is screwed' comment above
189  $this->setContinueEnumParameter( 'start',
190  wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
191  } else {
192  $this->setContinueEnumParameter( 'continue',
193  $this->getContinueStr( $img ) );
194  }
195  break;
196  }
197  }
198 
199  // Now get the old revisions
200  // Get one more to facilitate query-continue functionality
201  $count = ( $gotOne ? 1 : 0 );
202  $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
204  foreach ( $oldies as $oldie ) {
205  if ( ++$count > $params['limit'] ) {
206  // We've reached the extra one which shows that there are
207  // additional pages to be had. Stop here...
208  // Only set a query-continue if there was only one title
209  if ( count( $pageIds[NS_FILE] ) == 1 ) {
210  $this->setContinueEnumParameter( 'start',
211  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
212  }
213  break;
214  }
215  $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
216  $this->addPageSubItem( $pageId,
217  static::getInfo( $oldie, $prop, $result,
218  $finalThumbParams, $opts
219  )
220  );
221  if ( !$fit ) {
222  if ( count( $pageIds[NS_FILE] ) == 1 ) {
223  $this->setContinueEnumParameter( 'start',
224  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
225  } else {
226  $this->setContinueEnumParameter( 'continue',
227  $this->getContinueStr( $oldie ) );
228  }
229  break;
230  }
231  }
232  if ( !$fit ) {
233  break;
234  }
235  }
236  }
237  }
238 
244  public function getScale( $params ) {
245  if ( $params['urlwidth'] != -1 ) {
246  $scale = [];
247  $scale['width'] = $params['urlwidth'];
248  $scale['height'] = $params['urlheight'];
249  } elseif ( $params['urlheight'] != -1 ) {
250  // Height is specified but width isn't
251  // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
252  $scale = [];
253  $scale['height'] = $params['urlheight'];
254  } elseif ( $params['urlparam'] ) {
255  // Audio files might not have a width/height.
256  $scale = [];
257  } else {
258  $scale = null;
259  }
260 
261  return $scale;
262  }
263 
273  protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
274  if ( $thumbParams === null ) {
275  // No scaling requested
276  return null;
277  }
278  if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
279  // We want to limit only by height in this situation, so pass the
280  // image's full width as the limiting width. But some file types
281  // don't have a width of their own, so pick something arbitrary so
282  // thumbnailing the default icon works.
283  if ( $image->getWidth() <= 0 ) {
284  $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
285  } else {
286  $thumbParams['width'] = $image->getWidth();
287  }
288  }
289 
290  if ( !$otherParams ) {
291  $this->checkParameterNormalise( $image, $thumbParams );
292  return $thumbParams;
293  }
294  $p = $this->getModulePrefix();
295 
296  $h = $image->getHandler();
297  if ( !$h ) {
298  $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
299 
300  return $thumbParams;
301  }
302 
303  $paramList = $h->parseParamString( $otherParams );
304  if ( !$paramList ) {
305  // Just set a warning (instead of dieWithError), as in many cases
306  // we could still render the image using width and height parameters,
307  // and this type of thing could happen between different versions of
308  // handlers.
309  $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
310  $this->checkParameterNormalise( $image, $thumbParams );
311  return $thumbParams;
312  }
313 
314  if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
315  if ( (int)$paramList['width'] != (int)$thumbParams['width'] ) {
316  $this->addWarning(
317  [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
318  );
319  }
320  }
321 
322  foreach ( $paramList as $name => $value ) {
323  if ( !$h->validateParam( $name, $value ) ) {
324  $this->dieWithError(
325  [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
326  );
327  }
328  }
329 
330  $finalParams = $thumbParams + $paramList;
331  $this->checkParameterNormalise( $image, $finalParams );
332  return $finalParams;
333  }
334 
346  protected function checkParameterNormalise( $image, $finalParams ) {
347  $h = $image->getHandler();
348  if ( !$h ) {
349  return;
350  }
351  // Note: normaliseParams modifies the array in place, but we aren't interested
352  // in the actual normalised version, only if we can actually normalise them,
353  // so we use the functions scope to throw away the normalisations.
354  if ( !$h->normaliseParams( $image, $finalParams ) ) {
355  $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
356  }
357  }
358 
374  public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
375  $anyHidden = false;
376 
377  if ( !$opts || is_string( $opts ) ) {
378  $opts = [
379  'version' => $opts ?: 'latest',
380  'language' => MediaWikiServices::getInstance()->getContentLanguage(),
381  'multilang' => false,
382  'extmetadatafilter' => [],
383  'revdelUser' => null,
384  ];
385  }
386  $version = $opts['version'];
387  $vals = [
388  ApiResult::META_TYPE => 'assoc',
389  ];
390 
391  // Some information will be unavailable if the file does not exist. T221812
392  $exists = $file->exists();
393 
394  // Timestamp is shown even if the file is revdelete'd in interface
395  // so do same here.
396  if ( isset( $prop['timestamp'] ) && $exists ) {
397  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
398  }
399 
400  // Handle external callers who don't pass revdelUser
401  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
402  $revdelUser = $opts['revdelUser'];
403  $canShowField = function ( $field ) use ( $file, $revdelUser ) {
404  return $file->userCan( $field, $revdelUser );
405  };
406  } else {
407  $canShowField = function ( $field ) use ( $file ) {
408  return !$file->isDeleted( $field );
409  };
410  }
411 
412  $user = isset( $prop['user'] );
413  $userid = isset( $prop['userid'] );
414 
415  if ( ( $user || $userid ) && $exists ) {
416  if ( $file->isDeleted( File::DELETED_USER ) ) {
417  $vals['userhidden'] = true;
418  $anyHidden = true;
419  }
420  if ( $canShowField( File::DELETED_USER ) ) {
421  if ( $user ) {
422  $vals['user'] = $file->getUser();
423  }
424  if ( $userid ) {
425  $vals['userid'] = $file->getUser( 'id' );
426  }
427  if ( !$file->getUser( 'id' ) ) {
428  $vals['anon'] = true;
429  }
430  }
431  }
432 
433  // This is shown even if the file is revdelete'd in interface
434  // so do same here.
435  if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
436  $vals['size'] = (int)$file->getSize();
437  $vals['width'] = (int)$file->getWidth();
438  $vals['height'] = (int)$file->getHeight();
439 
440  $pageCount = $file->pageCount();
441  if ( $pageCount !== false ) {
442  $vals['pagecount'] = $pageCount;
443  }
444 
445  // length as in how many seconds long a video is.
446  $length = $file->getLength();
447  if ( $length ) {
448  // Call it duration, because "length" can be ambiguous.
449  $vals['duration'] = (float)$length;
450  }
451  }
452 
453  $pcomment = isset( $prop['parsedcomment'] );
454  $comment = isset( $prop['comment'] );
455 
456  if ( ( $pcomment || $comment ) && $exists ) {
457  if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
458  $vals['commenthidden'] = true;
459  $anyHidden = true;
460  }
461  if ( $canShowField( File::DELETED_COMMENT ) ) {
462  if ( $pcomment ) {
463  $vals['parsedcomment'] = Linker::formatComment(
464  $file->getDescription( File::RAW ), $file->getTitle() );
465  }
466  if ( $comment ) {
467  $vals['comment'] = $file->getDescription( File::RAW );
468  }
469  }
470  }
471 
472  $canonicaltitle = isset( $prop['canonicaltitle'] );
473  $url = isset( $prop['url'] );
474  $sha1 = isset( $prop['sha1'] );
475  $meta = isset( $prop['metadata'] );
476  $extmetadata = isset( $prop['extmetadata'] );
477  $commonmeta = isset( $prop['commonmetadata'] );
478  $mime = isset( $prop['mime'] );
479  $mediatype = isset( $prop['mediatype'] );
480  $archive = isset( $prop['archivename'] );
481  $bitdepth = isset( $prop['bitdepth'] );
482  $uploadwarning = isset( $prop['uploadwarning'] );
483 
484  if ( $uploadwarning ) {
486  }
487 
488  if ( $file->isDeleted( File::DELETED_FILE ) ) {
489  $vals['filehidden'] = true;
490  $anyHidden = true;
491  }
492 
493  if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
494  $vals['suppressed'] = true;
495  }
496 
497  if ( !$canShowField( File::DELETED_FILE ) ) {
498  // Early return, tidier than indenting all following things one level
499  return $vals;
500  }
501 
502  if ( $canonicaltitle ) {
503  $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
504  }
505 
506  if ( $url ) {
507  if ( $exists ) {
508  if ( !is_null( $thumbParams ) ) {
509  $mto = $file->transform( $thumbParams );
510  self::$transformCount++;
511  if ( $mto && !$mto->isError() ) {
512  $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
513 
514  // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
515  // thumbnail sizes for the thumbnail actual size
516  if ( $mto->getUrl() !== $file->getUrl() ) {
517  $vals['thumbwidth'] = (int)$mto->getWidth();
518  $vals['thumbheight'] = (int)$mto->getHeight();
519  } else {
520  $vals['thumbwidth'] = (int)$file->getWidth();
521  $vals['thumbheight'] = (int)$file->getHeight();
522  }
523 
524  if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
525  list( , $mime ) = $file->getHandler()->getThumbType(
526  $mto->getExtension(), $file->getMimeType(), $thumbParams );
527  $vals['thumbmime'] = $mime;
528  }
529  } elseif ( $mto && $mto->isError() ) {
531  '@phan-var MediaTransformError $mto';
532  $vals['thumberror'] = $mto->toText();
533  }
534  }
535  $vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
536  }
537  $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
538 
539  $shortDescriptionUrl = $file->getDescriptionShortUrl();
540  if ( $shortDescriptionUrl !== null ) {
541  $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
542  }
543  }
544 
545  if ( !$exists ) {
546  $vals['filemissing'] = true;
547  }
548 
549  if ( $sha1 && $exists ) {
550  $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
551  }
552 
553  if ( $meta && $exists ) {
554  Wikimedia\suppressWarnings();
555  $metadata = unserialize( $file->getMetadata() );
556  Wikimedia\restoreWarnings();
557  if ( $metadata && $version !== 'latest' ) {
558  $metadata = $file->convertMetadataVersion( $metadata, $version );
559  }
560  $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
561  }
562  if ( $commonmeta && $exists ) {
563  $metaArray = $file->getCommonMetaArray();
564  $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
565  }
566 
567  if ( $extmetadata && $exists ) {
568  // Note, this should return an array where all the keys
569  // start with a letter, and all the values are strings.
570  // Thus there should be no issue with format=xml.
571  $format = new FormatMetadata;
572  $format->setSingleLanguage( !$opts['multilang'] );
573  // @phan-suppress-next-line PhanUndeclaredMethod
574  $format->getContext()->setLanguage( $opts['language'] );
575  $extmetaArray = $format->fetchExtendedMetadata( $file );
576  if ( $opts['extmetadatafilter'] ) {
577  $extmetaArray = array_intersect_key(
578  $extmetaArray, array_flip( $opts['extmetadatafilter'] )
579  );
580  }
581  $vals['extmetadata'] = $extmetaArray;
582  }
583 
584  if ( $mime && $exists ) {
585  $vals['mime'] = $file->getMimeType();
586  }
587 
588  if ( $mediatype && $exists ) {
589  $vals['mediatype'] = $file->getMediaType();
590  }
591 
592  if ( $archive && $file->isOld() ) {
594  '@phan-var OldLocalFile $file';
595  $vals['archivename'] = $file->getArchiveName();
596  }
597 
598  if ( $bitdepth && $exists ) {
599  $vals['bitdepth'] = $file->getBitDepth();
600  }
601 
602  return $vals;
603  }
604 
612  static function getTransformCount() {
613  return self::$transformCount;
614  }
615 
622  public static function processMetaData( $metadata, $result ) {
623  $retval = [];
624  if ( is_array( $metadata ) ) {
625  foreach ( $metadata as $key => $value ) {
626  $r = [
627  'name' => $key,
628  ApiResult::META_BC_BOOLS => [ 'value' ],
629  ];
630  if ( is_array( $value ) ) {
631  $r['value'] = static::processMetaData( $value, $result );
632  } else {
633  $r['value'] = $value;
634  }
635  $retval[] = $r;
636  }
637  }
638  ApiResult::setIndexedTagName( $retval, 'metadata' );
639 
640  return $retval;
641  }
642 
643  public function getCacheMode( $params ) {
644  if ( $this->userCanSeeRevDel() ) {
645  return 'private';
646  }
647 
648  return 'public';
649  }
650 
656  protected function getContinueStr( $img, $start = null ) {
657  if ( $start === null ) {
658  $start = $img->getTimestamp();
659  }
660 
661  return $img->getOriginalTitle()->getDBkey() . '|' . $start;
662  }
663 
664  public function getAllowedParams() {
665  return [
666  'prop' => [
667  ApiBase::PARAM_ISMULTI => true,
668  ApiBase::PARAM_DFLT => 'timestamp|user',
669  ApiBase::PARAM_TYPE => static::getPropertyNames(),
670  ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
671  ],
672  'limit' => [
673  ApiBase::PARAM_TYPE => 'limit',
674  ApiBase::PARAM_DFLT => 1,
675  ApiBase::PARAM_MIN => 1,
678  ],
679  'start' => [
680  ApiBase::PARAM_TYPE => 'timestamp'
681  ],
682  'end' => [
683  ApiBase::PARAM_TYPE => 'timestamp'
684  ],
685  'urlwidth' => [
686  ApiBase::PARAM_TYPE => 'integer',
687  ApiBase::PARAM_DFLT => -1,
689  'apihelp-query+imageinfo-param-urlwidth',
690  self::TRANSFORM_LIMIT,
691  ],
692  ],
693  'urlheight' => [
694  ApiBase::PARAM_TYPE => 'integer',
695  ApiBase::PARAM_DFLT => -1
696  ],
697  'metadataversion' => [
698  ApiBase::PARAM_TYPE => 'string',
699  ApiBase::PARAM_DFLT => '1',
700  ],
701  'extmetadatalanguage' => [
702  ApiBase::PARAM_TYPE => 'string',
704  MediaWikiServices::getInstance()->getContentLanguage()->getCode(),
705  ],
706  'extmetadatamultilang' => [
707  ApiBase::PARAM_TYPE => 'boolean',
708  ApiBase::PARAM_DFLT => false,
709  ],
710  'extmetadatafilter' => [
711  ApiBase::PARAM_TYPE => 'string',
712  ApiBase::PARAM_ISMULTI => true,
713  ],
714  'urlparam' => [
715  ApiBase::PARAM_DFLT => '',
716  ApiBase::PARAM_TYPE => 'string',
717  ],
718  'badfilecontexttitle' => [
719  ApiBase::PARAM_TYPE => 'string',
720  ],
721  'continue' => [
722  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
723  ],
724  'localonly' => false,
725  ];
726  }
727 
734  public static function getPropertyNames( $filter = [] ) {
735  return array_keys( static::getPropertyMessages( $filter ) );
736  }
737 
744  public static function getPropertyMessages( $filter = [] ) {
745  return array_diff_key(
746  [
747  'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
748  'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
749  'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
750  'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
751  'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
752  'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
753  'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
754  'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
755  'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
756  'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
757  'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
758  'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
759  'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
760  'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
761  'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
762  'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
763  'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
764  'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
765  'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
766  'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
767  ],
768  array_flip( $filter )
769  );
770  }
771 
772  protected function getExamplesMessages() {
773  return [
774  'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
775  => 'apihelp-query+imageinfo-example-simple',
776  'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
777  'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
778  => 'apihelp-query+imageinfo-example-dated',
779  ];
780  }
781 
782  public function getHelpUrls() {
783  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
784  }
785 }
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:94
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:261
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
const DELETED_COMMENT
Definition: File.php:64
getResult()
Get the result object.
Definition: ApiBase.php:640
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
Format Image metadata values into a human readable form.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:259
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:97
This is a base class for all Query modules.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:2005
const PROTO_CURRENT
Definition: Defines.php:202
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:761
const META_TYPE
Key for the &#39;type&#39; metadata item.
Definition: ApiResult.php:110
getPageSet()
Get the PageSet object to work on.
static getExistsWarning( $file)
Helper function that does various existence checks for a file.
__construct(ApiQuery $query, $moduleName, $prefix='ii')
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:164
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
const DELETED_FILE
Definition: File.php:63
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
checkParameterNormalise( $image, $finalParams)
Verify that the final image parameters can be normalised.
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:1165
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
static processMetaData( $metadata, $result)
static singleton()
Definition: RepoGroup.php:60
dieContinueUsageIf( $condition)
Die with the &#39;badcontinue&#39; error.
Definition: ApiBase.php:2199
static getTransformCount()
Get the count of image transformations performed.
unserialize( $serialized)
$filter
A query action to get image information and upload history.
const NS_FILE
Definition: Defines.php:66
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE &#39;limit&#39;.
Definition: ApiBase.php:103
This is the main query class.
Definition: ApiQuery.php:37
setSingleLanguage( $val)
Trigger only outputting single language for multilanguage fields.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:131
const DELETED_USER
Definition: File.php:65
const DELETED_RESTRICTED
Definition: File.php:66
static getExistsWarning( $exists)
Functions for formatting warnings.
getScale( $params)
From parameters, construct a &#39;scale&#39; array.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:528
const RAW
Definition: File.php:81
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1924
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
const META_BC_BOOLS
Key for the &#39;BC bools&#39; metadata item.
Definition: ApiResult.php:136
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
getContinueStr( $img, $start=null)
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE &#39;integer&#39; and &#39;limit&#39;.
Definition: ApiBase.php:106
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.