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