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