Merge "Add configuration for running etsy/phan against core"
[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 = [
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 [
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 [ '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 [ '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 static::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 static::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 if ( $params['urlwidth'] != -1 ) {
229 $scale = [];
230 $scale['width'] = $params['urlwidth'];
231 $scale['height'] = $params['urlheight'];
232 } elseif ( $params['urlheight'] != -1 ) {
233 // Height is specified but width isn't
234 // Don't set $scale['width']; this signals mergeThumbParams() to fill it with the image's width
235 $scale = [];
236 $scale['height'] = $params['urlheight'];
237 } else {
238 if ( $params['urlparam'] ) {
239 // Audio files might not have a width/height.
240 $scale = [];
241 } else {
242 $scale = null;
243 }
244 }
245
246 return $scale;
247 }
248
249 /** Validate and merge scale parameters with handler thumb parameters, give error if invalid.
250 *
251 * We do this later than getScale, since we need the image
252 * to know which handler, since handlers can make their own parameters.
253 * @param File $image Image that params are for.
254 * @param array $thumbParams Thumbnail parameters from getScale
255 * @param string $otherParams String of otherParams (iiurlparam).
256 * @return array Array of parameters for transform.
257 */
258 protected function mergeThumbParams( $image, $thumbParams, $otherParams ) {
259 if ( $thumbParams === null ) {
260 // No scaling requested
261 return null;
262 }
263 if ( !isset( $thumbParams['width'] ) && isset( $thumbParams['height'] ) ) {
264 // We want to limit only by height in this situation, so pass the
265 // image's full width as the limiting width. But some file types
266 // don't have a width of their own, so pick something arbitrary so
267 // thumbnailing the default icon works.
268 if ( $image->getWidth() <= 0 ) {
269 $thumbParams['width'] = max( $this->getConfig()->get( 'ThumbLimits' ) );
270 } else {
271 $thumbParams['width'] = $image->getWidth();
272 }
273 }
274
275 if ( !$otherParams ) {
276 $this->checkParameterNormalise( $image, $thumbParams );
277 return $thumbParams;
278 }
279 $p = $this->getModulePrefix();
280
281 $h = $image->getHandler();
282 if ( !$h ) {
283 $this->addWarning( [ 'apiwarn-nothumb-noimagehandler', wfEscapeWikiText( $image->getName() ) ] );
284
285 return $thumbParams;
286 }
287
288 $paramList = $h->parseParamString( $otherParams );
289 if ( !$paramList ) {
290 // Just set a warning (instead of dieUsage), as in many cases
291 // we could still render the image using width and height parameters,
292 // and this type of thing could happen between different versions of
293 // handlers.
294 $this->addWarning( [ 'apiwarn-badurlparam', $p, wfEscapeWikiText( $image->getName() ) ] );
295 $this->checkParameterNormalise( $image, $thumbParams );
296 return $thumbParams;
297 }
298
299 if ( isset( $paramList['width'] ) && isset( $thumbParams['width'] ) ) {
300 if ( intval( $paramList['width'] ) != intval( $thumbParams['width'] ) ) {
301 $this->addWarning(
302 [ 'apiwarn-urlparamwidth', $p, $paramList['width'], $thumbParams['width'] ]
303 );
304 }
305 }
306
307 foreach ( $paramList as $name => $value ) {
308 if ( !$h->validateParam( $name, $value ) ) {
309 $this->dieWithError(
310 [ 'apierror-invalidurlparam', $p, wfEscapeWikiText( $name ), wfEscapeWikiText( $value ) ]
311 );
312 }
313 }
314
315 $finalParams = $thumbParams + $paramList;
316 $this->checkParameterNormalise( $image, $finalParams );
317 return $finalParams;
318 }
319
320 /**
321 * Verify that the final image parameters can be normalised.
322 *
323 * This doesn't use the normalised parameters, since $file->transform
324 * expects the pre-normalised parameters, but doing the normalisation
325 * allows us to catch certain error conditions early (such as missing
326 * required parameter).
327 *
328 * @param File $image
329 * @param array $finalParams List of parameters to transform image with
330 */
331 protected function checkParameterNormalise( $image, $finalParams ) {
332 $h = $image->getHandler();
333 if ( !$h ) {
334 return;
335 }
336 // Note: normaliseParams modifies the array in place, but we aren't interested
337 // in the actual normalised version, only if we can actually normalise them,
338 // so we use the functions scope to throw away the normalisations.
339 if ( !$h->normaliseParams( $image, $finalParams ) ) {
340 $this->dieWithError( [ 'apierror-urlparamnormal', wfEscapeWikiText( $image->getName() ) ] );
341 }
342 }
343
344 /**
345 * Get result information for an image revision
346 *
347 * @param File $file
348 * @param array $prop Array of properties to get (in the keys)
349 * @param ApiResult $result
350 * @param array $thumbParams Containing 'width' and 'height' items, or null
351 * @param array|bool|string $opts Options for data fetching.
352 * This is an array consisting of the keys:
353 * 'version': The metadata version for the metadata option
354 * 'language': The language for extmetadata property
355 * 'multilang': Return all translations in extmetadata property
356 * 'revdelUser': User to use when checking whether to show revision-deleted fields.
357 * @return array Result array
358 */
359 public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
360 global $wgContLang;
361
362 $anyHidden = false;
363
364 if ( !$opts || is_string( $opts ) ) {
365 $opts = [
366 'version' => $opts ?: 'latest',
367 'language' => $wgContLang,
368 'multilang' => false,
369 'extmetadatafilter' => [],
370 'revdelUser' => null,
371 ];
372 }
373 $version = $opts['version'];
374 $vals = [
375 ApiResult::META_TYPE => 'assoc',
376 ];
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'] = true;
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'] = true;
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'] = true;
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'] = true;
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 $shortDescriptionUrl = $file->getDescriptionShortUrl();
519 if ( $shortDescriptionUrl !== null ) {
520 $vals['descriptionshorturl'] = wfExpandUrl( $shortDescriptionUrl, PROTO_CURRENT );
521 }
522 }
523
524 if ( $sha1 ) {
525 $vals['sha1'] = Wikimedia\base_convert( $file->getSha1(), 36, 16, 40 );
526 }
527
528 if ( $meta ) {
529 MediaWiki\suppressWarnings();
530 $metadata = unserialize( $file->getMetadata() );
531 MediaWiki\restoreWarnings();
532 if ( $metadata && $version !== 'latest' ) {
533 $metadata = $file->convertMetadataVersion( $metadata, $version );
534 }
535 $vals['metadata'] = $metadata ? static::processMetaData( $metadata, $result ) : null;
536 }
537 if ( $commonmeta ) {
538 $metaArray = $file->getCommonMetaArray();
539 $vals['commonmetadata'] = $metaArray ? static::processMetaData( $metaArray, $result ) : [];
540 }
541
542 if ( $extmetadata ) {
543 // Note, this should return an array where all the keys
544 // start with a letter, and all the values are strings.
545 // Thus there should be no issue with format=xml.
546 $format = new FormatMetadata;
547 $format->setSingleLanguage( !$opts['multilang'] );
548 $format->getContext()->setLanguage( $opts['language'] );
549 $extmetaArray = $format->fetchExtendedMetadata( $file );
550 if ( $opts['extmetadatafilter'] ) {
551 $extmetaArray = array_intersect_key(
552 $extmetaArray, array_flip( $opts['extmetadatafilter'] )
553 );
554 }
555 $vals['extmetadata'] = $extmetaArray;
556 }
557
558 if ( $mime ) {
559 $vals['mime'] = $file->getMimeType();
560 }
561
562 if ( $mediatype ) {
563 $vals['mediatype'] = $file->getMediaType();
564 }
565
566 if ( $archive && $file->isOld() ) {
567 $vals['archivename'] = $file->getArchiveName();
568 }
569
570 if ( $bitdepth ) {
571 $vals['bitdepth'] = $file->getBitDepth();
572 }
573
574 return $vals;
575 }
576
577 /**
578 * Get the count of image transformations performed
579 *
580 * If this is >= TRANSFORM_LIMIT, you should probably stop processing images.
581 *
582 * @return int Count
583 */
584 static function getTransformCount() {
585 return self::$transformCount;
586 }
587
588 /**
589 *
590 * @param array $metadata
591 * @param ApiResult $result
592 * @return array
593 */
594 public static function processMetaData( $metadata, $result ) {
595 $retval = [];
596 if ( is_array( $metadata ) ) {
597 foreach ( $metadata as $key => $value ) {
598 $r = [
599 'name' => $key,
600 ApiResult::META_BC_BOOLS => [ 'value' ],
601 ];
602 if ( is_array( $value ) ) {
603 $r['value'] = static::processMetaData( $value, $result );
604 } else {
605 $r['value'] = $value;
606 }
607 $retval[] = $r;
608 }
609 }
610 ApiResult::setIndexedTagName( $retval, 'metadata' );
611
612 return $retval;
613 }
614
615 public function getCacheMode( $params ) {
616 if ( $this->userCanSeeRevDel() ) {
617 return 'private';
618 }
619
620 return 'public';
621 }
622
623 /**
624 * @param File $img
625 * @param null|string $start
626 * @return string
627 */
628 protected function getContinueStr( $img, $start = null ) {
629 if ( $start === null ) {
630 $start = $img->getTimestamp();
631 }
632
633 return $img->getOriginalTitle()->getDBkey() . '|' . $start;
634 }
635
636 public function getAllowedParams() {
637 global $wgContLang;
638
639 return [
640 'prop' => [
641 ApiBase::PARAM_ISMULTI => true,
642 ApiBase::PARAM_DFLT => 'timestamp|user',
643 ApiBase::PARAM_TYPE => static::getPropertyNames(),
644 ApiBase::PARAM_HELP_MSG_PER_VALUE => static::getPropertyMessages(),
645 ],
646 'limit' => [
647 ApiBase::PARAM_TYPE => 'limit',
648 ApiBase::PARAM_DFLT => 1,
649 ApiBase::PARAM_MIN => 1,
650 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
651 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
652 ],
653 'start' => [
654 ApiBase::PARAM_TYPE => 'timestamp'
655 ],
656 'end' => [
657 ApiBase::PARAM_TYPE => 'timestamp'
658 ],
659 'urlwidth' => [
660 ApiBase::PARAM_TYPE => 'integer',
661 ApiBase::PARAM_DFLT => -1,
662 ApiBase::PARAM_HELP_MSG => [
663 'apihelp-query+imageinfo-param-urlwidth',
664 ApiQueryImageInfo::TRANSFORM_LIMIT,
665 ],
666 ],
667 'urlheight' => [
668 ApiBase::PARAM_TYPE => 'integer',
669 ApiBase::PARAM_DFLT => -1
670 ],
671 'metadataversion' => [
672 ApiBase::PARAM_TYPE => 'string',
673 ApiBase::PARAM_DFLT => '1',
674 ],
675 'extmetadatalanguage' => [
676 ApiBase::PARAM_TYPE => 'string',
677 ApiBase::PARAM_DFLT => $wgContLang->getCode(),
678 ],
679 'extmetadatamultilang' => [
680 ApiBase::PARAM_TYPE => 'boolean',
681 ApiBase::PARAM_DFLT => false,
682 ],
683 'extmetadatafilter' => [
684 ApiBase::PARAM_TYPE => 'string',
685 ApiBase::PARAM_ISMULTI => true,
686 ],
687 'urlparam' => [
688 ApiBase::PARAM_DFLT => '',
689 ApiBase::PARAM_TYPE => 'string',
690 ],
691 'continue' => [
692 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
693 ],
694 'localonly' => false,
695 ];
696 }
697
698 /**
699 * Returns all possible parameters to iiprop
700 *
701 * @param array $filter List of properties to filter out
702 * @return array
703 */
704 public static function getPropertyNames( $filter = [] ) {
705 return array_keys( static::getPropertyMessages( $filter ) );
706 }
707
708 /**
709 * Returns messages for all possible parameters to iiprop
710 *
711 * @param array $filter List of properties to filter out
712 * @return array
713 */
714 public static function getPropertyMessages( $filter = [] ) {
715 return array_diff_key(
716 [
717 'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
718 'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
719 'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
720 'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
721 'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
722 'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
723 'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
724 'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
725 'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
726 'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
727 'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
728 'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
729 'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
730 'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
731 'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
732 'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
733 'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
734 'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
735 'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
736 ],
737 array_flip( $filter )
738 );
739 }
740
741 /**
742 * Returns array key value pairs of properties and their descriptions
743 *
744 * @deprecated since 1.25
745 * @param string $modulePrefix
746 * @return array
747 */
748 private static function getProperties( $modulePrefix = '' ) {
749 return [
750 'timestamp' => ' timestamp - Adds timestamp for the uploaded version',
751 'user' => ' user - Adds the user who uploaded the image version',
752 'userid' => ' userid - Add the user ID that uploaded the image version',
753 'comment' => ' comment - Comment on the version',
754 'parsedcomment' => ' parsedcomment - Parse the comment on the version',
755 'canonicaltitle' => ' canonicaltitle - Adds the canonical title of the image file',
756 'url' => ' url - Gives URL to the image and the description page',
757 'size' => ' size - Adds the size of the image in bytes, ' .
758 'its height and its width. Page count and duration are added if applicable',
759 'dimensions' => ' dimensions - Alias for size', // B/C with Allimages
760 'sha1' => ' sha1 - Adds SHA-1 hash for the image',
761 'mime' => ' mime - Adds MIME type of the image',
762 'thumbmime' => ' thumbmime - Adds MIME type of the image thumbnail' .
763 ' (requires url and param ' . $modulePrefix . 'urlwidth)',
764 'mediatype' => ' mediatype - Adds the media type of the image',
765 'metadata' => ' metadata - Lists Exif metadata for the version of the image',
766 'commonmetadata' => ' commonmetadata - Lists file format generic metadata ' .
767 'for the version of the image',
768 'extmetadata' => ' extmetadata - Lists formatted metadata combined ' .
769 'from multiple sources. Results are HTML formatted.',
770 'archivename' => ' archivename - Adds the file name of the archive ' .
771 'version for non-latest versions',
772 'bitdepth' => ' bitdepth - Adds the bit depth of the version',
773 'uploadwarning' => ' uploadwarning - Used by the Special:Upload page to ' .
774 'get information about an existing file. Not intended for use outside MediaWiki core',
775 ];
776 }
777
778 /**
779 * Returns the descriptions for the properties provided by getPropertyNames()
780 *
781 * @deprecated since 1.25
782 * @param array $filter List of properties to filter out
783 * @param string $modulePrefix
784 * @return array
785 */
786 public static function getPropertyDescriptions( $filter = [], $modulePrefix = '' ) {
787 return array_merge(
788 [ 'What image information to get:' ],
789 array_values( array_diff_key( static::getProperties( $modulePrefix ), array_flip( $filter ) ) )
790 );
791 }
792
793 protected function getExamplesMessages() {
794 return [
795 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
796 => 'apihelp-query+imageinfo-example-simple',
797 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
798 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
799 => 'apihelp-query+imageinfo-example-dated',
800 ];
801 }
802
803 public function getHelpUrls() {
804 return 'https://www.mediawiki.org/wiki/API:Imageinfo';
805 }
806 }