Merge "Fully replace Title::moveTo() with MovePage"
[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( ApiQuery $query, $moduleName, $prefix = 'ii' ) {
37 // We allow a subclass to override the prefix, to create a related API
38 // module. Some other parts of MediaWiki construct this with a null
39 // $prefix, which used to be ignored when this only took two arguments
40 if ( is_null( $prefix ) ) {
41 $prefix = 'ii';
42 }
43 parent::__construct( $query, $moduleName, $prefix );
44 }
45
46 public function execute() {
47 $params = $this->extractRequestParams();
48
49 $prop = array_flip( $params['prop'] );
50
51 $scale = $this->getScale( $params );
52
53 $opts = array(
54 'version' => $params['metadataversion'],
55 'language' => $params['extmetadatalanguage'],
56 'multilang' => $params['extmetadatamultilang'],
57 'extmetadatafilter' => $params['extmetadatafilter'],
58 'revdelUser' => $this->getUser(),
59 );
60
61 $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
62 if ( !empty( $pageIds[NS_FILE] ) ) {
63 $titles = array_keys( $pageIds[NS_FILE] );
64 asort( $titles ); // Ensure the order is always the same
65
66 $fromTitle = null;
67 if ( !is_null( $params['continue'] ) ) {
68 $cont = explode( '|', $params['continue'] );
69 $this->dieContinueUsageIf( count( $cont ) != 2 );
70 $fromTitle = strval( $cont[0] );
71 $fromTimestamp = $cont[1];
72 // Filter out any titles before $fromTitle
73 foreach ( $titles as $key => $title ) {
74 if ( $title < $fromTitle ) {
75 unset( $titles[$key] );
76 } else {
77 break;
78 }
79 }
80 }
81
82 $user = $this->getUser();
83 $findTitles = array_map( function ( $title ) use ( $user ) {
84 return array(
85 'title' => $title,
86 'private' => $user,
87 );
88 }, $titles );
89
90 if ( $params['localonly'] ) {
91 $images = RepoGroup::singleton()->getLocalRepo()->findFiles( $findTitles );
92 } else {
93 $images = RepoGroup::singleton()->findFiles( $findTitles );
94 }
95
96 $result = $this->getResult();
97 foreach ( $titles as $title ) {
98 $pageId = $pageIds[NS_FILE][$title];
99 $start = $title === $fromTitle ? $fromTimestamp : $params['start'];
100
101 if ( !isset( $images[$title] ) ) {
102 if ( isset( $prop['uploadwarning'] ) ) {
103 // Uploadwarning needs info about non-existing files
104 $images[$title] = wfLocalFile( $title );
105 } else {
106 $result->addValue(
107 array( 'query', 'pages', intval( $pageId ) ),
108 'imagerepository', ''
109 );
110 // The above can't fail because it doesn't increase the result size
111 continue;
112 }
113 }
114
115 /** @var $img File */
116 $img = $images[$title];
117
118 if ( self::getTransformCount() >= self::TRANSFORM_LIMIT ) {
119 if ( count( $pageIds[NS_FILE] ) == 1 ) {
120 // See the 'the user is screwed' comment below
121 $this->setContinueEnumParameter( 'start',
122 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
123 );
124 } else {
125 $this->setContinueEnumParameter( 'continue',
126 $this->getContinueStr( $img, $start ) );
127 }
128 break;
129 }
130
131 $fit = $result->addValue(
132 array( 'query', 'pages', intval( $pageId ) ),
133 'imagerepository', $img->getRepoName()
134 );
135 if ( !$fit ) {
136 if ( count( $pageIds[NS_FILE] ) == 1 ) {
137 // The user is screwed. imageinfo can't be solely
138 // responsible for exceeding the limit in this case,
139 // so set a query-continue that just returns the same
140 // thing again. When the violating queries have been
141 // out-continued, the result will get through
142 $this->setContinueEnumParameter( 'start',
143 $start !== null ? $start : wfTimestamp( TS_ISO_8601, $img->getTimestamp() )
144 );
145 } else {
146 $this->setContinueEnumParameter( 'continue',
147 $this->getContinueStr( $img, $start ) );
148 }
149 break;
150 }
151
152 // Check if we can make the requested thumbnail, and get transform parameters.
153 $finalThumbParams = $this->mergeThumbParams( $img, $scale, $params['urlparam'] );
154
155 // Get information about the current version first
156 // Check that the current version is within the start-end boundaries
157 $gotOne = false;
158 if (
159 ( is_null( $start ) || $img->getTimestamp() <= $start ) &&
160 ( is_null( $params['end'] ) || $img->getTimestamp() >= $params['end'] )
161 ) {
162 $gotOne = true;
163
164 $fit = $this->addPageSubItem( $pageId,
165 self::getInfo( $img, $prop, $result,
166 $finalThumbParams, $opts
167 )
168 );
169 if ( !$fit ) {
170 if ( count( $pageIds[NS_FILE] ) == 1 ) {
171 // See the 'the user is screwed' comment above
172 $this->setContinueEnumParameter( 'start',
173 wfTimestamp( TS_ISO_8601, $img->getTimestamp() ) );
174 } else {
175 $this->setContinueEnumParameter( 'continue',
176 $this->getContinueStr( $img ) );
177 }
178 break;
179 }
180 }
181
182 // Now get the old revisions
183 // Get one more to facilitate query-continue functionality
184 $count = ( $gotOne ? 1 : 0 );
185 $oldies = $img->getHistory( $params['limit'] - $count + 1, $start, $params['end'] );
186 /** @var $oldie File */
187 foreach ( $oldies as $oldie ) {
188 if ( ++$count > $params['limit'] ) {
189 // We've reached the extra one which shows that there are
190 // additional pages to be had. Stop here...
191 // Only set a query-continue if there was only one title
192 if ( count( $pageIds[NS_FILE] ) == 1 ) {
193 $this->setContinueEnumParameter( 'start',
194 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
195 }
196 break;
197 }
198 $fit = self::getTransformCount() < self::TRANSFORM_LIMIT &&
199 $this->addPageSubItem( $pageId,
200 self::getInfo( $oldie, $prop, $result,
201 $finalThumbParams, $opts
202 )
203 );
204 if ( !$fit ) {
205 if ( count( $pageIds[NS_FILE] ) == 1 ) {
206 $this->setContinueEnumParameter( 'start',
207 wfTimestamp( TS_ISO_8601, $oldie->getTimestamp() ) );
208 } else {
209 $this->setContinueEnumParameter( 'continue',
210 $this->getContinueStr( $oldie ) );
211 }
212 break;
213 }
214 }
215 if ( !$fit ) {
216 break;
217 }
218 }
219 }
220 }
221
222 /**
223 * From parameters, construct a 'scale' array
224 * @param array $params Parameters passed to api.
225 * @return array|null Key-val array of 'width' and 'height', or null
226 */
227 public function getScale( $params ) {
228 $p = $this->getModulePrefix();
229
230 if ( $params['urlwidth'] != -1 ) {
231 $scale = array();
232 $scale['width'] = $params['urlwidth'];
233 $scale['height'] = $params['urlheight'];
234 } elseif ( $params['urlheight'] != -1 ) {
235 // Height is specified but width isn't
236 // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
237 $scale = array();
238 $scale['height'] = $params['urlheight'];
239 } else {
240 if ( $params['urlparam'] ) {
241 // Audio files might not have a width/height.
242 $scale = array();
243 } else {
244 $scale = null;
245 }
246 }
247
248 return $scale;
249 }
250
251 /** Validate and merge scale parameters with handler thumb parameters, give error if invalid.
252 *
253 * We do this later than getScale, since we need the image
254 * to know which handler, since handlers can make their own parameters.
255 * @param File $image Image that params are for.
256 * @param array $thumbParams Thumbnail parameters from getScale
257 * @param string $otherParams String of otherParams (iiurlparam).
258 * @return array Array of parameters for transform.
259 */
260 protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
261 if ( $thumbParams === null ) {
262 // No scaling requested
263 return null;
264 }
265 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
266 // We want to limit only by height in this situation, so pass the
267 // image's full width as the limiting width. But some file types
268 // don't have a width of their own, so pick something arbitrary so
269 // thumbnailing the default icon works.
270 if ( $image->getWidth() <= 0 ) {
271 $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
272 } else {
273 $thumbParams['width'] = $image->getWidth();
274 }
275 }
276
277 if ( !$otherParams ) {
278 $this->checkParameterNormalise( $image, $thumbParams );
279 return $thumbParams;
280 }
281 $p = $this->getModulePrefix();
282
283 $h = $image->getHandler();
284 if ( !$h ) {
285 $this->setWarning( 'Could not create thumbnail because ' .
286 $image->getName() . ' does not have an associated image handler' );
287
288 return $thumbParams;
289 }
290
291 $paramList = $h->parseParamString( $otherParams );
292 if ( !$paramList ) {
293 // Just set a warning (instead of dieUsage), as in many cases
294 // we could still render the image using width and height parameters,
295 // and this type of thing could happen between different versions of
296 // handlers.
297 $this->setWarning( "Could not parse {$p}urlparam for " . $image->getName()
298 . '. Using only width and height' );
299 $this->checkParameterNormalise( $image, $thumbParams );
300 return $thumbParams;
301 }
302
303 if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
304 if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
305 $this->setWarning( "Ignoring width value set in {$p}urlparam ({$paramList['width']}) "
306 . "in favor of width value derived from {$p}urlwidth/{$p}urlheight "
307 . "({$thumbParams['width']})" );
308 }
309 }
310
311 foreach ( $paramList as $name => $value ) {
312 if ( !$h->validateParam( $name, $value ) ) {
313 $this->dieUsage( "Invalid value for {$p}urlparam ($name=$value)", "urlparam" );
314 }
315 }
316
317 $finalParams = $thumbParams + $paramList;
318 $this->checkParameterNormalise( $image, $finalParams );
319 return $finalParams;
320 }
321
322 /**
323 * Verify that the final image parameters can be normalised.
324 *
325 * This doesn't use the normalised parameters, since $file->transform
326 * expects the pre-normalised parameters, but doing the normalisation
327 * allows us to catch certain error conditions early (such as missing
328 * required parameter).
329 *
330 * @param $image File
331 * @param $finalParams array List of parameters to transform image with
332 */
333 protected function checkParameterNormalise( $image, $finalParams ) {
334 $h = $image->getHandler();
335 if ( !$h ) {
336 return;
337 }
338 // Note: normaliseParams modifies the array in place, but we aren't interested
339 // in the actual normalised version, only if we can actually normalise them,
340 // so we use the functions scope to throw away the normalisations.
341 if ( !$h->normaliseParams( $image, $finalParams ) ) {
342 $this->dieUsage( "Could not normalise image parameters for " . $image->getName(), "urlparamnormal" );
343 }
344 }
345
346 /**
347 * Get result information for an image revision
348 *
349 * @param File $file
350 * @param array $prop Array of properties to get (in the keys)
351 * @param ApiResult $result
352 * @param array $thumbParams Containing 'width' and 'height' items, or null
353 * @param array|bool|string $opts Options for data fetching.
354 * This is an array consisting of the keys:
355 * 'version': The metadata version for the metadata option
356 * 'language': The language for extmetadata property
357 * 'multilang': Return all translations in extmetadata property
358 * 'revdelUser': User to use when checking whether to show revision-deleted fields.
359 * @return array Result array
360 */
361 static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
362 global $wgContLang;
363
364 $anyHidden = false;
365
366 if ( !$opts || is_string( $opts ) ) {
367 $opts = array(
368 'version' => $opts ?: 'latest',
369 'language' => $wgContLang,
370 'multilang' => false,
371 'extmetadatafilter' => array(),
372 'revdelUser' => null,
373 );
374 }
375 $version = $opts['version'];
376 $vals = array();
377 // Timestamp is shown even if the file is revdelete'd in interface
378 // so do same here.
379 if ( isset( $prop['timestamp'] ) ) {
380 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
381 }
382
383 // Handle external callers who don't pass revdelUser
384 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
385 $revdelUser = $opts['revdelUser'];
386 $canShowField = function ( $field ) use ( $file, $revdelUser ) {
387 return $file->userCan( $field, $revdelUser );
388 };
389 } else {
390 $canShowField = function ( $field ) use ( $file ) {
391 return !$file->isDeleted( $field );
392 };
393 }
394
395 $user = isset( $prop['user'] );
396 $userid = isset( $prop['userid'] );
397
398 if ( $user || $userid ) {
399 if ( $file->isDeleted( File::DELETED_USER ) ) {
400 $vals['userhidden'] = '';
401 $anyHidden = true;
402 }
403 if ( $canShowField( File::DELETED_USER ) ) {
404 if ( $user ) {
405 $vals['user'] = $file->getUser();
406 }
407 if ( $userid ) {
408 $vals['userid'] = $file->getUser( 'id' );
409 }
410 if ( !$file->getUser( 'id' ) ) {
411 $vals['anon'] = '';
412 }
413 }
414 }
415
416 // This is shown even if the file is revdelete'd in interface
417 // so do same here.
418 if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
419 $vals['size'] = intval( $file->getSize() );
420 $vals['width'] = intval( $file->getWidth() );
421 $vals['height'] = intval( $file->getHeight() );
422
423 $pageCount = $file->pageCount();
424 if ( $pageCount !== false ) {
425 $vals['pagecount'] = $pageCount;
426 }
427
428 // length as in how many seconds long a video is.
429 $length = $file->getLength();
430 if ( $length ) {
431 // Call it duration, because "length" can be ambiguous.
432 $vals['duration'] = (float)$length;
433 }
434 }
435
436 $pcomment = isset( $prop['parsedcomment'] );
437 $comment = isset( $prop['comment'] );
438
439 if ( $pcomment || $comment ) {
440 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
441 $vals['commenthidden'] = '';
442 $anyHidden = true;
443 }
444 if ( $canShowField( File::DELETED_COMMENT ) ) {
445 if ( $pcomment ) {
446 $vals['parsedcomment'] = Linker::formatComment(
447 $file->getDescription( File::RAW ), $file->getTitle() );
448 }
449 if ( $comment ) {
450 $vals['comment'] = $file->getDescription( File::RAW );
451 }
452 }
453 }
454
455 $canonicaltitle = isset( $prop['canonicaltitle'] );
456 $url = isset( $prop['url'] );
457 $sha1 = isset( $prop['sha1'] );
458 $meta = isset( $prop['metadata'] );
459 $extmetadata = isset( $prop['extmetadata'] );
460 $commonmeta = isset( $prop['commonmetadata'] );
461 $mime = isset( $prop['mime'] );
462 $mediatype = isset( $prop['mediatype'] );
463 $archive = isset( $prop['archivename'] );
464 $bitdepth = isset( $prop['bitdepth'] );
465 $uploadwarning = isset( $prop['uploadwarning'] );
466
467 if ( $uploadwarning ) {
468 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
469 }
470
471 if ( $file->isDeleted( File::DELETED_FILE ) ) {
472 $vals['filehidden'] = '';
473 $anyHidden = true;
474 }
475
476 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
477 $vals['suppressed'] = true;
478 }
479
480 if ( !$canShowField( File::DELETED_FILE ) ) {
481 //Early return, tidier than indenting all following things one level
482 return $vals;
483 }
484
485 if ( $canonicaltitle ) {
486 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
487 }
488
489 if ( $url ) {
490 if ( !is_null( $thumbParams ) ) {
491 $mto = $file->transform( $thumbParams );
492 self::$transformCount++;
493 if ( $mto && !$mto->isError() ) {
494 $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
495
496 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
497 // thumbnail sizes for the thumbnail actual size
498 if ( $mto->getUrl() !== $file->getUrl() ) {
499 $vals['thumbwidth'] = intval( $mto->getWidth() );
500 $vals['thumbheight'] = intval( $mto->getHeight() );
501 } else {
502 $vals['thumbwidth'] = intval( $file->getWidth() );
503 $vals['thumbheight'] = intval( $file->getHeight() );
504 }
505
506 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
507 list( , $mime ) = $file->getHandler()->getThumbType(
508 $mto->getExtension(), $file->getMimeType(), $thumbParams );
509 $vals['thumbmime'] = $mime;
510 }
511 } elseif ( $mto && $mto->isError() ) {
512 $vals['thumberror'] = $mto->toText();
513 }
514 }
515 $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
516 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
517 }
518
519 if ( $sha1 ) {
520 $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
521 }
522
523 if ( $meta ) {
524 wfSuppressWarnings();
525 $metadata = unserialize( $file->getMetadata() );
526 wfRestoreWarnings();
527 if ( $metadata && $version !== 'latest' ) {
528 $metadata = $file->convertMetadataVersion( $metadata, $version );
529 }
530 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
531 }
532 if ( $commonmeta ) {
533 $metaArray = $file->getCommonMetaArray();
534 $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : array();
535 }
536
537 if ( $extmetadata ) {
538 // Note, this should return an array where all the keys
539 // start with a letter, and all the values are strings.
540 // Thus there should be no issue with format=xml.
541 $format = new FormatMetadata;
542 $format->setSingleLanguage( !$opts['multilang'] );
543 $format->getContext()->setLanguage( $opts['language'] );
544 $extmetaArray = $format->fetchExtendedMetadata( $file );
545 if ( $opts['extmetadatafilter'] ) {
546 $extmetaArray = array_intersect_key(
547 $extmetaArray, array_flip( $opts['extmetadatafilter'] )
548 );
549 }
550 $vals['extmetadata'] = $extmetaArray;
551 }
552
553 if ( $mime ) {
554 $vals['mime'] = $file->getMimeType();
555 }
556
557 if ( $mediatype ) {
558 $vals['mediatype'] = $file->getMediaType();
559 }
560
561 if ( $archive && $file->isOld() ) {
562 $vals['archivename'] = $file->getArchiveName();
563 }
564
565 if ( $bitdepth ) {
566 $vals['bitdepth'] = $file->getBitDepth();
567 }
568
569 return $vals;
570 }
571
572 /**
573 * Get the count of image transformations performed
574 *
575 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
576 *
577 * @return int Count
578 */
579 static function getTransformCount() {
580 return self::$transformCount;
581 }
582
583 /**
584 *
585 * @param array $metadata
586 * @param ApiResult $result
587 * @return array
588 */
589 public static function processMetaData( $metadata, $result ) {
590 $retval = array();
591 if ( is_array( $metadata ) ) {
592 foreach ( $metadata as $key => $value ) {
593 $r = array( 'name' => $key );
594 if ( is_array( $value ) ) {
595 $r['value'] = self::processMetaData( $value, $result );
596 } else {
597 $r['value'] = $value;
598 }
599 $retval[] = $r;
600 }
601 }
602 $result->setIndexedTagName( $retval, 'metadata' );
603
604 return $retval;
605 }
606
607 public function getCacheMode( $params ) {
608 if ( $this->userCanSeeRevDel() ) {
609 return 'private';
610 }
611
612 return 'public';
613 }
614
615 /**
616 * @param File $img
617 * @param null|string $start
618 * @return string
619 */
620 protected function getContinueStr( $img, $start = null ) {
621 if ( $start === null ) {
622 $start = $img->getTimestamp();
623 }
624
625 return $img->getOriginalTitle()->getDBkey() . '|' . $start;
626 }
627
628 public function getAllowedParams() {
629 global $wgContLang;
630
631 return array(
632 'prop' => array(
633 ApiBase::PARAM_ISMULTI => true,
634 ApiBase::PARAM_DFLT => 'timestamp|user',
635 ApiBase::PARAM_TYPE => self::getPropertyNames()
636 ),
637 'limit' => array(
638 ApiBase::PARAM_TYPE => 'limit',
639 ApiBase::PARAM_DFLT => 1,
640 ApiBase::PARAM_MIN => 1,
641 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
642 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
643 ),
644 'start' => array(
645 ApiBase::PARAM_TYPE => 'timestamp'
646 ),
647 'end' => array(
648 ApiBase::PARAM_TYPE => 'timestamp'
649 ),
650 'urlwidth' => array(
651 ApiBase::PARAM_TYPE => 'integer',
652 ApiBase::PARAM_DFLT => -1,
653 ApiBase::PARAM_HELP_MSG => array(
654 'apihelp-query+imageinfo-param-urlwidth',
655 ApiQueryImageInfo::TRANSFORM_LIMIT,
656 ),
657 ),
658 'urlheight' => array(
659 ApiBase::PARAM_TYPE => 'integer',
660 ApiBase::PARAM_DFLT => -1
661 ),
662 'metadataversion' => array(
663 ApiBase::PARAM_TYPE => 'string',
664 ApiBase::PARAM_DFLT => '1',
665 ),
666 'extmetadatalanguage' => array(
667 ApiBase::PARAM_TYPE => 'string',
668 ApiBase::PARAM_DFLT => $wgContLang->getCode(),
669 ),
670 'extmetadatamultilang' => array(
671 ApiBase::PARAM_TYPE => 'boolean',
672 ApiBase::PARAM_DFLT => false,
673 ),
674 'extmetadatafilter' => array(
675 ApiBase::PARAM_TYPE => 'string',
676 ApiBase::PARAM_ISMULTI => true,
677 ),
678 'urlparam' => array(
679 ApiBase::PARAM_DFLT => '',
680 ApiBase::PARAM_TYPE => 'string',
681 ),
682 'continue' => array(
683 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
684 ),
685 'localonly' => false,
686 );
687 }
688
689 /**
690 * Returns all possible parameters to iiprop
691 *
692 * @param array $filter List of properties to filter out
693 *
694 * @return array
695 */
696 public static function getPropertyNames( $filter = array() ) {
697 return array_diff( array_keys( self::getProperties() ), $filter );
698 }
699
700 /**
701 * Returns array key value pairs of properties and their descriptions
702 *
703 * @deprecated since 1.25
704 * @param string $modulePrefix
705 * @return array
706 */
707 private static function getProperties( $modulePrefix = '' ) {
708 return array(
709 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
710 'user' => ' user - Adds the user who uploaded the image version',
711 'userid' => ' userid - Add the user ID that uploaded the image version',
712 'comment' => ' comment - Comment on the version',
713 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
714 'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
715 'url' => ' url - Gives URL to the image and the description page',
716 'size' => ' size - Adds the size of the image in bytes, ' .
717 'its height and its width. Page count and duration are added if applicable',
718 'dimensions' => ' dimensions - Alias for size', // B/C with Allimages
719 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
720 'mime' => ' mime - Adds MIME type of the image',
721 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
722 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
723 'mediatype' => ' mediatype - Adds the media type of the image',
724 'metadata' => ' metadata - Lists Exif metadata for the version of the image',
725 'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
726 'for the version of the image',
727 'extmetadata' => ' extmetadata - Lists formatted metadata combined ' .
728 'from multiple sources. Results are HTML formatted.',
729 'archivename' => ' archivename - Adds the file name of the archive ' .
730 'version for non-latest versions',
731 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
732 'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
733 'get information about an existing file. Not intended for use outside MediaWiki core',
734 );
735 }
736
737 /**
738 * Returns the descriptions for the properties provided by getPropertyNames()
739 *
740 * @deprecated since 1.25
741 * @param array $filter List of properties to filter out
742 * @param string $modulePrefix
743 * @return array
744 */
745 public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
746 return array_merge(
747 array( 'What image information to get:' ),
748 array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
749 );
750 }
751
752 protected function getExamplesMessages() {
753 return array(
754 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
755 => 'apihelp-query+imageinfo-example-simple',
756 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
757 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
758 => 'apihelp-query+imageinfo-example-dated',
759 );
760 }
761
762 public function getHelpUrls() {
763 return 'https://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii';
764 }
765 }