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