MediaWiki  master
ApiQueryImageInfo.php
Go to the documentation of this file.
1 <?php
25 
32  public const TRANSFORM_LIMIT = 50;
33  private static $transformCount = 0;
34 
36  private $repoGroup;
37 
40 
42  private $badFileLookup;
43 
52  public function __construct(
53  ApiQuery $query,
54  $moduleName,
55  $prefixOrRepoGroup = null,
56  $repoGroupOrContentLanguage = null,
57  $contentLanguageOrBadFileLookup = null,
58  $badFileLookupOrUnused = null
59  ) {
60  // We allow a subclass to override the prefix, to create a related API module.
61  // The ObjectFactory is injecting the services without the prefix.
62  if ( !is_string( $prefixOrRepoGroup ) ) {
63  $prefix = 'ii';
64  $repoGroup = $prefixOrRepoGroup;
65  $contentLanguage = $repoGroupOrContentLanguage;
66  $badFileLookup = $contentLanguageOrBadFileLookup;
67  // $badFileLookupOrUnused is null in this case
68  } else {
69  $prefix = $prefixOrRepoGroup;
70  $repoGroup = $repoGroupOrContentLanguage;
71  $contentLanguage = $contentLanguageOrBadFileLookup;
72  $badFileLookup = $badFileLookupOrUnused;
73  }
74  parent::__construct( $query, $moduleName, $prefix );
75  // This class is extended and therefor fallback to global state - T259960
76  $services = MediaWikiServices::getInstance();
77  $this->repoGroup = $repoGroup ?? $services->getRepoGroup();
78  $this->contentLanguage = $contentLanguage ?? $services->getContentLanguage();
79  $this->badFileLookup = $badFileLookup ?? $services->getBadFileLookup();
80  }
81 
82  public function execute() {
83  $params = $this->extractRequestParams();
84 
85  $prop = array_fill_keys( $params['prop'], true );
86 
87  $scale = $this->getScale( $params );
88 
89  $opts = [
90  'version' => $params['metadataversion'],
91  'language' => $params['extmetadatalanguage'],
92  'multilang' => $params['extmetadatamultilang'],
93  'extmetadatafilter' => $params['extmetadatafilter'],
94  'revdelUser' => $this->getAuthority(),
95  ];
96 
97  if ( isset( $params['badfilecontexttitle'] ) ) {
98  $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
99  if ( !$badFileContextTitle ) {
100  $p = $this->getModulePrefix();
101  $this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
102  }
103  } else {
104  $badFileContextTitle = null;
105  }
106 
107  $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
108  if ( !empty( $pageIds[NS_FILE] ) ) {
109  $titles = array_keys( $pageIds[NS_FILE] );
110  asort( $titles ); // Ensure the order is always the same
111 
112  $fromTitle = null;
113  if ( $params['continue'] !== null ) {
114  $cont = explode( '|', $params['continue'] );
115  $this->dieContinueUsageIf( count( $cont ) != 2 );
116  $fromTitle = strval( $cont[0] );
117  $fromTimestamp = $cont[1];
118  // Filter out any titles before $fromTitle
119  foreach ( $titles as $key => $title ) {
120  if ( $title < $fromTitle ) {
121  unset( $titles[$key] );
122  } else {
123  break;
124  }
125  }
126  }
127 
128  $performer = $this->getAuthority();
129  $findTitles = array_map( static function ( $title ) use ( $performer ) {
130  return [
131  'title' => $title,
132  'private' => $performer,
133  ];
134  }, $titles );
135 
136  if ( $params['localonly'] ) {
137  $images = $this->repoGroup->getLocalRepo()->findFiles( $findTitles );
138  } else {
139  $images = $this->repoGroup->findFiles( $findTitles );
140  }
141 
142  $result = $this->getResult();
143  foreach ( $titles as $title ) {
144  $info = [];
145  $pageId = $pageIds[NS_FILE][$title];
146  $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
147 
148  if ( !isset( $images[$title] ) ) {
149  if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
150  // uploadwarning and badfile need info about non-existing files
151  $images[$title] = $this->repoGroup->getLocalRepo()->newFile( $title );
152  // Doesn't exist, so set an empty image repository
153  $info['imagerepository'] = '';
154  } else {
155  $result->addValue(
156  [ 'query', 'pages', (int)$pageId ],
157  'imagerepository', ''
158  );
159  // The above can't fail because it doesn't increase the result size
160  continue;
161  }
162  }
163 
165  $img = $images[$title];
166 
167  if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
168  if ( count( $pageIds[NS_FILE] ) == 1 ) {
169  // See the 'the user is screwed' comment below
170  $this->setContinueEnumParameter( 'start',
171  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
172  );
173  } else {
174  $this->setContinueEnumParameter( 'continue',
175  $this->getContinueStr( $img, $start ) );
176  }
177  break;
178  }
179 
180  if ( !isset( $info['imagerepository'] ) ) {
181  $info['imagerepository'] = $img->getRepoName();
182  }
183  if ( isset( $prop['badfile'] ) ) {
184  $info['badfile'] = (bool)$this->badFileLookup->isBadFile( $title, $badFileContextTitle );
185  }
186 
187  $fit = $result->addValue( [ 'query', 'pages' ], (int)$pageId, $info );
188  if ( !$fit ) {
189  if ( count( $pageIds[NS_FILE] ) == 1 ) {
190  // The user is screwed. imageinfo can't be solely
191  // responsible for exceeding the limit in this case,
192  // so set a query-continue that just returns the same
193  // thing again. When the violating queries have been
194  // out-continued, the result will get through
195  $this->setContinueEnumParameter( 'start',
196  $start ?? wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
197  );
198  } else {
199  $this->setContinueEnumParameter( 'continue',
200  $this->getContinueStr( $img, $start ) );
201  }
202  break;
203  }
204 
205  // Check if we can make the requested thumbnail, and get transform parameters.
206  $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
207 
208  // Get information about the current version first
209  // Check that the current version is within the start-end boundaries
210  $gotOne = false;
211  if (
212  ( $start === null || $img->getTimestamp() <= $start ) &&
213  ( $params['end'] === null || $img->getTimestamp() >= $params['end'] )
214  ) {
215  $gotOne = true;
216 
217  $fit = $this->addPageSubItem( $pageId,
218  static::getInfo( $img, $prop, $result,
219  $finalThumbParams, $opts
220  )
221  );
222  if ( !$fit ) {
223  if ( count( $pageIds[NS_FILE] ) == 1 ) {
224  // See the 'the user is screwed' comment above
225  $this->setContinueEnumParameter( 'start',
226  wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
227  } else {
228  $this->setContinueEnumParameter( 'continue',
229  $this->getContinueStr( $img ) );
230  }
231  break;
232  }
233  }
234 
235  // Now get the old revisions
236  // Get one more to facilitate query-continue functionality
237  $count = ( $gotOne ? 1 : 0 );
238  $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
240  foreach ( $oldies as $oldie ) {
241  if ( ++$count > $params['limit'] ) {
242  // We've reached the extra one which shows that there are
243  // additional pages to be had. Stop here...
244  // Only set a query-continue if there was only one title
245  if ( count( $pageIds[NS_FILE] ) == 1 ) {
246  $this->setContinueEnumParameter( 'start',
247  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
248  }
249  break;
250  }
251  $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
252  $this->addPageSubItem( $pageId,
253  static::getInfo( $oldie, $prop, $result,
254  $finalThumbParams, $opts
255  )
256  );
257  if ( !$fit ) {
258  if ( count( $pageIds[NS_FILE] ) == 1 ) {
259  $this->setContinueEnumParameter( 'start',
260  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
261  } else {
262  $this->setContinueEnumParameter( 'continue',
263  $this->getContinueStr( $oldie ) );
264  }
265  break;
266  }
267  }
268  if ( !$fit ) {
269  break;
270  }
271  }
272  }
273  }
274 
280  public function getScale( $params ) {
281  if ( $params['urlwidth'] != -1 ) {
282  $scale = [];
283  $scale['width'] = $params['urlwidth'];
284  $scale['height'] = $params['urlheight'];
285  } elseif ( $params['urlheight'] != -1 ) {
286  // Height is specified but width isn't
287  // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
288  $scale = [];
289  $scale['height'] = $params['urlheight'];
290  } elseif ( $params['urlparam'] ) {
291  // Audio files might not have a width/height.
292  $scale = [];
293  } else {
294  $scale = null;
295  }
296 
297  return $scale;
298  }
299 
309  protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
310  if ( $thumbParams === null ) {
311  // No scaling requested
312  return null;
313  }
314  if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
315  // We want to limit only by height in this situation, so pass the
316  // image's full width as the limiting width. But some file types
317  // don't have a width of their own, so pick something arbitrary so
318  // thumbnailing the default icon works.
319  if ( $image->getWidth() <= 0 ) {
320  $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
321  } else {
322  $thumbParams['width'] = $image->getWidth();
323  }
324  }
325 
326  if ( !$otherParams ) {
327  $this->checkParameterNormalise( $image, $thumbParams );
328  return $thumbParams;
329  }
330  $p = $this->getModulePrefix();
331 
332  $h = $image->getHandler();
333  if ( !$h ) {
334  $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
335 
336  return $thumbParams;
337  }
338 
339  $paramList = $h->parseParamString( $otherParams );
340  if ( !$paramList ) {
341  // Just set a warning (instead of dieWithError), as in many cases
342  // we could still render the image using width and height parameters,
343  // and this type of thing could happen between different versions of
344  // handlers.
345  $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
346  $this->checkParameterNormalise( $image, $thumbParams );
347  return $thumbParams;
348  }
349 
350  if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
351  if ( (int)$paramList['width'] != (int)$thumbParams['width'] ) {
352  $this->addWarning(
353  [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
354  );
355  }
356  }
357 
358  foreach ( $paramList as $name => $value ) {
359  if ( !$h->validateParam( $name, $value ) ) {
360  $this->dieWithError(
361  [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
362  );
363  }
364  }
365 
366  $finalParams = $thumbParams + $paramList;
367  $this->checkParameterNormalise( $image, $finalParams );
368  return $finalParams;
369  }
370 
382  protected function checkParameterNormalise( $image, $finalParams ) {
383  $h = $image->getHandler();
384  if ( !$h ) {
385  return;
386  }
387  // Note: normaliseParams modifies the array in place, but we aren't interested
388  // in the actual normalised version, only if we can actually normalise them,
389  // so we use the functions scope to throw away the normalisations.
390  if ( !$h->normaliseParams( $image, $finalParams ) ) {
391  $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
392  }
393  }
394 
410  public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
411  $anyHidden = false;
412 
413  if ( !$opts || is_string( $opts ) ) {
414  $opts = [
415  'version' => $opts ?: 'latest',
416  'language' => MediaWikiServices::getInstance()->getContentLanguage(),
417  'multilang' => false,
418  'extmetadatafilter' => [],
419  'revdelUser' => null,
420  ];
421  }
422  $version = $opts['version'];
423  $vals = [
424  ApiResult::META_TYPE => 'assoc',
425  ];
426 
427  // Some information will be unavailable if the file does not exist. T221812
428  $exists = $file->exists();
429 
430  // Timestamp is shown even if the file is revdelete'd in interface
431  // so do same here.
432  if ( isset( $prop['timestamp'] ) && $exists ) {
433  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
434  }
435 
436  $user = isset( $prop['user'] );
437  $userid = isset( $prop['userid'] );
438 
439  if ( ( $user || $userid ) && $exists ) {
440  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
441  $uploader = $file->getUploader( File::FOR_THIS_USER, $opts['revdelUser'] );
442  } else {
443  $uploader = $file->getUploader( File::FOR_PUBLIC );
444  }
445  if ( $uploader ) {
446  if ( $user ) {
447  $vals['user'] = $uploader->getName();
448  }
449  if ( $userid ) {
450  $vals['userid'] = $uploader->getId();
451  }
452  if ( !$uploader->isRegistered() ) {
453  $vals['anon'] = true;
454  }
455  } else {
456  $vals['userhidden'] = true;
457  $anyHidden = true;
458  }
459  }
460 
461  // This is shown even if the file is revdelete'd in interface
462  // so do same here.
463  if ( ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) && $exists ) {
464  $vals['size'] = (int)$file->getSize();
465  $vals['width'] = (int)$file->getWidth();
466  $vals['height'] = (int)$file->getHeight();
467 
468  $pageCount = $file->pageCount();
469  if ( $pageCount !== false ) {
470  $vals['pagecount'] = $pageCount;
471  }
472 
473  // length as in how many seconds long a video is.
474  $length = $file->getLength();
475  if ( $length ) {
476  // Call it duration, because "length" can be ambiguous.
477  $vals['duration'] = (float)$length;
478  }
479  }
480 
481  $pcomment = isset( $prop['parsedcomment'] );
482  $comment = isset( $prop['comment'] );
483 
484  if ( ( $pcomment || $comment ) && $exists ) {
485  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
486  $description = $file->getDescription( File::FOR_THIS_USER, $opts['revdelUser'] );
487  } else {
488  $description = $file->getDescription( File::FOR_PUBLIC );
489  }
490  if ( $description ) {
491  if ( $pcomment ) {
492  $vals['parsedcomment'] = Linker::formatComment( $description, $file->getTitle() );
493  }
494  if ( $comment ) {
495  $vals['comment'] = $description;
496  }
497  } else {
498  $vals['commenthidden'] = true;
499  $anyHidden = true;
500  }
501  }
502 
503  $canonicaltitle = isset( $prop['canonicaltitle'] );
504  $url = isset( $prop['url'] );
505  $sha1 = isset( $prop['sha1'] );
506  $meta = isset( $prop['metadata'] );
507  $extmetadata = isset( $prop['extmetadata'] );
508  $commonmeta = isset( $prop['commonmetadata'] );
509  $mime = isset( $prop['mime'] );
510  $mediatype = isset( $prop['mediatype'] );
511  $archive = isset( $prop['archivename'] );
512  $bitdepth = isset( $prop['bitdepth'] );
513  $uploadwarning = isset( $prop['uploadwarning'] );
514 
515  if ( $uploadwarning ) {
517  }
518 
519  if ( $file->isDeleted( File::DELETED_FILE ) ) {
520  $vals['filehidden'] = true;
521  $anyHidden = true;
522  }
523 
524  if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
525  $vals['suppressed'] = true;
526  }
527 
528  // Early return, tidier than indenting all following things one level
529  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser']
530  && !$file->userCan( File::DELETED_FILE, $opts['revdelUser'] )
531  ) {
532  return $vals;
533  } elseif ( $file->isDeleted( File::DELETED_FILE ) ) {
534  return $vals;
535  }
536 
537  if ( $canonicaltitle ) {
538  $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
539  }
540 
541  if ( $url ) {
542  if ( $exists ) {
543  if ( $thumbParams !== null ) {
544  $mto = $file->transform( $thumbParams );
545  self::$transformCount++;
546  if ( $mto && !$mto->isError() ) {
547  $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
548 
549  // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
550  // thumbnail sizes for the thumbnail actual size
551  if ( $mto->getUrl() !== $file->getUrl() ) {
552  $vals['thumbwidth'] = (int)$mto->getWidth();
553  $vals['thumbheight'] = (int)$mto->getHeight();
554  } else {
555  $vals['thumbwidth'] = (int)$file->getWidth();
556  $vals['thumbheight'] = (int)$file->getHeight();
557  }
558 
559  if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
560  list( , $mime ) = $file->getHandler()->getThumbType(
561  $mto->getExtension(), $file->getMimeType(), $thumbParams );
562  $vals['thumbmime'] = $mime;
563  }
564  // Report srcset parameters
566  'width' => $vals['thumbwidth'],
567  'height' => $vals['thumbheight']
568  ] + $thumbParams );
569  foreach ( $mto->responsiveUrls as $density => $url ) {
570  $vals['responsiveUrls'][$density] = wfExpandUrl( $url, PROTO_CURRENT );
571  }
572  } elseif ( $mto && $mto->isError() ) {
574  '@phan-var MediaTransformError $mto';
575  $vals['thumberror'] = $mto->toText();
576  }
577  }
578  $vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
579  }
580  $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
581 
582  $shortDescriptionUrl = $file->getDescriptionShortUrl();
583  if ( $shortDescriptionUrl !== null ) {
584  $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
585  }
586  }
587 
588  if ( !$exists ) {
589  $vals['filemissing'] = true;
590  }
591 
592  if ( $sha1 && $exists ) {
593  $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
594  }
595 
596  if ( $meta && $exists ) {
597  $metadata = $file->getMetadataArray();
598  if ( $metadata && $version !== 'latest' ) {
599  $metadata = $file->convertMetadataVersion( $metadata, $version );
600  }
601  $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
602  }
603  if ( $commonmeta && $exists ) {
604  $metaArray = $file->getCommonMetaArray();
605  $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
606  }
607 
608  if ( $extmetadata && $exists ) {
609  // Note, this should return an array where all the keys
610  // start with a letter, and all the values are strings.
611  // Thus there should be no issue with format=xml.
612  $format = new FormatMetadata;
613  $format->setSingleLanguage( !$opts['multilang'] );
614  // @phan-suppress-next-line PhanUndeclaredMethod
615  $format->getContext()->setLanguage( $opts['language'] );
616  $extmetaArray = $format->fetchExtendedMetadata( $file );
617  if ( $opts['extmetadatafilter'] ) {
618  $extmetaArray = array_intersect_key(
619  $extmetaArray, array_fill_keys( $opts['extmetadatafilter'], true )
620  );
621  }
622  $vals['extmetadata'] = $extmetaArray;
623  }
624 
625  if ( $mime && $exists ) {
626  $vals['mime'] = $file->getMimeType();
627  }
628 
629  if ( $mediatype && $exists ) {
630  $vals['mediatype'] = $file->getMediaType();
631  }
632 
633  if ( $archive && $file->isOld() ) {
635  '@phan-var OldLocalFile $file';
636  $vals['archivename'] = $file->getArchiveName();
637  }
638 
639  if ( $bitdepth && $exists ) {
640  $vals['bitdepth'] = $file->getBitDepth();
641  }
642 
643  return $vals;
644  }
645 
653  protected static function getTransformCount() {
654  return self::$transformCount;
655  }
656 
662  public static function processMetaData( $metadata, $result ) {
663  $retval = [];
664  if ( is_array( $metadata ) ) {
665  foreach ( $metadata as $key => $value ) {
666  $r = [
667  'name' => $key,
668  ApiResult::META_BC_BOOLS => [ 'value' ],
669  ];
670  if ( is_array( $value ) ) {
671  $r['value'] = static::processMetaData( $value, $result );
672  } else {
673  $r['value'] = $value;
674  }
675  $retval[] = $r;
676  }
677  }
678  ApiResult::setIndexedTagName( $retval, 'metadata' );
679 
680  return $retval;
681  }
682 
683  public function getCacheMode( $params ) {
684  if ( $this->userCanSeeRevDel() ) {
685  return 'private';
686  }
687 
688  return 'public';
689  }
690 
696  protected function getContinueStr( $img, $start = null ) {
697  if ( $start === null ) {
698  $start = $img->getTimestamp();
699  }
700 
701  return $img->getOriginalTitle()->getDBkey() . '|' . $start;
702  }
703 
704  public function getAllowedParams() {
705  return [
706  'prop' => [
707  ApiBase::PARAM_ISMULTI => true,
708  ApiBase::PARAM_DFLT => 'timestamp|user',
709  ApiBase::PARAM_TYPE => static::getPropertyNames(),
710  ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
711  ],
712  'limit' => [
713  ApiBase::PARAM_TYPE => 'limit',
714  ApiBase::PARAM_DFLT => 1,
715  ApiBase::PARAM_MIN => 1,
718  ],
719  'start' => [
720  ApiBase::PARAM_TYPE => 'timestamp'
721  ],
722  'end' => [
723  ApiBase::PARAM_TYPE => 'timestamp'
724  ],
725  'urlwidth' => [
726  ApiBase::PARAM_TYPE => 'integer',
727  ApiBase::PARAM_DFLT => -1,
729  'apihelp-query+imageinfo-param-urlwidth',
731  ],
732  ],
733  'urlheight' => [
734  ApiBase::PARAM_TYPE => 'integer',
735  ApiBase::PARAM_DFLT => -1
736  ],
737  'metadataversion' => [
738  ApiBase::PARAM_TYPE => 'string',
739  ApiBase::PARAM_DFLT => '1',
740  ],
741  'extmetadatalanguage' => [
742  ApiBase::PARAM_TYPE => 'string',
744  $this->contentLanguage->getCode(),
745  ],
746  'extmetadatamultilang' => [
747  ApiBase::PARAM_TYPE => 'boolean',
748  ApiBase::PARAM_DFLT => false,
749  ],
750  'extmetadatafilter' => [
751  ApiBase::PARAM_TYPE => 'string',
752  ApiBase::PARAM_ISMULTI => true,
753  ],
754  'urlparam' => [
755  ApiBase::PARAM_DFLT => '',
756  ApiBase::PARAM_TYPE => 'string',
757  ],
758  'badfilecontexttitle' => [
759  ApiBase::PARAM_TYPE => 'string',
760  ],
761  'continue' => [
762  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
763  ],
764  'localonly' => false,
765  ];
766  }
767 
774  public static function getPropertyNames( $filter = [] ) {
775  return array_keys( static::getPropertyMessages( $filter ) );
776  }
777 
784  public static function getPropertyMessages( $filter = [] ) {
785  return array_diff_key(
786  [
787  'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
788  'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
789  'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
790  'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
791  'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
792  'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
793  'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
794  'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
795  'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
796  'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
797  'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
798  'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
799  'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
800  'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
801  'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
802  'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
803  'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
804  'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
805  'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
806  'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
807  ],
808  array_fill_keys( $filter, true )
809  );
810  }
811 
812  protected function getExamplesMessages() {
813  return [
814  'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
815  => 'apihelp-query+imageinfo-example-simple',
816  'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
817  'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
818  => 'apihelp-query+imageinfo-example-dated',
819  ];
820  }
821 
822  public function getHelpUrls() {
823  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
824  }
825 }
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:72
ApiQueryImageInfo\getPropertyNames
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
Definition: ApiQueryImageInfo.php:774
ApiQueryImageInfo\getContinueStr
getContinueStr( $img, $start=null)
Definition: ApiQueryImageInfo.php:696
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:383
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:1297
ApiQueryImageInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryImageInfo.php:812
ApiQueryImageInfo\$contentLanguage
Language $contentLanguage
Definition: ApiQueryImageInfo.php:39
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:73
ApiQueryImageInfo\mergeThumbParams
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
Definition: ApiQueryImageInfo.php:309
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
MediaWiki\BadFileLookup
Definition: BadFileLookup.php:13
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:1379
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:105
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1668
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:72
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:571
ApiQueryImageInfo\$transformCount
static $transformCount
Definition: ApiQueryImageInfo.php:33
$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:792
ApiQueryImageInfo
A query action to get image information and upload history.
Definition: ApiQueryImageInfo.php:31
ApiQueryImageInfo\getInfo
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
Definition: ApiQueryImageInfo.php:410
ApiQueryImageInfo\__construct
__construct(ApiQuery $query, $moduleName, $prefixOrRepoGroup=null, $repoGroupOrContentLanguage=null, $contentLanguageOrBadFileLookup=null, $badFileLookupOrUnused=null)
Definition: ApiQueryImageInfo.php:52
File\FOR_PUBLIC
const FOR_PUBLIC
Definition: File.php:86
SpecialUpload\getExistsWarning
static getExistsWarning( $exists)
Functions for formatting warnings.
Definition: SpecialUpload.php:839
FormatMetadata\setSingleLanguage
setSingleLanguage( $val)
Trigger only outputting single language for multilanguage fields.
Definition: FormatMetadata.php:70
ApiQueryImageInfo\getTransformCount
static getTransformCount()
Get the count of image transformations performed.
Definition: ApiQueryImageInfo.php:653
ApiQueryImageInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryImageInfo.php:82
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:75
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:66
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:163
ApiQueryImageInfo\checkParameterNormalise
checkParameterNormalise( $image, $finalParams)
Verify that the final image parameters can be normalised.
Definition: ApiQueryImageInfo.php:382
ApiQueryImageInfo\$repoGroup
RepoGroup $repoGroup
Definition: ApiQueryImageInfo.php:36
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:73
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:707
$title
$title
Definition: testCompression.php:38
ApiQueryImageInfo\processMetaData
static processMetaData( $metadata, $result)
Definition: ApiQueryImageInfo.php:662
File\FOR_THIS_USER
const FOR_THIS_USER
Definition: File.php:87
ApiQueryImageInfo\$badFileLookup
BadFileLookup $badFileLookup
Definition: ApiQueryImageInfo.php:42
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:448
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:195
ApiQueryImageInfo\TRANSFORM_LIMIT
const TRANSFORM_LIMIT
Definition: ApiQueryImageInfo.php:32
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:603
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:1569
ContextSource\getAuthority
getAuthority()
Definition: ContextSource.php:144
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1459
UploadBase\getExistsWarning
static getExistsWarning( $file)
Helper function that does various existence checks for a file.
Definition: UploadBase.php:2033
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:143
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:1372
FormatMetadata
Format Image metadata values into a human readable form.
Definition: FormatMetadata.php:54
ApiQueryImageInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryImageInfo.php:704
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:165
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:70
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:71
RepoGroup
Prioritized list of file repositories.
Definition: RepoGroup.php:32
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:74
ApiQueryImageInfo\getScale
getScale( $params)
From parameters, construct a 'scale' array.
Definition: ApiQueryImageInfo.php:280
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:70
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:515
$mime
$mime
Definition: router.php:60
NS_FILE
const NS_FILE
Definition: Defines.php:70
ApiQueryImageInfo\getPropertyMessages
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
Definition: ApiQueryImageInfo.php:784
ApiQueryImageInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryImageInfo.php:822
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:138
ApiQueryBase\userCanSeeRevDel
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Definition: ApiQueryBase.php:607
ApiQueryBase\addPageSubItem
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
Definition: ApiQueryBase.php:494
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
ApiQueryImageInfo\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryImageInfo.php:683