Fix hook situation for Skin::doEditSectionLink
[mediawiki.git] / includes / api / ApiQueryImageInfo.php
blobc4ca5d66cf6606ad139e3ecd9d572c7dca102385
1 <?php
2 /**
5 * Created on July 6, 2007
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * A query action to get image information and upload history.
30 * @ingroup API
32 class ApiQueryImageInfo extends ApiQueryBase {
33 const TRANSFORM_LIMIT = 50;
34 private static $transformCount = 0;
36 public function __construct( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
37 // We allow a subclass to override the prefix, to create a related API
38 // module. Some other parts of MediaWiki construct this with a null
39 // $prefix, which used to be ignored when this only took two arguments
40 if ( is_null( $prefix ) ) {
41 $prefix = 'ii';
43 parent::__construct( $query, $moduleName, $prefix );
46 public function execute() {
47 $params = $this->extractRequestParams();
49 $prop = array_flip( $params['prop'] );
51 $scale = $this->getScale( $params );
53 $opts = array(
54 'version' => $params['metadataversion'],
55 'language' => $params['extmetadatalanguage'],
56 'multilang' => $params['extmetadatamultilang'],
57 'extmetadatafilter' => $params['extmetadatafilter'],
58 'revdelUser' => $this->getUser(),
61 $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
62 if ( !empty( $pageIds[NS_FILE] ) ) {
63 $titles = array_keys( $pageIds[NS_FILE] );
64 asort( $titles ); // Ensure the order is always the same
66 $fromTitle = null;
67 if ( !is_null( $params['continue'] ) ) {
68 $cont = explode( '|', $params['continue'] );
69 $this->dieContinueUsageIf( count( $cont ) != 2 );
70 $fromTitle = strval( $cont[0] );
71 $fromTimestamp = $cont[1];
72 // Filter out any titles before $fromTitle
73 foreach ( $titles as $key => $title ) {
74 if ( $title < $fromTitle ) {
75 unset( $titles[$key] );
76 } else {
77 break;
82 $user = $this->getUser();
83 $findTitles = array_map( function ( $title ) use ( $user ) {
84 return array(
85 'title' => $title,
86 'private' => $user,
88 }, $titles );
90 if ( $params['localonly'] ) {
91 $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
92 } else {
93 $images = RepoGroup::singleton()->findFiles( $findTitles );
96 $result = $this->getResult();
97 foreach ( $titles as $title ) {
98 $pageId = $pageIds[NS_FILE][$title];
99 $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
101 if ( !isset( $images[$title] ) ) {
102 if ( isset( $prop['uploadwarning'] ) ) {
103 // Uploadwarning needs info about non-existing files
104 $images[$title] = wfLocalFile( $title );
105 } else {
106 $result->addValue(
107 array( 'query', 'pages', intval( $pageId ) ),
108 'imagerepository', ''
110 // The above can't fail because it doesn't increase the result size
111 continue;
115 /** @var $img File */
116 $img = $images[$title];
118 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
119 if ( count( $pageIds[NS_FILE] ) == 1 ) {
120 // See the 'the user is screwed' comment below
121 $this->setContinueEnumParameter( 'start',
122 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
124 } else {
125 $this->setContinueEnumParameter( 'continue',
126 $this->getContinueStr( $img, $start ) );
128 break;
131 $fit = $result->addValue(
132 array( 'query', 'pages', intval( $pageId ) ),
133 'imagerepository', $img->getRepoName()
135 if ( !$fit ) {
136 if ( count( $pageIds[NS_FILE] ) == 1 ) {
137 // The user is screwed. imageinfo can't be solely
138 // responsible for exceeding the limit in this case,
139 // so set a query-continue that just returns the same
140 // thing again. When the violating queries have been
141 // out-continued, the result will get through
142 $this->setContinueEnumParameter( 'start',
143 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
145 } else {
146 $this->setContinueEnumParameter( 'continue',
147 $this->getContinueStr( $img, $start ) );
149 break;
152 // Check if we can make the requested thumbnail, and get transform parameters.
153 $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
155 // Get information about the current version first
156 // Check that the current version is within the start-end boundaries
157 $gotOne = false;
158 if (
159 ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
160 ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
162 $gotOne = true;
164 $fit = $this->addPageSubItem( $pageId,
165 self::getInfo( $img, $prop, $result,
166 $finalThumbParams, $opts
169 if ( !$fit ) {
170 if ( count( $pageIds[NS_FILE] ) == 1 ) {
171 // See the 'the user is screwed' comment above
172 $this->setContinueEnumParameter( 'start',
173 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
174 } else {
175 $this->setContinueEnumParameter( 'continue',
176 $this->getContinueStr( $img ) );
178 break;
182 // Now get the old revisions
183 // Get one more to facilitate query-continue functionality
184 $count = ( $gotOne ? 1 : 0 );
185 $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
186 /** @var $oldie File */
187 foreach ( $oldies as $oldie ) {
188 if ( ++$count > $params['limit'] ) {
189 // We've reached the extra one which shows that there are
190 // additional pages to be had. Stop here...
191 // Only set a query-continue if there was only one title
192 if ( count( $pageIds[NS_FILE] ) == 1 ) {
193 $this->setContinueEnumParameter( 'start',
194 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
196 break;
198 $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
199 $this->addPageSubItem( $pageId,
200 self::getInfo( $oldie, $prop, $result,
201 $finalThumbParams, $opts
204 if ( !$fit ) {
205 if ( count( $pageIds[NS_FILE] ) == 1 ) {
206 $this->setContinueEnumParameter( 'start',
207 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
208 } else {
209 $this->setContinueEnumParameter( 'continue',
210 $this->getContinueStr( $oldie ) );
212 break;
215 if ( !$fit ) {
216 break;
223 * From parameters, construct a 'scale' array
224 * @param array $params Parameters passed to api.
225 * @return array|null Key-val array of 'width' and 'height', or null
227 public function getScale( $params ) {
228 $p = $this->getModulePrefix();
230 if ( $params['urlwidth'] != -1 ) {
231 $scale = array();
232 $scale['width'] = $params['urlwidth'];
233 $scale['height'] = $params['urlheight'];
234 } elseif ( $params['urlheight'] != -1 ) {
235 // Height is specified but width isn't
236 // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
237 $scale = array();
238 $scale['height'] = $params['urlheight'];
239 } else {
240 if ( $params['urlparam'] ) {
241 // Audio files might not have a width/height.
242 $scale = array();
243 } else {
244 $scale = null;
248 return $scale;
251 /** Validate and merge scale parameters with handler thumb parameters, give error if invalid.
253 * We do this later than getScale, since we need the image
254 * to know which handler, since handlers can make their own parameters.
255 * @param File $image Image that params are for.
256 * @param array $thumbParams Thumbnail parameters from getScale
257 * @param string $otherParams String of otherParams (iiurlparam).
258 * @return array Array of parameters for transform.
260 protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
261 if ( $thumbParams === null ) {
262 // No scaling requested
263 return null;
265 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
266 // We want to limit only by height in this situation, so pass the
267 // image's full width as the limiting width. But some file types
268 // don't have a width of their own, so pick something arbitrary so
269 // thumbnailing the default icon works.
270 if ( $image->getWidth() <= 0 ) {
271 $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
272 } else {
273 $thumbParams['width'] = $image->getWidth();
277 if ( !$otherParams ) {
278 $this->checkParameterNormalise( $image, $thumbParams );
279 return $thumbParams;
281 $p = $this->getModulePrefix();
283 $h = $image->getHandler();
284 if ( !$h ) {
285 $this->setWarning( 'Could not create thumbnail because ' .
286 $image->getName() . ' does not have an associated image handler' );
288 return $thumbParams;
291 $paramList = $h->parseParamString( $otherParams );
292 if ( !$paramList ) {
293 // Just set a warning (instead of dieUsage), as in many cases
294 // we could still render the image using width and height parameters,
295 // and this type of thing could happen between different versions of
296 // handlers.
297 $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
298 . '. Using only width and height' );
299 $this->checkParameterNormalise( $image, $thumbParams );
300 return $thumbParams;
303 if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
304 if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
305 $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
306 . "in favor of width value derived from {$p}urlwidth/{$p}urlheight "
307 . "({$thumbParams['width']})" );
311 foreach ( $paramList as $name => $value ) {
312 if ( !$h->validateParam( $name, $value ) ) {
313 $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" );
317 $finalParams = $thumbParams + $paramList;
318 $this->checkParameterNormalise( $image, $finalParams );
319 return $finalParams;
323 * Verify that the final image parameters can be normalised.
325 * This doesn't use the normalised parameters, since $file->transform
326 * expects the pre-normalised parameters, but doing the normalisation
327 * allows us to catch certain error conditions early (such as missing
328 * required parameter).
330 * @param $image File
331 * @param $finalParams array List of parameters to transform image with
333 protected function checkParameterNormalise( $image, $finalParams ) {
334 $h = $image->getHandler();
335 if ( !$h ) {
336 return;
338 // Note: normaliseParams modifies the array in place, but we aren't interested
339 // in the actual normalised version, only if we can actually normalise them,
340 // so we use the functions scope to throw away the normalisations.
341 if ( !$h->normaliseParams( $image, $finalParams ) ) {
342 $this->dieUsage( "Could not normalise image parameters for " . $image->getName(), "urlparamnormal" );
347 * Get result information for an image revision
349 * @param File $file
350 * @param array $prop Array of properties to get (in the keys)
351 * @param ApiResult $result
352 * @param array $thumbParams Containing 'width' and 'height' items, or null
353 * @param array|bool|string $opts Options for data fetching.
354 * This is an array consisting of the keys:
355 * 'version': The metadata version for the metadata option
356 * 'language': The language for extmetadata property
357 * 'multilang': Return all translations in extmetadata property
358 * 'revdelUser': User to use when checking whether to show revision-deleted fields.
359 * @return array Result array
361 static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
362 global $wgContLang;
364 $anyHidden = false;
366 if ( !$opts || is_string( $opts ) ) {
367 $opts = array(
368 'version' => $opts ?: 'latest',
369 'language' => $wgContLang,
370 'multilang' => false,
371 'extmetadatafilter' => array(),
372 'revdelUser' => null,
375 $version = $opts['version'];
376 $vals = array();
377 // Timestamp is shown even if the file is revdelete'd in interface
378 // so do same here.
379 if ( isset( $prop['timestamp'] ) ) {
380 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
383 // Handle external callers who don't pass revdelUser
384 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
385 $revdelUser = $opts['revdelUser'];
386 $canShowField = function ( $field ) use ( $file, $revdelUser ) {
387 return $file->userCan( $field, $revdelUser );
389 } else {
390 $canShowField = function ( $field ) use ( $file ) {
391 return !$file->isDeleted( $field );
395 $user = isset( $prop['user'] );
396 $userid = isset( $prop['userid'] );
398 if ( $user || $userid ) {
399 if ( $file->isDeleted( File::DELETED_USER ) ) {
400 $vals['userhidden'] = '';
401 $anyHidden = true;
403 if ( $canShowField( File::DELETED_USER ) ) {
404 if ( $user ) {
405 $vals['user'] = $file->getUser();
407 if ( $userid ) {
408 $vals['userid'] = $file->getUser( 'id' );
410 if ( !$file->getUser( 'id' ) ) {
411 $vals['anon'] = '';
416 // This is shown even if the file is revdelete'd in interface
417 // so do same here.
418 if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
419 $vals['size'] = intval( $file->getSize() );
420 $vals['width'] = intval( $file->getWidth() );
421 $vals['height'] = intval( $file->getHeight() );
423 $pageCount = $file->pageCount();
424 if ( $pageCount !== false ) {
425 $vals['pagecount'] = $pageCount;
428 // length as in how many seconds long a video is.
429 $length = $file->getLength();
430 if ( $length ) {
431 // Call it duration, because "length" can be ambiguous.
432 $vals['duration'] = (float)$length;
436 $pcomment = isset( $prop['parsedcomment'] );
437 $comment = isset( $prop['comment'] );
439 if ( $pcomment || $comment ) {
440 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
441 $vals['commenthidden'] = '';
442 $anyHidden = true;
444 if ( $canShowField( File::DELETED_COMMENT ) ) {
445 if ( $pcomment ) {
446 $vals['parsedcomment'] = Linker::formatComment(
447 $file->getDescription( File::RAW ), $file->getTitle() );
449 if ( $comment ) {
450 $vals['comment'] = $file->getDescription( File::RAW );
455 $canonicaltitle = isset( $prop['canonicaltitle'] );
456 $url = isset( $prop['url'] );
457 $sha1 = isset( $prop['sha1'] );
458 $meta = isset( $prop['metadata'] );
459 $extmetadata = isset( $prop['extmetadata'] );
460 $commonmeta = isset( $prop['commonmetadata'] );
461 $mime = isset( $prop['mime'] );
462 $mediatype = isset( $prop['mediatype'] );
463 $archive = isset( $prop['archivename'] );
464 $bitdepth = isset( $prop['bitdepth'] );
465 $uploadwarning = isset( $prop['uploadwarning'] );
467 if ( $uploadwarning ) {
468 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
471 if ( $file->isDeleted( File::DELETED_FILE ) ) {
472 $vals['filehidden'] = '';
473 $anyHidden = true;
476 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
477 $vals['suppressed'] = true;
480 if ( !$canShowField( File::DELETED_FILE ) ) {
481 //Early return, tidier than indenting all following things one level
482 return $vals;
485 if ( $canonicaltitle ) {
486 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
489 if ( $url ) {
490 if ( !is_null( $thumbParams ) ) {
491 $mto = $file->transform( $thumbParams );
492 self::$transformCount++;
493 if ( $mto && !$mto->isError() ) {
494 $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
496 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
497 // thumbnail sizes for the thumbnail actual size
498 if ( $mto->getUrl() !== $file->getUrl() ) {
499 $vals['thumbwidth'] = intval( $mto->getWidth() );
500 $vals['thumbheight'] = intval( $mto->getHeight() );
501 } else {
502 $vals['thumbwidth'] = intval( $file->getWidth() );
503 $vals['thumbheight'] = intval( $file->getHeight() );
506 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
507 list( , $mime ) = $file->getHandler()->getThumbType(
508 $mto->getExtension(), $file->getMimeType(), $thumbParams );
509 $vals['thumbmime'] = $mime;
511 } elseif ( $mto && $mto->isError() ) {
512 $vals['thumberror'] = $mto->toText();
515 $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
516 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
519 if ( $sha1 ) {
520 $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
523 if ( $meta ) {
524 wfSuppressWarnings();
525 $metadata = unserialize( $file->getMetadata() );
526 wfRestoreWarnings();
527 if ( $metadata && $version !== 'latest' ) {
528 $metadata = $file->convertMetadataVersion( $metadata, $version );
530 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
532 if ( $commonmeta ) {
533 $metaArray = $file->getCommonMetaArray();
534 $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : array();
537 if ( $extmetadata ) {
538 // Note, this should return an array where all the keys
539 // start with a letter, and all the values are strings.
540 // Thus there should be no issue with format=xml.
541 $format = new FormatMetadata;
542 $format->setSingleLanguage( !$opts['multilang'] );
543 $format->getContext()->setLanguage( $opts['language'] );
544 $extmetaArray = $format->fetchExtendedMetadata( $file );
545 if ( $opts['extmetadatafilter'] ) {
546 $extmetaArray = array_intersect_key(
547 $extmetaArray, array_flip( $opts['extmetadatafilter'] )
550 $vals['extmetadata'] = $extmetaArray;
553 if ( $mime ) {
554 $vals['mime'] = $file->getMimeType();
557 if ( $mediatype ) {
558 $vals['mediatype'] = $file->getMediaType();
561 if ( $archive && $file->isOld() ) {
562 $vals['archivename'] = $file->getArchiveName();
565 if ( $bitdepth ) {
566 $vals['bitdepth'] = $file->getBitDepth();
569 return $vals;
573 * Get the count of image transformations performed
575 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
577 * @return int Count
579 static function getTransformCount() {
580 return self::$transformCount;
585 * @param array $metadata
586 * @param ApiResult $result
587 * @return array
589 public static function processMetaData( $metadata, $result ) {
590 $retval = array();
591 if ( is_array( $metadata ) ) {
592 foreach ( $metadata as $key => $value ) {
593 $r = array( 'name' => $key );
594 if ( is_array( $value ) ) {
595 $r['value'] = self::processMetaData( $value, $result );
596 } else {
597 $r['value'] = $value;
599 $retval[] = $r;
602 $result->setIndexedTagName( $retval, 'metadata' );
604 return $retval;
607 public function getCacheMode( $params ) {
608 if ( $this->userCanSeeRevDel() ) {
609 return 'private';
612 return 'public';
616 * @param File $img
617 * @param null|string $start
618 * @return string
620 protected function getContinueStr( $img, $start = null ) {
621 if ( $start === null ) {
622 $start = $img->getTimestamp();
625 return $img->getOriginalTitle()->getDBkey() . '|' . $start;
628 public function getAllowedParams() {
629 global $wgContLang;
631 return array(
632 'prop' => array(
633 ApiBase::PARAM_ISMULTI => true,
634 ApiBase::PARAM_DFLT => 'timestamp|user',
635 ApiBase::PARAM_TYPE => self::getPropertyNames(),
636 ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages(),
638 'limit' => array(
639 ApiBase::PARAM_TYPE => 'limit',
640 ApiBase::PARAM_DFLT => 1,
641 ApiBase::PARAM_MIN => 1,
642 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
643 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
645 'start' => array(
646 ApiBase::PARAM_TYPE => 'timestamp'
648 'end' => array(
649 ApiBase::PARAM_TYPE => 'timestamp'
651 'urlwidth' => array(
652 ApiBase::PARAM_TYPE => 'integer',
653 ApiBase::PARAM_DFLT => -1,
654 ApiBase::PARAM_HELP_MSG => array(
655 'apihelp-query+imageinfo-param-urlwidth',
656 ApiQueryImageInfo::TRANSFORM_LIMIT,
659 'urlheight' => array(
660 ApiBase::PARAM_TYPE => 'integer',
661 ApiBase::PARAM_DFLT => -1
663 'metadataversion' => array(
664 ApiBase::PARAM_TYPE => 'string',
665 ApiBase::PARAM_DFLT => '1',
667 'extmetadatalanguage' => array(
668 ApiBase::PARAM_TYPE => 'string',
669 ApiBase::PARAM_DFLT => $wgContLang->getCode(),
671 'extmetadatamultilang' => array(
672 ApiBase::PARAM_TYPE => 'boolean',
673 ApiBase::PARAM_DFLT => false,
675 'extmetadatafilter' => array(
676 ApiBase::PARAM_TYPE => 'string',
677 ApiBase::PARAM_ISMULTI => true,
679 'urlparam' => array(
680 ApiBase::PARAM_DFLT => '',
681 ApiBase::PARAM_TYPE => 'string',
683 'continue' => array(
684 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
686 'localonly' => false,
691 * Returns all possible parameters to iiprop
693 * @param array $filter List of properties to filter out
694 * @return array
696 public static function getPropertyNames( $filter = array() ) {
697 return array_keys( self::getPropertyMessages( $filter ) );
701 * Returns messages for all possible parameters to iiprop
703 * @param array $filter List of properties to filter out
704 * @return array
706 public static function getPropertyMessages( $filter = array() ) {
707 return array_diff_key(
708 array(
709 'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
710 'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
711 'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
712 'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
713 'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
714 'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
715 'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
716 'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
717 'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
718 'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
719 'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
720 'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
721 'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
722 'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
723 'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
724 'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
725 'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
726 'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
727 'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
729 array_flip( $filter )
734 * Returns array key value pairs of properties and their descriptions
736 * @deprecated since 1.25
737 * @param string $modulePrefix
738 * @return array
740 private static function getProperties( $modulePrefix = '' ) {
741 return array(
742 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
743 'user' => ' user - Adds the user who uploaded the image version',
744 'userid' => ' userid - Add the user ID that uploaded the image version',
745 'comment' => ' comment - Comment on the version',
746 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
747 'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
748 'url' => ' url - Gives URL to the image and the description page',
749 'size' => ' size - Adds the size of the image in bytes, ' .
750 'its height and its width. Page count and duration are added if applicable',
751 'dimensions' => ' dimensions - Alias for size', // B/C with Allimages
752 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
753 'mime' => ' mime - Adds MIME type of the image',
754 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
755 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
756 'mediatype' => ' mediatype - Adds the media type of the image',
757 'metadata' => ' metadata - Lists Exif metadata for the version of the image',
758 'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
759 'for the version of the image',
760 'extmetadata' => ' extmetadata - Lists formatted metadata combined ' .
761 'from multiple sources. Results are HTML formatted.',
762 'archivename' => ' archivename - Adds the file name of the archive ' .
763 'version for non-latest versions',
764 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
765 'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
766 'get information about an existing file. Not intended for use outside MediaWiki core',
771 * Returns the descriptions for the properties provided by getPropertyNames()
773 * @deprecated since 1.25
774 * @param array $filter List of properties to filter out
775 * @param string $modulePrefix
776 * @return array
778 public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
779 return array_merge(
780 array( 'What image information to get:' ),
781 array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
785 protected function getExamplesMessages() {
786 return array(
787 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
788 => 'apihelp-query+imageinfo-example-simple',
789 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
790 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
791 => 'apihelp-query+imageinfo-example-dated',
795 public function getHelpUrls() {
796 return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';