Merge "DifferenceEngine: Remove broken comment"
[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 global $wgThumbLimits;
235
236 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
237 // We want to limit only by height in this situation, so pass the
238 // image's full width as the limiting width. But some file types
239 // don't have a width of their own, so pick something arbitrary so
240 // thumbnailing the default icon works.
241 if ( $image->getWidth() <= 0 ) {
242 $thumbParams['width'] = max( $wgThumbLimits );
243 } else {
244 $thumbParams['width'] = $image->getWidth();
245 }
246 }
247
248 if ( !$otherParams ) {
249 return $thumbParams;
250 }
251 $p = $this->getModulePrefix();
252
253 $h = $image->getHandler();
254 if ( !$h ) {
255 $this->setWarning( 'Could not create thumbnail because ' .
256 $image->getName() . ' does not have an associated image handler' );
257 return $thumbParams;
258 }
259
260 $paramList = $h->parseParamString( $otherParams );
261 if ( !$paramList ) {
262 // Just set a warning (instead of dieUsage), as in many cases
263 // we could still render the image using width and height parameters,
264 // and this type of thing could happen between different versions of
265 // handlers.
266 $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
267 . '. Using only width and height' );
268 return $thumbParams;
269 }
270
271 if ( isset( $paramList['width'] ) ) {
272 if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
273 $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
274 . "in favor of width value derived from {$p}urlwidth/{$p}urlheight ({$thumbParams['width']})" );
275 }
276 }
277
278 foreach ( $paramList as $name => $value ) {
279 if ( !$h->validateParam( $name, $value ) ) {
280 $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" );
281 }
282 }
283
284 return $thumbParams + $paramList;
285 }
286
287 /**
288 * Get result information for an image revision
289 *
290 * @param $file File object
291 * @param array $prop of properties to get (in the keys)
292 * @param $result ApiResult object
293 * @param array $thumbParams containing 'width' and 'height' items, or null
294 * @param string $version Version of image metadata (for things like jpeg which have different versions).
295 * @return Array: result array
296 */
297 static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) {
298 $vals = array();
299 // Timestamp is shown even if the file is revdelete'd in interface
300 // so do same here.
301 if ( isset( $prop['timestamp'] ) ) {
302 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
303 }
304
305 $user = isset( $prop['user'] );
306 $userid = isset( $prop['userid'] );
307
308 if ( $user || $userid ) {
309 if ( $file->isDeleted( File::DELETED_USER ) ) {
310 $vals['userhidden'] = '';
311 } else {
312 if ( $user ) {
313 $vals['user'] = $file->getUser();
314 }
315 if ( $userid ) {
316 $vals['userid'] = $file->getUser( 'id' );
317 }
318 if ( !$file->getUser( 'id' ) ) {
319 $vals['anon'] = '';
320 }
321 }
322 }
323
324 // This is shown even if the file is revdelete'd in interface
325 // so do same here.
326 if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
327 $vals['size'] = intval( $file->getSize() );
328 $vals['width'] = intval( $file->getWidth() );
329 $vals['height'] = intval( $file->getHeight() );
330
331 $pageCount = $file->pageCount();
332 if ( $pageCount !== false ) {
333 $vals['pagecount'] = $pageCount;
334 }
335 }
336
337 $pcomment = isset( $prop['parsedcomment'] );
338 $comment = isset( $prop['comment'] );
339
340 if ( $pcomment || $comment ) {
341 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
342 $vals['commenthidden'] = '';
343 } else {
344 if ( $pcomment ) {
345 $vals['parsedcomment'] = Linker::formatComment(
346 $file->getDescription(), $file->getTitle() );
347 }
348 if ( $comment ) {
349 $vals['comment'] = $file->getDescription();
350 }
351 }
352 }
353
354 $url = isset( $prop['url'] );
355 $sha1 = isset( $prop['sha1'] );
356 $meta = isset( $prop['metadata'] );
357 $mime = isset( $prop['mime'] );
358 $mediatype = isset( $prop['mediatype'] );
359 $archive = isset( $prop['archivename'] );
360 $bitdepth = isset( $prop['bitdepth'] );
361
362 if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth )
363 && $file->isDeleted( File::DELETED_FILE ) ) {
364 $vals['filehidden'] = '';
365
366 //Early return, tidier than indenting all following things one level
367 return $vals;
368 }
369
370 if ( $url ) {
371 if ( !is_null( $thumbParams ) ) {
372 $mto = $file->transform( $thumbParams );
373 self::$transformCount++;
374 if ( $mto && !$mto->isError() ) {
375 $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
376
377 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
378 // thumbnail sizes for the thumbnail actual size
379 if ( $mto->getUrl() !== $file->getUrl() ) {
380 $vals['thumbwidth'] = intval( $mto->getWidth() );
381 $vals['thumbheight'] = intval( $mto->getHeight() );
382 } else {
383 $vals['thumbwidth'] = intval( $file->getWidth() );
384 $vals['thumbheight'] = intval( $file->getHeight() );
385 }
386
387 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
388 list( , $mime ) = $file->getHandler()->getThumbType(
389 $mto->getExtension(), $file->getMimeType(), $thumbParams );
390 $vals['thumbmime'] = $mime;
391 }
392 } elseif ( $mto && $mto->isError() ) {
393 $vals['thumberror'] = $mto->toText();
394 }
395 }
396 $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
397 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
398 }
399
400 if ( $sha1 ) {
401 $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
402 }
403
404 if ( $meta ) {
405 wfSuppressWarnings();
406 $metadata = unserialize( $file->getMetadata() );
407 wfRestoreWarnings();
408 if ( $metadata && $version !== 'latest' ) {
409 $metadata = $file->convertMetadataVersion( $metadata, $version );
410 }
411 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
412 }
413
414 if ( $mime ) {
415 $vals['mime'] = $file->getMimeType();
416 }
417
418 if ( $mediatype ) {
419 $vals['mediatype'] = $file->getMediaType();
420 }
421
422 if ( $archive && $file->isOld() ) {
423 $vals['archivename'] = $file->getArchiveName();
424 }
425
426 if ( $bitdepth ) {
427 $vals['bitdepth'] = $file->getBitDepth();
428 }
429
430 return $vals;
431 }
432
433 /**
434 * Get the count of image transformations performed
435 *
436 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
437 *
438 * @return integer count
439 */
440 static function getTransformCount() {
441 return self::$transformCount;
442 }
443
444 /**
445 *
446 * @param $metadata Array
447 * @param $result ApiResult
448 * @return Array
449 */
450 public static function processMetaData( $metadata, $result ) {
451 $retval = array();
452 if ( is_array( $metadata ) ) {
453 foreach ( $metadata as $key => $value ) {
454 $r = array( 'name' => $key );
455 if ( is_array( $value ) ) {
456 $r['value'] = self::processMetaData( $value, $result );
457 } else {
458 $r['value'] = $value;
459 }
460 $retval[] = $r;
461 }
462 }
463 $result->setIndexedTagName( $retval, 'metadata' );
464 return $retval;
465 }
466
467 public function getCacheMode( $params ) {
468 return 'public';
469 }
470
471 /**
472 * @param $img File
473 * @param null|string $start
474 * @return string
475 */
476 protected function getContinueStr( $img, $start = null ) {
477 if ( $start === null ) {
478 $start = $img->getTimestamp();
479 }
480 return $img->getOriginalTitle()->getDBkey() . '|' . $start;
481 }
482
483 public function getAllowedParams() {
484 return array(
485 'prop' => array(
486 ApiBase::PARAM_ISMULTI => true,
487 ApiBase::PARAM_DFLT => 'timestamp|user',
488 ApiBase::PARAM_TYPE => self::getPropertyNames()
489 ),
490 'limit' => array(
491 ApiBase::PARAM_TYPE => 'limit',
492 ApiBase::PARAM_DFLT => 1,
493 ApiBase::PARAM_MIN => 1,
494 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
495 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
496 ),
497 'start' => array(
498 ApiBase::PARAM_TYPE => 'timestamp'
499 ),
500 'end' => array(
501 ApiBase::PARAM_TYPE => 'timestamp'
502 ),
503 'urlwidth' => array(
504 ApiBase::PARAM_TYPE => 'integer',
505 ApiBase::PARAM_DFLT => -1
506 ),
507 'urlheight' => array(
508 ApiBase::PARAM_TYPE => 'integer',
509 ApiBase::PARAM_DFLT => -1
510 ),
511 'metadataversion' => array(
512 ApiBase::PARAM_TYPE => 'string',
513 ApiBase::PARAM_DFLT => '1',
514 ),
515 'urlparam' => array(
516 ApiBase::PARAM_DFLT => '',
517 ApiBase::PARAM_TYPE => 'string',
518 ),
519 'continue' => null,
520 'localonly' => false,
521 );
522 }
523
524 /**
525 * Returns all possible parameters to iiprop
526 *
527 * @param array $filter List of properties to filter out
528 *
529 * @return Array
530 */
531 public static function getPropertyNames( $filter = array() ) {
532 return array_diff( array_keys( self::getProperties() ), $filter );
533 }
534
535 /**
536 * Returns array key value pairs of properties and their descriptions
537 *
538 * @param string $modulePrefix
539 * @return array
540 */
541 private static function getProperties( $modulePrefix = '' ) {
542 return array(
543 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
544 'user' => ' user - Adds the user who uploaded the image version',
545 'userid' => ' userid - Add the user ID that uploaded the image version',
546 'comment' => ' comment - Comment on the version',
547 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
548 'url' => ' url - Gives URL to the image and the description page',
549 'size' => ' size - Adds the size of the image in bytes and the height, width and page count (if applicable)',
550 'dimensions' => ' dimensions - Alias for size', // For backwards compatibility with Allimages
551 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
552 'mime' => ' mime - Adds MIME type of the image',
553 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
554 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
555 'mediatype' => ' mediatype - Adds the media type of the image',
556 'metadata' => ' metadata - Lists Exif metadata for the version of the image',
557 'archivename' => ' archivename - Adds the file name of the archive version for non-latest versions',
558 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
559 );
560 }
561
562 /**
563 * Returns the descriptions for the properties provided by getPropertyNames()
564 *
565 * @param array $filter List of properties to filter out
566 * @param string $modulePrefix
567 * @return array
568 */
569 public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
570 return array_merge(
571 array( 'What image information to get:' ),
572 array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
573 );
574 }
575
576 /**
577 * Return the API documentation for the parameters.
578 * @return Array parameter documentation.
579 */
580 public function getParamDescription() {
581 $p = $this->getModulePrefix();
582 return array(
583 'prop' => self::getPropertyDescriptions( array(), $p ),
584 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
585 'For performance reasons if this option is used, ' .
586 'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.' ),
587 'urlheight' => "Similar to {$p}urlwidth.",
588 'urlparam' => array( "A handler specific parameter string. For example, pdf's ",
589 "might use 'page15-100px'. {$p}urlwidth must be used and be consistent with {$p}urlparam" ),
590 'limit' => 'How many image revisions to return per image',
591 'start' => 'Timestamp to start listing from',
592 'end' => 'Timestamp to stop listing at',
593 'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
594 "Defaults to '1' for backwards compatibility" ),
595 'continue' => 'If the query response includes a continue value, use it here to get another page of results',
596 'localonly' => 'Look only for files in the local repository',
597 );
598 }
599
600 public static function getResultPropertiesFiltered( $filter = array() ) {
601 $props = array(
602 'timestamp' => array(
603 'timestamp' => 'timestamp'
604 ),
605 'user' => array(
606 'userhidden' => 'boolean',
607 'user' => 'string',
608 'anon' => 'boolean'
609 ),
610 'userid' => array(
611 'userhidden' => 'boolean',
612 'userid' => 'integer',
613 'anon' => 'boolean'
614 ),
615 'size' => array(
616 'size' => 'integer',
617 'width' => 'integer',
618 'height' => 'integer',
619 'pagecount' => array(
620 ApiBase::PROP_TYPE => 'integer',
621 ApiBase::PROP_NULLABLE => true
622 )
623 ),
624 'dimensions' => array(
625 'size' => 'integer',
626 'width' => 'integer',
627 'height' => 'integer',
628 'pagecount' => array(
629 ApiBase::PROP_TYPE => 'integer',
630 ApiBase::PROP_NULLABLE => true
631 )
632 ),
633 'comment' => array(
634 'commenthidden' => 'boolean',
635 'comment' => array(
636 ApiBase::PROP_TYPE => 'string',
637 ApiBase::PROP_NULLABLE => true
638 )
639 ),
640 'parsedcomment' => array(
641 'commenthidden' => 'boolean',
642 'parsedcomment' => array(
643 ApiBase::PROP_TYPE => 'string',
644 ApiBase::PROP_NULLABLE => true
645 )
646 ),
647 'url' => array(
648 'filehidden' => 'boolean',
649 'thumburl' => array(
650 ApiBase::PROP_TYPE => 'string',
651 ApiBase::PROP_NULLABLE => true
652 ),
653 'thumbwidth' => array(
654 ApiBase::PROP_TYPE => 'integer',
655 ApiBase::PROP_NULLABLE => true
656 ),
657 'thumbheight' => array(
658 ApiBase::PROP_TYPE => 'integer',
659 ApiBase::PROP_NULLABLE => true
660 ),
661 'thumberror' => array(
662 ApiBase::PROP_TYPE => 'string',
663 ApiBase::PROP_NULLABLE => true
664 ),
665 'url' => array(
666 ApiBase::PROP_TYPE => 'string',
667 ApiBase::PROP_NULLABLE => true
668 ),
669 'descriptionurl' => array(
670 ApiBase::PROP_TYPE => 'string',
671 ApiBase::PROP_NULLABLE => true
672 )
673 ),
674 'sha1' => array(
675 'filehidden' => 'boolean',
676 'sha1' => array(
677 ApiBase::PROP_TYPE => 'string',
678 ApiBase::PROP_NULLABLE => true
679 )
680 ),
681 'mime' => array(
682 'filehidden' => 'boolean',
683 'mime' => array(
684 ApiBase::PROP_TYPE => 'string',
685 ApiBase::PROP_NULLABLE => true
686 )
687 ),
688 'thumbmime' => array(
689 'filehidden' => 'boolean',
690 'thumbmime' => array(
691 ApiBase::PROP_TYPE => 'string',
692 ApiBase::PROP_NULLABLE => true
693 )
694 ),
695 'mediatype' => array(
696 'filehidden' => 'boolean',
697 'mediatype' => array(
698 ApiBase::PROP_TYPE => 'string',
699 ApiBase::PROP_NULLABLE => true
700 )
701 ),
702 'archivename' => array(
703 'filehidden' => 'boolean',
704 'archivename' => array(
705 ApiBase::PROP_TYPE => 'string',
706 ApiBase::PROP_NULLABLE => true
707 )
708 ),
709 'bitdepth' => array(
710 'filehidden' => 'boolean',
711 'bitdepth' => array(
712 ApiBase::PROP_TYPE => 'integer',
713 ApiBase::PROP_NULLABLE => true
714 )
715 ),
716 );
717 return array_diff_key( $props, array_flip( $filter ) );
718 }
719
720 public function getResultProperties() {
721 return self::getResultPropertiesFiltered();
722 }
723
724 public function getDescription() {
725 return 'Returns image information and upload history';
726 }
727
728 public function getPossibleErrors() {
729 $p = $this->getModulePrefix();
730 return array_merge( parent::getPossibleErrors(), array(
731 array( 'code' => "{$p}urlwidth", 'info' => "{$p}urlheight cannot be used without {$p}urlwidth" ),
732 array( 'code' => 'urlparam', 'info' => "Invalid value for {$p}urlparam" ),
733 array( 'code' => 'urlparam_no_width', 'info' => "{$p}urlparam requires {$p}urlwidth" ),
734 ) );
735 }
736
737 public function getExamples() {
738 return array(
739 'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
740 'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&iiend=20071231235959&iiprop=timestamp|user|url',
741 );
742 }
743
744 public function getHelpUrls() {
745 return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';
746 }
747 }