Merge "Localisation updates from http://translatewiki.net."
[lhc/web/wiklou.git] / includes / api / ApiQueryImageInfo.php
1 <?php
2 /**
3 *
4 *
5 * Created on July 6, 2007
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * A query action to get image information and upload history.
29 *
30 * @ingroup API
31 */
32 class ApiQueryImageInfo extends ApiQueryBase {
33 const TRANSFORM_LIMIT = 50;
34 private static $transformCount = 0;
35
36 public function __construct( $query, $moduleName, $prefix = 'ii' ) {
37 // We allow a subclass to override the prefix, to create a related API module.
38 // Some other parts of MediaWiki construct this with a null $prefix, which used to be ignored when this only took two arguments
39 if ( is_null( $prefix ) ) {
40 $prefix = 'ii';
41 }
42 parent::__construct( $query, $moduleName, $prefix );
43 }
44
45 public function execute() {
46 $params = $this->extractRequestParams();
47
48 $prop = array_flip( $params['prop'] );
49
50 $scale = $this->getScale( $params );
51
52 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
53 if ( !empty( $pageIds[NS_FILE] ) ) {
54 $titles = array_keys( $pageIds[NS_FILE] );
55 asort( $titles ); // Ensure the order is always the same
56
57 $fromTitle = null;
58 if ( !is_null( $params['continue'] ) ) {
59 $cont = explode( '|', $params['continue'] );
60 $this->dieContinueUsageIf( count( $cont ) != 2 );
61 $fromTitle = strval( $cont[0] );
62 $fromTimestamp = $cont[1];
63 // Filter out any titles before $fromTitle
64 foreach ( $titles as $key => $title ) {
65 if ( $title < $fromTitle ) {
66 unset( $titles[$key] );
67 } else {
68 break;
69 }
70 }
71 }
72
73 $result = $this->getResult();
74 //search only inside the local repo
75 if ( $params['localonly'] ) {
76 $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $titles );
77 } else {
78 $images = RepoGroup::singleton()->findFiles( $titles );
79 }
80 foreach ( $titles as $title ) {
81 $pageId = $pageIds[NS_FILE][$title];
82 $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
83
84 if ( !isset( $images[$title] ) ) {
85 $result->addValue(
86 array( 'query', 'pages', intval( $pageId ) ),
87 'imagerepository', ''
88 );
89 // The above can't fail because it doesn't increase the result size
90 continue;
91 }
92
93 /** @var $img File */
94 $img = $images[$title];
95
96 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
97 if ( count( $pageIds[NS_FILE] ) == 1 ) {
98 // See the 'the user is screwed' comment below
99 $this->setContinueEnumParameter( 'start',
100 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
101 );
102 } else {
103 $this->setContinueEnumParameter( 'continue',
104 $this->getContinueStr( $img, $start ) );
105 }
106 break;
107 }
108
109 $fit = $result->addValue(
110 array( 'query', 'pages', intval( $pageId ) ),
111 'imagerepository', $img->getRepoName()
112 );
113 if ( !$fit ) {
114 if ( count( $pageIds[NS_FILE] ) == 1 ) {
115 // The user is screwed. imageinfo can't be solely
116 // responsible for exceeding the limit in this case,
117 // so set a query-continue that just returns the same
118 // thing again. When the violating queries have been
119 // out-continued, the result will get through
120 $this->setContinueEnumParameter( 'start',
121 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
122 );
123 } else {
124 $this->setContinueEnumParameter( 'continue',
125 $this->getContinueStr( $img, $start ) );
126 }
127 break;
128 }
129
130 // Check if we can make the requested thumbnail, and get transform parameters.
131 $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
132
133 // Get information about the current version first
134 // Check that the current version is within the start-end boundaries
135 $gotOne = false;
136 if (
137 ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
138 ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
139 ) {
140 $gotOne = true;
141
142 $fit = $this->addPageSubItem( $pageId,
143 self::getInfo( $img, $prop, $result,
144 $finalThumbParams, $params['metadataversion'] ) );
145 if ( !$fit ) {
146 if ( count( $pageIds[NS_FILE] ) == 1 ) {
147 // See the 'the user is screwed' comment above
148 $this->setContinueEnumParameter( 'start',
149 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
150 } else {
151 $this->setContinueEnumParameter( 'continue',
152 $this->getContinueStr( $img ) );
153 }
154 break;
155 }
156 }
157
158 // Now get the old revisions
159 // Get one more to facilitate query-continue functionality
160 $count = ( $gotOne ? 1 : 0 );
161 $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
162 /** @var $oldie File */
163 foreach ( $oldies as $oldie ) {
164 if ( ++$count > $params['limit'] ) {
165 // We've reached the extra one which shows that there are additional pages to be had. Stop here...
166 // Only set a query-continue if there was only one title
167 if ( count( $pageIds[NS_FILE] ) == 1 ) {
168 $this->setContinueEnumParameter( 'start',
169 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
170 }
171 break;
172 }
173 $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
174 $this->addPageSubItem( $pageId,
175 self::getInfo( $oldie, $prop, $result,
176 $finalThumbParams, $params['metadataversion']
177 )
178 );
179 if ( !$fit ) {
180 if ( count( $pageIds[NS_FILE] ) == 1 ) {
181 $this->setContinueEnumParameter( 'start',
182 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
183 } else {
184 $this->setContinueEnumParameter( 'continue',
185 $this->getContinueStr( $oldie ) );
186 }
187 break;
188 }
189 }
190 if ( !$fit ) {
191 break;
192 }
193 }
194 }
195 }
196
197 /**
198 * From parameters, construct a 'scale' array
199 * @param array $params Parameters passed to api.
200 * @return Array or Null: key-val array of 'width' and 'height', or null
201 */
202 public function getScale( $params ) {
203 $p = $this->getModulePrefix();
204
205 if ( $params['urlwidth'] != -1 ) {
206 $scale = array();
207 $scale['width'] = $params['urlwidth'];
208 $scale['height'] = $params['urlheight'];
209 } elseif ( $params['urlheight'] != -1 ) {
210 // Height is specified but width isn't
211 // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
212 $scale = array();
213 $scale['height'] = $params['urlheight'];
214 } else {
215 $scale = null;
216 if ( $params['urlparam'] ) {
217 $this->dieUsage( "{$p}urlparam requires {$p}urlwidth", "urlparam_no_width" );
218 }
219 }
220
221 return $scale;
222 }
223
224 /** Validate and merge scale parameters with handler thumb parameters, give error if invalid.
225 *
226 * We do this later than getScale, since we need the image
227 * to know which handler, since handlers can make their own parameters.
228 * @param File $image Image that params are for.
229 * @param array $thumbParams thumbnail parameters from getScale
230 * @param string $otherParams of otherParams (iiurlparam).
231 * @return Array of parameters for transform.
232 */
233 protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
234
235 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
236 // Populate the width with the image's width, so only the height restriction applies
237 $thumbParams['width'] = $image->getWidth();
238 }
239
240 if ( !$otherParams ) {
241 return $thumbParams;
242 }
243 $p = $this->getModulePrefix();
244
245 $h = $image->getHandler();
246 if ( !$h ) {
247 $this->setWarning( 'Could not create thumbnail because ' .
248 $image->getName() . ' does not have an associated image handler' );
249 return $thumbParams;
250 }
251
252 $paramList = $h->parseParamString( $otherParams );
253 if ( !$paramList ) {
254 // Just set a warning (instead of dieUsage), as in many cases
255 // we could still render the image using width and height parameters,
256 // and this type of thing could happen between different versions of
257 // handlers.
258 $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
259 . '. Using only width and height' );
260 return $thumbParams;
261 }
262
263 if ( isset( $paramList['width'] ) ) {
264 if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
265 $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
266 . "in favor of width value derived from {$p}urlwidth/{$p}urlheight ({$thumbParams['width']})" );
267 }
268 }
269
270 foreach ( $paramList as $name => $value ) {
271 if ( !$h->validateParam( $name, $value ) ) {
272 $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" );
273 }
274 }
275
276 return $thumbParams + $paramList;
277 }
278
279 /**
280 * Get result information for an image revision
281 *
282 * @param $file File object
283 * @param array $prop of properties to get (in the keys)
284 * @param $result ApiResult object
285 * @param array $thumbParams containing 'width' and 'height' items, or null
286 * @param string $version Version of image metadata (for things like jpeg which have different versions).
287 * @return Array: result array
288 */
289 static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) {
290 $vals = array();
291 // Timestamp is shown even if the file is revdelete'd in interface
292 // so do same here.
293 if ( isset( $prop['timestamp'] ) ) {
294 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
295 }
296
297 $user = isset( $prop['user'] );
298 $userid = isset( $prop['userid'] );
299
300 if ( $user || $userid ) {
301 if ( $file->isDeleted( File::DELETED_USER ) ) {
302 $vals['userhidden'] = '';
303 } else {
304 if ( $user ) {
305 $vals['user'] = $file->getUser();
306 }
307 if ( $userid ) {
308 $vals['userid'] = $file->getUser( 'id' );
309 }
310 if ( !$file->getUser( 'id' ) ) {
311 $vals['anon'] = '';
312 }
313 }
314 }
315
316 // This is shown even if the file is revdelete'd in interface
317 // so do same here.
318 if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
319 $vals['size'] = intval( $file->getSize() );
320 $vals['width'] = intval( $file->getWidth() );
321 $vals['height'] = intval( $file->getHeight() );
322
323 $pageCount = $file->pageCount();
324 if ( $pageCount !== false ) {
325 $vals['pagecount'] = $pageCount;
326 }
327 }
328
329 $pcomment = isset( $prop['parsedcomment'] );
330 $comment = isset( $prop['comment'] );
331
332 if ( $pcomment || $comment ) {
333 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
334 $vals['commenthidden'] = '';
335 } else {
336 if ( $pcomment ) {
337 $vals['parsedcomment'] = Linker::formatComment(
338 $file->getDescription(), $file->getTitle() );
339 }
340 if ( $comment ) {
341 $vals['comment'] = $file->getDescription();
342 }
343 }
344 }
345
346 $url = isset( $prop['url'] );
347 $sha1 = isset( $prop['sha1'] );
348 $meta = isset( $prop['metadata'] );
349 $mime = isset( $prop['mime'] );
350 $mediatype = isset( $prop['mediatype'] );
351 $archive = isset( $prop['archivename'] );
352 $bitdepth = isset( $prop['bitdepth'] );
353
354 if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
355 && $file->isDeleted( File::DELETED_FILE ) ) {
356 $vals['filehidden'] = '';
357
358 //Early return, tidier than indenting all following things one level
359 return $vals;
360 }
361
362 if ( $url ) {
363 if ( !is_null( $thumbParams ) ) {
364 $mto = $file->transform( $thumbParams );
365 self::$transformCount++;
366 if ( $mto && !$mto->isError() ) {
367 $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
368
369 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
370 // thumbnail sizes for the thumbnail actual size
371 if ( $mto->getUrl() !== $file->getUrl() ) {
372 $vals['thumbwidth'] = intval( $mto->getWidth() );
373 $vals['thumbheight'] = intval( $mto->getHeight() );
374 } else {
375 $vals['thumbwidth'] = intval( $file->getWidth() );
376 $vals['thumbheight'] = intval( $file->getHeight() );
377 }
378
379 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
380 list( , $mime ) = $file->getHandler()->getThumbType(
381 $mto->getExtension(), $file->getMimeType(), $thumbParams );
382 $vals['thumbmime'] = $mime;
383 }
384 } elseif ( $mto && $mto->isError() ) {
385 $vals['thumberror'] = $mto->toText();
386 }
387 }
388 $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
389 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
390 }
391
392 if ( $sha1 ) {
393 $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
394 }
395
396 if ( $meta ) {
397 wfSuppressWarnings();
398 $metadata = unserialize( $file->getMetadata() );
399 wfRestoreWarnings();
400 if ( $metadata && $version !== 'latest' ) {
401 $metadata = $file->convertMetadataVersion( $metadata, $version );
402 }
403 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
404 }
405
406 if ( $mime ) {
407 $vals['mime'] = $file->getMimeType();
408 }
409
410 if ( $mediatype ) {
411 $vals['mediatype'] = $file->getMediaType();
412 }
413
414 if ( $archive && $file->isOld() ) {
415 $vals['archivename'] = $file->getArchiveName();
416 }
417
418 if ( $bitdepth ) {
419 $vals['bitdepth'] = $file->getBitDepth();
420 }
421
422 return $vals;
423 }
424
425 /**
426 * Get the count of image transformations performed
427 *
428 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
429 *
430 * @return integer count
431 */
432 static function getTransformCount() {
433 return self::$transformCount;
434 }
435
436 /**
437 *
438 * @param $metadata Array
439 * @param $result ApiResult
440 * @return Array
441 */
442 public static function processMetaData( $metadata, $result ) {
443 $retval = array();
444 if ( is_array( $metadata ) ) {
445 foreach ( $metadata as $key => $value ) {
446 $r = array( 'name' => $key );
447 if ( is_array( $value ) ) {
448 $r['value'] = self::processMetaData( $value, $result );
449 } else {
450 $r['value'] = $value;
451 }
452 $retval[] = $r;
453 }
454 }
455 $result->setIndexedTagName( $retval, 'metadata' );
456 return $retval;
457 }
458
459 public function getCacheMode( $params ) {
460 return 'public';
461 }
462
463 /**
464 * @param $img File
465 * @param null|string $start
466 * @return string
467 */
468 protected function getContinueStr( $img, $start = null ) {
469 if ( $start === null ) {
470 $start = $img->getTimestamp();
471 }
472 return $img->getOriginalTitle()->getText() . '|' . $start;
473 }
474
475 public function getAllowedParams() {
476 return array(
477 'prop' => array(
478 ApiBase::PARAM_ISMULTI => true,
479 ApiBase::PARAM_DFLT => 'timestamp|user',
480 ApiBase::PARAM_TYPE => self::getPropertyNames()
481 ),
482 'limit' => array(
483 ApiBase::PARAM_TYPE => 'limit',
484 ApiBase::PARAM_DFLT => 1,
485 ApiBase::PARAM_MIN => 1,
486 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
487 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
488 ),
489 'start' => array(
490 ApiBase::PARAM_TYPE => 'timestamp'
491 ),
492 'end' => array(
493 ApiBase::PARAM_TYPE => 'timestamp'
494 ),
495 'urlwidth' => array(
496 ApiBase::PARAM_TYPE => 'integer',
497 ApiBase::PARAM_DFLT => -1
498 ),
499 'urlheight' => array(
500 ApiBase::PARAM_TYPE => 'integer',
501 ApiBase::PARAM_DFLT => -1
502 ),
503 'metadataversion' => array(
504 ApiBase::PARAM_TYPE => 'string',
505 ApiBase::PARAM_DFLT => '1',
506 ),
507 'urlparam' => array(
508 ApiBase::PARAM_DFLT => '',
509 ApiBase::PARAM_TYPE => 'string',
510 ),
511 'continue' => null,
512 'localonly' => false,
513 );
514 }
515
516 /**
517 * Returns all possible parameters to iiprop
518 *
519 * @param array $filter List of properties to filter out
520 *
521 * @return Array
522 */
523 public static function getPropertyNames( $filter = array() ) {
524 return array_diff( array_keys( self::getProperties() ), $filter );
525 }
526
527 /**
528 * Returns array key value pairs of properties and their descriptions
529 *
530 * @param string $modulePrefix
531 * @return array
532 */
533 private static function getProperties( $modulePrefix = '' ) {
534 return array(
535 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
536 'user' => ' user - Adds the user who uploaded the image version',
537 'userid' => ' userid - Add the user ID that uploaded the image version',
538 'comment' => ' comment - Comment on the version',
539 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
540 'url' => ' url - Gives URL to the image and the description page',
541 'size' => ' size - Adds the size of the image in bytes and the height, width and page count (if applicable)',
542 'dimensions' => ' dimensions - Alias for size', // For backwards compatibility with Allimages
543 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
544 'mime' => ' mime - Adds MIME type of the image',
545 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
546 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
547 'mediatype' => ' mediatype - Adds the media type of the image',
548 'metadata' => ' metadata - Lists EXIF metadata for the version of the image',
549 'archivename' => ' archivename - Adds the file name of the archive version for non-latest versions',
550 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
551 );
552 }
553
554 /**
555 * Returns the descriptions for the properties provided by getPropertyNames()
556 *
557 * @param array $filter List of properties to filter out
558 * @param string $modulePrefix
559 * @return array
560 */
561 public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
562 return array_merge(
563 array( 'What image information to get:' ),
564 array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
565 );
566 }
567
568 /**
569 * Return the API documentation for the parameters.
570 * @return Array parameter documentation.
571 */
572 public function getParamDescription() {
573 $p = $this->getModulePrefix();
574 return array(
575 'prop' => self::getPropertyDescriptions( array(), $p ),
576 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
577 'For performance reasons if this option is used, ' .
578 'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.' ),
579 'urlheight' => "Similar to {$p}urlwidth.",
580 'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
581 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
582 'limit' => 'How many image revisions to return per image',
583 'start' => 'Timestamp to start listing from',
584 'end' => 'Timestamp to stop listing at',
585 'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
586 "Defaults to '1' for backwards compatibility" ),
587 'continue' => 'If the query response includes a continue value, use it here to get another page of results',
588 'localonly' => 'Look only for files in the local repository',
589 );
590 }
591
592 public static function getResultPropertiesFiltered( $filter = array() ) {
593 $props = array(
594 'timestamp' => array(
595 'timestamp' => 'timestamp'
596 ),
597 'user' => array(
598 'userhidden' => 'boolean',
599 'user' => 'string',
600 'anon' => 'boolean'
601 ),
602 'userid' => array(
603 'userhidden' => 'boolean',
604 'userid' => 'integer',
605 'anon' => 'boolean'
606 ),
607 'size' => array(
608 'size' => 'integer',
609 'width' => 'integer',
610 'height' => 'integer',
611 'pagecount' => array(
612 ApiBase::PROP_TYPE => 'integer',
613 ApiBase::PROP_NULLABLE => true
614 )
615 ),
616 'dimensions' => array(
617 'size' => 'integer',
618 'width' => 'integer',
619 'height' => 'integer',
620 'pagecount' => array(
621 ApiBase::PROP_TYPE => 'integer',
622 ApiBase::PROP_NULLABLE => true
623 )
624 ),
625 'comment' => array(
626 'commenthidden' => 'boolean',
627 'comment' => array(
628 ApiBase::PROP_TYPE => 'string',
629 ApiBase::PROP_NULLABLE => true
630 )
631 ),
632 'parsedcomment' => array(
633 'commenthidden' => 'boolean',
634 'parsedcomment' => array(
635 ApiBase::PROP_TYPE => 'string',
636 ApiBase::PROP_NULLABLE => true
637 )
638 ),
639 'url' => array(
640 'filehidden' => 'boolean',
641 'thumburl' => array(
642 ApiBase::PROP_TYPE => 'string',
643 ApiBase::PROP_NULLABLE => true
644 ),
645 'thumbwidth' => array(
646 ApiBase::PROP_TYPE => 'integer',
647 ApiBase::PROP_NULLABLE => true
648 ),
649 'thumbheight' => array(
650 ApiBase::PROP_TYPE => 'integer',
651 ApiBase::PROP_NULLABLE => true
652 ),
653 'thumberror' => array(
654 ApiBase::PROP_TYPE => 'string',
655 ApiBase::PROP_NULLABLE => true
656 ),
657 'url' => array(
658 ApiBase::PROP_TYPE => 'string',
659 ApiBase::PROP_NULLABLE => true
660 ),
661 'descriptionurl' => array(
662 ApiBase::PROP_TYPE => 'string',
663 ApiBase::PROP_NULLABLE => true
664 )
665 ),
666 'sha1' => array(
667 'filehidden' => 'boolean',
668 'sha1' => array(
669 ApiBase::PROP_TYPE => 'string',
670 ApiBase::PROP_NULLABLE => true
671 )
672 ),
673 'mime' => array(
674 'filehidden' => 'boolean',
675 'mime' => array(
676 ApiBase::PROP_TYPE => 'string',
677 ApiBase::PROP_NULLABLE => true
678 )
679 ),
680 'thumbmime' => array(
681 'filehidden' => 'boolean',
682 'thumbmime' => array(
683 ApiBase::PROP_TYPE => 'string',
684 ApiBase::PROP_NULLABLE => true
685 )
686 ),
687 'mediatype' => array(
688 'filehidden' => 'boolean',
689 'mediatype' => array(
690 ApiBase::PROP_TYPE => 'string',
691 ApiBase::PROP_NULLABLE => true
692 )
693 ),
694 'archivename' => array(
695 'filehidden' => 'boolean',
696 'archivename' => array(
697 ApiBase::PROP_TYPE => 'string',
698 ApiBase::PROP_NULLABLE => true
699 )
700 ),
701 'bitdepth' => array(
702 'filehidden' => 'boolean',
703 'bitdepth' => array(
704 ApiBase::PROP_TYPE => 'integer',
705 ApiBase::PROP_NULLABLE => true
706 )
707 ),
708 );
709 return array_diff_key( $props, array_flip( $filter ) );
710 }
711
712 public function getResultProperties() {
713 return self::getResultPropertiesFiltered();
714 }
715
716 public function getDescription() {
717 return 'Returns image information and upload history';
718 }
719
720 public function getPossibleErrors() {
721 $p = $this->getModulePrefix();
722 return array_merge( parent::getPossibleErrors(), array(
723 array( 'code' => "{$p}urlwidth", 'info' => "{$p}urlheight cannot be used without {$p}urlwidth" ),
724 array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ),
725 array( 'code' => 'urlparam_no_width', 'info' => "{$p}urlparam requires {$p}urlwidth" ),
726 ) );
727 }
728
729 public function getExamples() {
730 return array(
731 'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
732 'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&iiend=20071231235959&iiprop=timestamp|user|url',
733 );
734 }
735
736 public function getHelpUrls() {
737 return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';
738 }
739 }