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