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