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