Merge "Don't check namespace in SpecialWantedtemplates"
[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 ApiResult::META_TYPE => 'assoc',
378 );
379 // Timestamp is shown even if the file is revdelete'd in interface
380 // so do same here.
381 if ( isset( $prop['timestamp'] ) ) {
382 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
383 }
384
385 // Handle external callers who don't pass revdelUser
386 if ( isset( $opts['revdelUser'] ) && $opts['revdelUser'] ) {
387 $revdelUser = $opts['revdelUser'];
388 $canShowField = function ( $field ) use ( $file, $revdelUser ) {
389 return $file->userCan( $field, $revdelUser );
390 };
391 } else {
392 $canShowField = function ( $field ) use ( $file ) {
393 return !$file->isDeleted( $field );
394 };
395 }
396
397 $user = isset( $prop['user'] );
398 $userid = isset( $prop['userid'] );
399
400 if ( $user || $userid ) {
401 if ( $file->isDeleted( File::DELETED_USER ) ) {
402 $vals['userhidden'] = true;
403 $anyHidden = true;
404 }
405 if ( $canShowField( File::DELETED_USER ) ) {
406 if ( $user ) {
407 $vals['user'] = $file->getUser();
408 }
409 if ( $userid ) {
410 $vals['userid'] = $file->getUser( 'id' );
411 }
412 if ( !$file->getUser( 'id' ) ) {
413 $vals['anon'] = true;
414 }
415 }
416 }
417
418 // This is shown even if the file is revdelete'd in interface
419 // so do same here.
420 if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) {
421 $vals['size'] = intval( $file->getSize() );
422 $vals['width'] = intval( $file->getWidth() );
423 $vals['height'] = intval( $file->getHeight() );
424
425 $pageCount = $file->pageCount();
426 if ( $pageCount !== false ) {
427 $vals['pagecount'] = $pageCount;
428 }
429
430 // length as in how many seconds long a video is.
431 $length = $file->getLength();
432 if ( $length ) {
433 // Call it duration, because "length" can be ambiguous.
434 $vals['duration'] = (float)$length;
435 }
436 }
437
438 $pcomment = isset( $prop['parsedcomment'] );
439 $comment = isset( $prop['comment'] );
440
441 if ( $pcomment || $comment ) {
442 if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
443 $vals['commenthidden'] = true;
444 $anyHidden = true;
445 }
446 if ( $canShowField( File::DELETED_COMMENT ) ) {
447 if ( $pcomment ) {
448 $vals['parsedcomment'] = Linker::formatComment(
449 $file->getDescription( File::RAW ), $file->getTitle() );
450 }
451 if ( $comment ) {
452 $vals['comment'] = $file->getDescription( File::RAW );
453 }
454 }
455 }
456
457 $canonicaltitle = isset( $prop['canonicaltitle'] );
458 $url = isset( $prop['url'] );
459 $sha1 = isset( $prop['sha1'] );
460 $meta = isset( $prop['metadata'] );
461 $extmetadata = isset( $prop['extmetadata'] );
462 $commonmeta = isset( $prop['commonmetadata'] );
463 $mime = isset( $prop['mime'] );
464 $mediatype = isset( $prop['mediatype'] );
465 $archive = isset( $prop['archivename'] );
466 $bitdepth = isset( $prop['bitdepth'] );
467 $uploadwarning = isset( $prop['uploadwarning'] );
468
469 if ( $uploadwarning ) {
470 $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) );
471 }
472
473 if ( $file->isDeleted( File::DELETED_FILE ) ) {
474 $vals['filehidden'] = true;
475 $anyHidden = true;
476 }
477
478 if ( $anyHidden && $file->isDeleted( File::DELETED_RESTRICTED ) ) {
479 $vals['suppressed'] = true;
480 }
481
482 if ( !$canShowField( File::DELETED_FILE ) ) {
483 //Early return, tidier than indenting all following things one level
484 return $vals;
485 }
486
487 if ( $canonicaltitle ) {
488 $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
489 }
490
491 if ( $url ) {
492 if ( !is_null( $thumbParams ) ) {
493 $mto = $file->transform( $thumbParams );
494 self::$transformCount++;
495 if ( $mto && !$mto->isError() ) {
496 $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
497
498 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
499 // thumbnail sizes for the thumbnail actual size
500 if ( $mto->getUrl() !== $file->getUrl() ) {
501 $vals['thumbwidth'] = intval( $mto->getWidth() );
502 $vals['thumbheight'] = intval( $mto->getHeight() );
503 } else {
504 $vals['thumbwidth'] = intval( $file->getWidth() );
505 $vals['thumbheight'] = intval( $file->getHeight() );
506 }
507
508 if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) {
509 list( , $mime ) = $file->getHandler()->getThumbType(
510 $mto->getExtension(), $file->getMimeType(), $thumbParams );
511 $vals['thumbmime'] = $mime;
512 }
513 } elseif ( $mto && $mto->isError() ) {
514 $vals['thumberror'] = $mto->toText();
515 }
516 }
517 $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT );
518 $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT );
519 }
520
521 if ( $sha1 ) {
522 $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 );
523 }
524
525 if ( $meta ) {
526 MediaWiki\suppressWarnings();
527 $metadata = unserialize( $file->getMetadata() );
528 MediaWiki\restoreWarnings();
529 if ( $metadata && $version !== 'latest' ) {
530 $metadata = $file->convertMetadataVersion( $metadata, $version );
531 }
532 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
533 }
534 if ( $commonmeta ) {
535 $metaArray = $file->getCommonMetaArray();
536 $vals['commonmetadata'] = $metaArray ? self::processMetaData( $metaArray, $result ) : array();
537 }
538
539 if ( $extmetadata ) {
540 // Note, this should return an array where all the keys
541 // start with a letter, and all the values are strings.
542 // Thus there should be no issue with format=xml.
543 $format = new FormatMetadata;
544 $format->setSingleLanguage( !$opts['multilang'] );
545 $format->getContext()->setLanguage( $opts['language'] );
546 $extmetaArray = $format->fetchExtendedMetadata( $file );
547 if ( $opts['extmetadatafilter'] ) {
548 $extmetaArray = array_intersect_key(
549 $extmetaArray, array_flip( $opts['extmetadatafilter'] )
550 );
551 }
552 $vals['extmetadata'] = $extmetaArray;
553 }
554
555 if ( $mime ) {
556 $vals['mime'] = $file->getMimeType();
557 }
558
559 if ( $mediatype ) {
560 $vals['mediatype'] = $file->getMediaType();
561 }
562
563 if ( $archive && $file->isOld() ) {
564 $vals['archivename'] = $file->getArchiveName();
565 }
566
567 if ( $bitdepth ) {
568 $vals['bitdepth'] = $file->getBitDepth();
569 }
570
571 return $vals;
572 }
573
574 /**
575 * Get the count of image transformations performed
576 *
577 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
578 *
579 * @return int Count
580 */
581 static function getTransformCount() {
582 return self::$transformCount;
583 }
584
585 /**
586 *
587 * @param array $metadata
588 * @param ApiResult $result
589 * @return array
590 */
591 public static function processMetaData( $metadata, $result ) {
592 $retval = array();
593 if ( is_array( $metadata ) ) {
594 foreach ( $metadata as $key => $value ) {
595 $r = array(
596 'name' => $key,
597 ApiResult::META_BC_BOOLS => array( 'value' ),
598 );
599 if ( is_array( $value ) ) {
600 $r['value'] = self::processMetaData( $value, $result );
601 } else {
602 $r['value'] = $value;
603 }
604 $retval[] = $r;
605 }
606 }
607 ApiResult::setIndexedTagName( $retval, 'metadata' );
608
609 return $retval;
610 }
611
612 public function getCacheMode( $params ) {
613 if ( $this->userCanSeeRevDel() ) {
614 return 'private';
615 }
616
617 return 'public';
618 }
619
620 /**
621 * @param File $img
622 * @param null|string $start
623 * @return string
624 */
625 protected function getContinueStr( $img, $start = null ) {
626 if ( $start === null ) {
627 $start = $img->getTimestamp();
628 }
629
630 return $img->getOriginalTitle()->getDBkey() . '|' . $start;
631 }
632
633 public function getAllowedParams() {
634 global $wgContLang;
635
636 return array(
637 'prop' => array(
638 ApiBase::PARAM_ISMULTI => true,
639 ApiBase::PARAM_DFLT => 'timestamp|user',
640 ApiBase::PARAM_TYPE => self::getPropertyNames(),
641 ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages(),
642 ),
643 'limit' => array(
644 ApiBase::PARAM_TYPE => 'limit',
645 ApiBase::PARAM_DFLT => 1,
646 ApiBase::PARAM_MIN => 1,
647 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
648 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
649 ),
650 'start' => array(
651 ApiBase::PARAM_TYPE => 'timestamp'
652 ),
653 'end' => array(
654 ApiBase::PARAM_TYPE => 'timestamp'
655 ),
656 'urlwidth' => array(
657 ApiBase::PARAM_TYPE => 'integer',
658 ApiBase::PARAM_DFLT => -1,
659 ApiBase::PARAM_HELP_MSG => array(
660 'apihelp-query+imageinfo-param-urlwidth',
661 ApiQueryImageInfo::TRANSFORM_LIMIT,
662 ),
663 ),
664 'urlheight' => array(
665 ApiBase::PARAM_TYPE => 'integer',
666 ApiBase::PARAM_DFLT => -1
667 ),
668 'metadataversion' => array(
669 ApiBase::PARAM_TYPE => 'string',
670 ApiBase::PARAM_DFLT => '1',
671 ),
672 'extmetadatalanguage' => array(
673 ApiBase::PARAM_TYPE => 'string',
674 ApiBase::PARAM_DFLT => $wgContLang->getCode(),
675 ),
676 'extmetadatamultilang' => array(
677 ApiBase::PARAM_TYPE => 'boolean',
678 ApiBase::PARAM_DFLT => false,
679 ),
680 'extmetadatafilter' => array(
681 ApiBase::PARAM_TYPE => 'string',
682 ApiBase::PARAM_ISMULTI => true,
683 ),
684 'urlparam' => array(
685 ApiBase::PARAM_DFLT => '',
686 ApiBase::PARAM_TYPE => 'string',
687 ),
688 'continue' => array(
689 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
690 ),
691 'localonly' => false,
692 );
693 }
694
695 /**
696 * Returns all possible parameters to iiprop
697 *
698 * @param array $filter List of properties to filter out
699 * @return array
700 */
701 public static function getPropertyNames( $filter = array() ) {
702 return array_keys( self::getPropertyMessages( $filter ) );
703 }
704
705 /**
706 * Returns messages for all possible parameters to iiprop
707 *
708 * @param array $filter List of properties to filter out
709 * @return array
710 */
711 public static function getPropertyMessages( $filter = array() ) {
712 return array_diff_key(
713 array(
714 'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
715 'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
716 'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
717 'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
718 'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
719 'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
720 'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
721 'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
722 'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
723 'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
724 'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
725 'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
726 'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
727 'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
728 'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
729 'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
730 'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
731 'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
732 'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
733 ),
734 array_flip( $filter )
735 );
736 }
737
738 /**
739 * Returns array key value pairs of properties and their descriptions
740 *
741 * @deprecated since 1.25
742 * @param string $modulePrefix
743 * @return array
744 */
745 private static function getProperties( $modulePrefix = '' ) {
746 return array(
747 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
748 'user' => ' user - Adds the user who uploaded the image version',
749 'userid' => ' userid - Add the user ID that uploaded the image version',
750 'comment' => ' comment - Comment on the version',
751 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
752 'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
753 'url' => ' url - Gives URL to the image and the description page',
754 'size' => ' size - Adds the size of the image in bytes, ' .
755 'its height and its width. Page count and duration are added if applicable',
756 'dimensions' => ' dimensions - Alias for size', // B/C with Allimages
757 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
758 'mime' => ' mime - Adds MIME type of the image',
759 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
760 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
761 'mediatype' => ' mediatype - Adds the media type of the image',
762 'metadata' => ' metadata - Lists Exif metadata for the version of the image',
763 'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
764 'for the version of the image',
765 'extmetadata' => ' extmetadata - Lists formatted metadata combined ' .
766 'from multiple sources. Results are HTML formatted.',
767 'archivename' => ' archivename - Adds the file name of the archive ' .
768 'version for non-latest versions',
769 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
770 'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
771 'get information about an existing file. Not intended for use outside MediaWiki core',
772 );
773 }
774
775 /**
776 * Returns the descriptions for the properties provided by getPropertyNames()
777 *
778 * @deprecated since 1.25
779 * @param array $filter List of properties to filter out
780 * @param string $modulePrefix
781 * @return array
782 */
783 public static function getPropertyDescriptions( $filter = array(), $modulePrefix = '' ) {
784 return array_merge(
785 array( 'What image information to get:' ),
786 array_values( array_diff_key( self::getProperties( $modulePrefix ), array_flip( $filter ) ) )
787 );
788 }
789
790 protected function getExamplesMessages() {
791 return array(
792 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
793 => 'apihelp-query+imageinfo-example-simple',
794 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
795 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
796 => 'apihelp-query+imageinfo-example-dated',
797 );
798 }
799
800 public function getHelpUrls() {
801 return 'https://www.mediawiki.org/wiki/API:Imageinfo';
802 }
803 }