MediaWiki  REL1_31
ApiQueryImageInfo.php
Go to the documentation of this file.
1 <?php
29  const TRANSFORM_LIMIT = 50;
30  private static $transformCount = 0;
31 
32  public function __construct( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
33  // We allow a subclass to override the prefix, to create a related API
34  // module. Some other parts of MediaWiki construct this with a null
35  // $prefix, which used to be ignored when this only took two arguments
36  if ( is_null( $prefix ) ) {
37  $prefix = 'ii';
38  }
39  parent::__construct( $query, $moduleName, $prefix );
40  }
41 
42  public function execute() {
43  $params = $this->extractRequestParams();
44 
45  $prop = array_flip( $params['prop'] );
46 
47  $scale = $this->getScale( $params );
48 
49  $opts = [
50  'version' => $params['metadataversion'],
51  'language' => $params['extmetadatalanguage'],
52  'multilang' => $params['extmetadatamultilang'],
53  'extmetadatafilter' => $params['extmetadatafilter'],
54  'revdelUser' => $this->getUser(),
55  ];
56 
57  if ( isset( $params['badfilecontexttitle'] ) ) {
58  $badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
59  if ( !$badFileContextTitle ) {
60  $this->dieUsage( 'Invalid title in badfilecontexttitle parameter', 'invalid-title' );
61  }
62  } else {
63  $badFileContextTitle = false;
64  }
65 
66  $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
67  if ( !empty( $pageIds[NS_FILE] ) ) {
68  $titles = array_keys( $pageIds[NS_FILE] );
69  asort( $titles ); // Ensure the order is always the same
70 
71  $fromTitle = null;
72  if ( !is_null( $params['continue'] ) ) {
73  $cont = explode( '|', $params['continue'] );
74  $this->dieContinueUsageIf( count( $cont ) != 2 );
75  $fromTitle = strval( $cont[0] );
76  $fromTimestamp = $cont[1];
77  // Filter out any titles before $fromTitle
78  foreach ( $titles as $key => $title ) {
79  if ( $title < $fromTitle ) {
80  unset( $titles[$key] );
81  } else {
82  break;
83  }
84  }
85  }
86 
87  $user = $this->getUser();
88  $findTitles = array_map( function ( $title ) use ( $user ) {
89  return [
90  'title' => $title,
91  'private' => $user,
92  ];
93  }, $titles );
94 
95  if ( $params['localonly'] ) {
96  $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
97  } else {
98  $images = RepoGroup::singleton()->findFiles( $findTitles );
99  }
100 
101  $result = $this->getResult();
102  foreach ( $titles as $title ) {
103  $info = [];
104  $pageId = $pageIds[NS_FILE][$title];
105  $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
106 
107  if ( !isset( $images[$title] ) ) {
108  if ( isset( $prop['uploadwarning'] ) || isset( $prop['badfile'] ) ) {
109  // uploadwarning and badfile need info about non-existing files
110  $images[$title] = wfLocalFile( $title );
111  // Doesn't exist, so set an empty image repository
112  $info['imagerepository'] = '';
113  } else {
114  $result->addValue(
115  [ 'query', 'pages', intval( $pageId ) ],
116  'imagerepository', ''
117  );
118  // The above can't fail because it doesn't increase the result size
119  continue;
120  }
121  }
122 
124  $img = $images[$title];
125 
126  if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
127  if ( count( $pageIds[NS_FILE] ) == 1 ) {
128  // See the 'the user is screwed' comment below
129  $this->setContinueEnumParameter( 'start',
130  $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
131  );
132  } else {
133  $this->setContinueEnumParameter( 'continue',
134  $this->getContinueStr( $img, $start ) );
135  }
136  break;
137  }
138 
139  if ( !isset( $info['imagerepository'] ) ) {
140  $info['imagerepository'] = $img->getRepoName();
141  }
142  if ( isset( $prop['badfile'] ) ) {
143  $info['badfile'] = (bool)wfIsBadImage( $title, $badFileContextTitle );
144  }
145 
146  $fit = $result->addValue( [ 'query', 'pages' ], intval( $pageId ), $info );
147  if ( !$fit ) {
148  if ( count( $pageIds[NS_FILE] ) == 1 ) {
149  // The user is screwed. imageinfo can't be solely
150  // responsible for exceeding the limit in this case,
151  // so set a query-continue that just returns the same
152  // thing again. When the violating queries have been
153  // out-continued, the result will get through
154  $this->setContinueEnumParameter( 'start',
155  $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
156  );
157  } else {
158  $this->setContinueEnumParameter( 'continue',
159  $this->getContinueStr( $img, $start ) );
160  }
161  break;
162  }
163 
164  // Check if we can make the requested thumbnail, and get transform parameters.
165  $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
166 
167  // Get information about the current version first
168  // Check that the current version is within the start-end boundaries
169  $gotOne = false;
170  if (
171  ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
172  ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
173  ) {
174  $gotOne = true;
175 
176  $fit = $this->addPageSubItem( $pageId,
177  static::getInfo( $img, $prop, $result,
178  $finalThumbParams, $opts
179  )
180  );
181  if ( !$fit ) {
182  if ( count( $pageIds[NS_FILE] ) == 1 ) {
183  // See the 'the user is screwed' comment above
184  $this->setContinueEnumParameter( 'start',
185  wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
186  } else {
187  $this->setContinueEnumParameter( 'continue',
188  $this->getContinueStr( $img ) );
189  }
190  break;
191  }
192  }
193 
194  // Now get the old revisions
195  // Get one more to facilitate query-continue functionality
196  $count = ( $gotOne ? 1 : 0 );
197  $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
199  foreach ( $oldies as $oldie ) {
200  if ( ++$count > $params['limit'] ) {
201  // We've reached the extra one which shows that there are
202  // additional pages to be had. Stop here...
203  // Only set a query-continue if there was only one title
204  if ( count( $pageIds[NS_FILE] ) == 1 ) {
205  $this->setContinueEnumParameter( 'start',
206  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
207  }
208  break;
209  }
210  $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
211  $this->addPageSubItem( $pageId,
212  static::getInfo( $oldie, $prop, $result,
213  $finalThumbParams, $opts
214  )
215  );
216  if ( !$fit ) {
217  if ( count( $pageIds[NS_FILE] ) == 1 ) {
218  $this->setContinueEnumParameter( 'start',
219  wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
220  } else {
221  $this->setContinueEnumParameter( 'continue',
222  $this->getContinueStr( $oldie ) );
223  }
224  break;
225  }
226  }
227  if ( !$fit ) {
228  break;
229  }
230  }
231  }
232  }
233 
239  public function getScale( $params ) {
240  if ( $params['urlwidth'] != -1 ) {
241  $scale = [];
242  $scale['width'] = $params['urlwidth'];
243  $scale['height'] = $params['urlheight'];
244  } elseif ( $params['urlheight'] != -1 ) {
245  // Height is specified but width isn't
246  // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
247  $scale = [];
248  $scale['height'] = $params['urlheight'];
249  } else {
250  if ( $params['urlparam'] ) {
251  // Audio files might not have a width/height.
252  $scale = [];
253  } else {
254  $scale = null;
255  }
256  }
257 
258  return $scale;
259  }
260 
270  protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
271  if ( $thumbParams === null ) {
272  // No scaling requested
273  return null;
274  }
275  if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
276  // We want to limit only by height in this situation, so pass the
277  // image's full width as the limiting width. But some file types
278  // don't have a width of their own, so pick something arbitrary so
279  // thumbnailing the default icon works.
280  if ( $image->getWidth() <= 0 ) {
281  $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
282  } else {
283  $thumbParams['width'] = $image->getWidth();
284  }
285  }
286 
287  if ( !$otherParams ) {
288  $this->checkParameterNormalise( $image, $thumbParams );
289  return $thumbParams;
290  }
291  $p = $this->getModulePrefix();
292 
293  $h = $image->getHandler();
294  if ( !$h ) {
295  $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
296 
297  return $thumbParams;
298  }
299 
300  $paramList = $h->parseParamString( $otherParams );
301  if ( !$paramList ) {
302  // Just set a warning (instead of dieUsage), as in many cases
303  // we could still render the image using width and height parameters,
304  // and this type of thing could happen between different versions of
305  // handlers.
306  $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
307  $this->checkParameterNormalise( $image, $thumbParams );
308  return $thumbParams;
309  }
310 
311  if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
312  if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
313  $this->addWarning(
314  [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
315  );
316  }
317  }
318 
319  foreach ( $paramList as $name => $value ) {
320  if ( !$h->validateParam( $name, $value ) ) {
321  $this->dieWithError(
322  [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
323  );
324  }
325  }
326 
327  $finalParams = $thumbParams + $paramList;
328  $this->checkParameterNormalise( $image, $finalParams );
329  return $finalParams;
330  }
331 
343  protected function checkParameterNormalise( $image, $finalParams ) {
344  $h = $image->getHandler();
345  if ( !$h ) {
346  return;
347  }
348  // Note: normaliseParams modifies the array in place, but we aren't interested
349  // in the actual normalised version, only if we can actually normalise them,
350  // so we use the functions scope to throw away the normalisations.
351  if ( !$h->normaliseParams( $image, $finalParams ) ) {
352  $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
353  }
354  }
355 
371  public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
373 
374  $anyHidden = false;
375 
376  if ( !$opts || is_string( $opts ) ) {
377  $opts = [
378  'version' => $opts ?: 'latest',
379  'language' => $wgContLang,
380  'multilang' => false,
381  'extmetadatafilter' => [],
382  'revdelUser' => null,
383  ];
384  }
385  $version = $opts['version'];
386  $vals = [
387  ApiResult::META_TYPE => 'assoc',
388  ];
389  // Timestamp is shown even if the file is revdelete'd in interface
390  // so do same here.
391  if ( isset( $prop['timestamp'] ) ) {
392  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
393  }
394 
395  // Handle external callers who don't pass revdelUser
396  if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
397  $revdelUser = $opts['revdelUser'];
398  $canShowField = function ( $field ) use ( $file, $revdelUser ) {
399  return $file->userCan( $field, $revdelUser );
400  };
401  } else {
402  $canShowField = function ( $field ) use ( $file ) {
403  return !$file->isDeleted( $field );
404  };
405  }
406 
407  $user = isset( $prop['user'] );
408  $userid = isset( $prop['userid'] );
409 
410  if ( $user || $userid ) {
411  if ( $file->isDeleted( File::DELETED_USER ) ) {
412  $vals['userhidden'] = true;
413  $anyHidden = true;
414  }
415  if ( $canShowField( File::DELETED_USER ) ) {
416  if ( $user ) {
417  $vals['user'] = $file->getUser();
418  }
419  if ( $userid ) {
420  $vals['userid'] = $file->getUser( 'id' );
421  }
422  if ( !$file->getUser( 'id' ) ) {
423  $vals['anon'] = true;
424  }
425  }
426  }
427 
428  // This is shown even if the file is revdelete'd in interface
429  // so do same here.
430  if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
431  $vals['size'] = intval( $file->getSize() );
432  $vals['width'] = intval( $file->getWidth() );
433  $vals['height'] = intval( $file->getHeight() );
434 
435  $pageCount = $file->pageCount();
436  if ( $pageCount !== false ) {
437  $vals['pagecount'] = $pageCount;
438  }
439 
440  // length as in how many seconds long a video is.
441  $length = $file->getLength();
442  if ( $length ) {
443  // Call it duration, because "length" can be ambiguous.
444  $vals['duration'] = (float)$length;
445  }
446  }
447 
448  $pcomment = isset( $prop['parsedcomment'] );
449  $comment = isset( $prop['comment'] );
450 
451  if ( $pcomment || $comment ) {
452  if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
453  $vals['commenthidden'] = true;
454  $anyHidden = true;
455  }
456  if ( $canShowField( File::DELETED_COMMENT ) ) {
457  if ( $pcomment ) {
458  $vals['parsedcomment'] = Linker::formatComment(
459  $file->getDescription( File::RAW ), $file->getTitle() );
460  }
461  if ( $comment ) {
462  $vals['comment'] = $file->getDescription( File::RAW );
463  }
464  }
465  }
466 
467  $canonicaltitle = isset( $prop['canonicaltitle'] );
468  $url = isset( $prop['url'] );
469  $sha1 = isset( $prop['sha1'] );
470  $meta = isset( $prop['metadata'] );
471  $extmetadata = isset( $prop['extmetadata'] );
472  $commonmeta = isset( $prop['commonmetadata'] );
473  $mime = isset( $prop['mime'] );
474  $mediatype = isset( $prop['mediatype'] );
475  $archive = isset( $prop['archivename'] );
476  $bitdepth = isset( $prop['bitdepth'] );
477  $uploadwarning = isset( $prop['uploadwarning'] );
478 
479  if ( $uploadwarning ) {
481  }
482 
483  if ( $file->isDeleted( File::DELETED_FILE ) ) {
484  $vals['filehidden'] = true;
485  $anyHidden = true;
486  }
487 
488  if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
489  $vals['suppressed'] = true;
490  }
491 
492  if ( !$canShowField( File::DELETED_FILE ) ) {
493  // Early return, tidier than indenting all following things one level
494  return $vals;
495  }
496 
497  if ( $canonicaltitle ) {
498  $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
499  }
500 
501  if ( $url ) {
502  if ( $file->exists() ) {
503  if ( !is_null( $thumbParams ) ) {
504  $mto = $file->transform( $thumbParams );
505  self::$transformCount++;
506  if ( $mto && !$mto->isError() ) {
507  $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
508 
509  // T25834 - If the URLs are the same, we haven't resized it, so shouldn't give the wanted
510  // thumbnail sizes for the thumbnail actual size
511  if ( $mto->getUrl() !== $file->getUrl() ) {
512  $vals['thumbwidth'] = intval( $mto->getWidth() );
513  $vals['thumbheight'] = intval( $mto->getHeight() );
514  } else {
515  $vals['thumbwidth'] = intval( $file->getWidth() );
516  $vals['thumbheight'] = intval( $file->getHeight() );
517  }
518 
519  if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
520  list( , $mime ) = $file->getHandler()->getThumbType(
521  $mto->getExtension(), $file->getMimeType(), $thumbParams );
522  $vals['thumbmime'] = $mime;
523  }
524  } elseif ( $mto && $mto->isError() ) {
525  $vals['thumberror'] = $mto->toText();
526  }
527  }
528  $vals['url'] = wfExpandUrl( $file->getFullUrl(), PROTO_CURRENT );
529  } else {
530  $vals['filemissing'] = true;
531  }
532  $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
533 
534  $shortDescriptionUrl = $file->getDescriptionShortUrl();
535  if ( $shortDescriptionUrl !== null ) {
536  $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
537  }
538  }
539 
540  if ( $sha1 ) {
541  $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
542  }
543 
544  if ( $meta ) {
545  Wikimedia\suppressWarnings();
546  $metadata = unserialize( $file->getMetadata() );
547  Wikimedia\restoreWarnings();
548  if ( $metadata && $version !== 'latest' ) {
549  $metadata = $file->convertMetadataVersion( $metadata, $version );
550  }
551  $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
552  }
553  if ( $commonmeta ) {
554  $metaArray = $file->getCommonMetaArray();
555  $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
556  }
557 
558  if ( $extmetadata ) {
559  // Note, this should return an array where all the keys
560  // start with a letter, and all the values are strings.
561  // Thus there should be no issue with format=xml.
562  $format = new FormatMetadata;
563  $format->setSingleLanguage( !$opts['multilang'] );
564  $format->getContext()->setLanguage( $opts['language'] );
565  $extmetaArray = $format->fetchExtendedMetadata( $file );
566  if ( $opts['extmetadatafilter'] ) {
567  $extmetaArray = array_intersect_key(
568  $extmetaArray, array_flip( $opts['extmetadatafilter'] )
569  );
570  }
571  $vals['extmetadata'] = $extmetaArray;
572  }
573 
574  if ( $mime ) {
575  $vals['mime'] = $file->getMimeType();
576  }
577 
578  if ( $mediatype ) {
579  $vals['mediatype'] = $file->getMediaType();
580  }
581 
582  if ( $archive && $file->isOld() ) {
583  $vals['archivename'] = $file->getArchiveName();
584  }
585 
586  if ( $bitdepth ) {
587  $vals['bitdepth'] = $file->getBitDepth();
588  }
589 
590  return $vals;
591  }
592 
600  static function getTransformCount() {
601  return self::$transformCount;
602  }
603 
610  public static function processMetaData( $metadata, $result ) {
611  $retval = [];
612  if ( is_array( $metadata ) ) {
613  foreach ( $metadata as $key => $value ) {
614  $r = [
615  'name' => $key,
616  ApiResult::META_BC_BOOLS => [ 'value' ],
617  ];
618  if ( is_array( $value ) ) {
619  $r['value'] = static::processMetaData( $value, $result );
620  } else {
621  $r['value'] = $value;
622  }
623  $retval[] = $r;
624  }
625  }
626  ApiResult::setIndexedTagName( $retval, 'metadata' );
627 
628  return $retval;
629  }
630 
631  public function getCacheMode( $params ) {
632  if ( $this->userCanSeeRevDel() ) {
633  return 'private';
634  }
635 
636  return 'public';
637  }
638 
644  protected function getContinueStr( $img, $start = null ) {
645  if ( $start === null ) {
646  $start = $img->getTimestamp();
647  }
648 
649  return $img->getOriginalTitle()->getDBkey() . '|' . $start;
650  }
651 
652  public function getAllowedParams() {
654 
655  return [
656  'prop' => [
657  ApiBase::PARAM_ISMULTI => true,
658  ApiBase::PARAM_DFLT => 'timestamp|user',
659  ApiBase::PARAM_TYPE => static::getPropertyNames(),
660  ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
661  ],
662  'limit' => [
663  ApiBase::PARAM_TYPE => 'limit',
664  ApiBase::PARAM_DFLT => 1,
665  ApiBase::PARAM_MIN => 1,
668  ],
669  'start' => [
670  ApiBase::PARAM_TYPE => 'timestamp'
671  ],
672  'end' => [
673  ApiBase::PARAM_TYPE => 'timestamp'
674  ],
675  'urlwidth' => [
676  ApiBase::PARAM_TYPE => 'integer',
677  ApiBase::PARAM_DFLT => -1,
679  'apihelp-query+imageinfo-param-urlwidth',
681  ],
682  ],
683  'urlheight' => [
684  ApiBase::PARAM_TYPE => 'integer',
685  ApiBase::PARAM_DFLT => -1
686  ],
687  'metadataversion' => [
688  ApiBase::PARAM_TYPE => 'string',
689  ApiBase::PARAM_DFLT => '1',
690  ],
691  'extmetadatalanguage' => [
692  ApiBase::PARAM_TYPE => 'string',
693  ApiBase::PARAM_DFLT => $wgContLang->getCode(),
694  ],
695  'extmetadatamultilang' => [
696  ApiBase::PARAM_TYPE => 'boolean',
697  ApiBase::PARAM_DFLT => false,
698  ],
699  'extmetadatafilter' => [
700  ApiBase::PARAM_TYPE => 'string',
701  ApiBase::PARAM_ISMULTI => true,
702  ],
703  'urlparam' => [
704  ApiBase::PARAM_DFLT => '',
705  ApiBase::PARAM_TYPE => 'string',
706  ],
707  'badfilecontexttitle' => [
708  ApiBase::PARAM_TYPE => 'string',
709  ],
710  'continue' => [
711  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
712  ],
713  'localonly' => false,
714  ];
715  }
716 
723  public static function getPropertyNames( $filter = [] ) {
724  return array_keys( static::getPropertyMessages( $filter ) );
725  }
726 
733  public static function getPropertyMessages( $filter = [] ) {
734  return array_diff_key(
735  [
736  'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
737  'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
738  'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
739  'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
740  'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
741  'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
742  'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
743  'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
744  'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
745  'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
746  'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
747  'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
748  'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
749  'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
750  'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
751  'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
752  'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
753  'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
754  'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
755  'badfile' => 'apihelp-query+imageinfo-paramvalue-prop-badfile',
756  ],
757  array_flip( $filter )
758  );
759  }
760 
768  private static function getProperties( $modulePrefix = '' ) {
769  return [
770  'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
771  'user' => ' user - Adds the user who uploaded the image version',
772  'userid' => ' userid - Add the user ID that uploaded the image version',
773  'comment' => ' comment - Comment on the version',
774  'parsedcomment' => ' parsedcomment - Parse the comment on the version',
775  'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
776  'url' => ' url - Gives URL to the image and the description page',
777  'size' => ' size - Adds the size of the image in bytes, ' .
778  'its height and its width. Page count and duration are added if applicable',
779  'dimensions' => ' dimensions - Alias for size', // B/C with Allimages
780  'sha1' => ' sha1 - Adds SHA-1 hash for the image',
781  'mime' => ' mime - Adds MIME type of the image',
782  'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
783  ' (requires url and param ' . $modulePrefix . 'urlwidth)',
784  'mediatype' => ' mediatype - Adds the media type of the image',
785  'metadata' => ' metadata - Lists Exif metadata for the version of the image',
786  'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
787  'for the version of the image',
788  'extmetadata' => ' extmetadata - Lists formatted metadata combined ' .
789  'from multiple sources. Results are HTML formatted.',
790  'archivename' => ' archivename - Adds the file name of the archive ' .
791  'version for non-latest versions',
792  'bitdepth' => ' bitdepth - Adds the bit depth of the version',
793  'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
794  'get information about an existing file. Not intended for use outside MediaWiki core',
795  ];
796  }
797 
806  public static function getPropertyDescriptions( $filter = [], $modulePrefix = '' ) {
807  return array_merge(
808  [ 'What image information to get:' ],
809  array_values( array_diff_key( static::getProperties( $modulePrefix ), array_flip( $filter ) ) )
810  );
811  }
812 
813  protected function getExamplesMessages() {
814  return [
815  'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
816  => 'apihelp-query+imageinfo-example-simple',
817  'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
818  'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
819  => 'apihelp-query+imageinfo-example-dated',
820  ];
821  }
822 
823  public function getHelpUrls() {
824  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Imageinfo';
825  }
826 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ApiQueryImageInfo\getPropertyNames
static getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
Definition: ApiQueryImageInfo.php:723
ApiQueryImageInfo\getContinueStr
getContinueStr( $img, $start=null)
Definition: ApiQueryImageInfo.php:644
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:273
ApiQuery
This is the main query class.
Definition: ApiQuery.php:36
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1819
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:59
ApiQueryImageInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryImageInfo.php:813
File\DELETED_USER
const DELETED_USER
Definition: File.php:55
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:56
ApiQueryImageInfo\mergeThumbParams
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
Definition: ApiQueryImageInfo.php:270
File\RAW
const RAW
Definition: File.php:71
ApiResult\META_TYPE
const META_TYPE
Key for the 'type' metadata item.
Definition: ApiResult.php:108
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1895
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:124
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1980
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:641
ApiQueryImageInfo\$transformCount
static $transformCount
Definition: ApiQueryImageInfo.php:30
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:192
NS_FILE
const NS_FILE
Definition: Defines.php:80
$params
$params
Definition: styleTest.css.php:40
ApiQueryImageInfo
A query action to get image information and upload history.
Definition: ApiQueryImageInfo.php:28
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1993
ApiQueryImageInfo\getInfo
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
Definition: ApiQueryImageInfo.php:371
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
SpecialUpload\getExistsWarning
static getExistsWarning( $exists)
Formats a result of UploadBase::getExistsWarning as HTML This check is static and can be done pre-upl...
Definition: SpecialUpload.php:781
FormatMetadata\setSingleLanguage
setSingleLanguage( $val)
Trigger only outputting single language for multilanguage fields.
Definition: FormatMetadata.php:65
ApiQueryImageInfo\getTransformCount
static getTransformCount()
Get the count of image transformations performed.
Definition: ApiQueryImageInfo.php:600
ApiQueryImageInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryImageInfo.php:42
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:99
ApiQueryImageInfo\getProperties
static getProperties( $modulePrefix='')
Returns array key value pairs of properties and their descriptions.
Definition: ApiQueryImageInfo.php:768
ApiQueryImageInfo\__construct
__construct(ApiQuery $query, $moduleName, $prefix='ii')
Definition: ApiQueryImageInfo.php:32
File\DELETED_COMMENT
const DELETED_COMMENT
Definition: File.php:54
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:33
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:234
ApiQueryImageInfo\checkParameterNormalise
checkParameterNormalise( $image, $finalParams)
Verify that the final image parameters can be normalised.
Definition: ApiQueryImageInfo.php:343
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:232
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:90
ApiResult\META_BC_BOOLS
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
Definition: ApiResult.php:134
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
ApiQueryImageInfo\processMetaData
static processMetaData( $metadata, $result)
Definition: ApiQueryImageInfo.php:610
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:529
$mime
if( $ext=='php'|| $ext=='php5') $mime
Definition: router.php:59
ApiQueryImageInfo\TRANSFORM_LIMIT
const TRANSFORM_LIMIT
Definition: ApiQueryImageInfo.php:29
wfIsBadImage
wfIsBadImage( $name, $contextTitle=false, $blacklist=null)
Determine if an image exists on the 'bad image list'.
Definition: GlobalFunctions.php:3238
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:749
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
$value
$value
Definition: styleTest.css.php:45
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2066
ApiBase\dieUsage
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
Definition: ApiBase.php:2672
ApiQueryImageInfo\getPropertyDescriptions
static getPropertyDescriptions( $filter=[], $modulePrefix='')
Returns the descriptions for the properties provided by getPropertyNames()
Definition: ApiQueryImageInfo.php:806
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1643
UploadBase\getExistsWarning
static getExistsWarning( $file)
Helper function that does various existence checks for a file.
Definition: UploadBase.php:2001
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:130
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:1109
FormatMetadata
Format Image metadata values into a human readable form.
Definition: FormatMetadata.php:51
ApiQueryImageInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryImageInfo.php:652
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$image
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
Definition: hooks.txt:895
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:236
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:96
ApiQueryImageInfo\getScale
getScale( $params)
From parameters, construct a 'scale' array.
Definition: ApiQueryImageInfo.php:239
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:53
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:531
ApiQueryImageInfo\getPropertyMessages
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
Definition: ApiQueryImageInfo.php:733
ApiQueryImageInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryImageInfo.php:823
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1620
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:157
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:2864
ApiQueryBase\userCanSeeRevDel
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Definition: ApiQueryBase.php:602
ApiQueryBase\addPageSubItem
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
Definition: ApiQueryBase.php:510
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:266
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:521
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:57
ApiQueryImageInfo\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryImageInfo.php:631