MediaWiki master
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Api;
10
17
24
25 private RepoGroup $repoGroup;
26
27 public function __construct(
28 ApiQuery $query,
29 string $moduleName,
30 RepoGroup $repoGroup,
31 Language $contentLanguage,
32 BadFileLookup $badFileLookup
33 ) {
34 parent::__construct(
35 $query,
36 $moduleName,
37 'sii',
38 $repoGroup,
39 $contentLanguage,
40 $badFileLookup
41 );
42 $this->repoGroup = $repoGroup;
43 }
44
45 public function execute() {
46 if ( !$this->getUser()->isRegistered() ) {
47 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
48 }
49
50 $params = $this->extractRequestParams();
51 $modulePrefix = $this->getModulePrefix();
52
53 $prop = array_fill_keys( $params['prop'], true );
54
55 $scale = $this->getScale( $params );
56
57 $result = $this->getResult();
58
59 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
60
61 // Alias sessionkey to filekey, but give an existing filekey precedence.
62 if ( !$params['filekey'] && $params['sessionkey'] ) {
63 $params['filekey'] = $params['sessionkey'];
64 }
65
66 try {
67 $stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() );
68
69 foreach ( $params['filekey'] as $filekey ) {
70 $file = $stash->getFile( $filekey );
71 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
72 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
73 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
74 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
75 }
76 // @todo Update exception handling here to understand current getFile exceptions
78 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
79 } catch ( UploadStashBadPathException $e ) {
80 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
81 }
82 }
83
84 private const PROPERTY_FILTER = [
85 'user', 'userid', 'comment', 'parsedcomment',
86 'mediatype', 'archivename', 'uploadwarning',
87 ];
88
95 public static function getPropertyNames( $filter = null ) {
96 return parent::getPropertyNames( $filter ?? self::PROPERTY_FILTER );
97 }
98
105 public static function getPropertyMessages( $filter = null ) {
106 return parent::getPropertyMessages( $filter ?? self::PROPERTY_FILTER );
107 }
108
110 public function getAllowedParams() {
111 return [
112 'filekey' => [
113 ParamValidator::PARAM_ISMULTI => true,
114 ],
115 'sessionkey' => [
116 ParamValidator::PARAM_ISMULTI => true,
117 ParamValidator::PARAM_DEPRECATED => true,
118 ],
119 'prop' => [
120 ParamValidator::PARAM_ISMULTI => true,
121 ParamValidator::PARAM_DEFAULT => 'timestamp|url',
122 ParamValidator::PARAM_TYPE => self::getPropertyNames(),
123 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
125 ],
126 'urlwidth' => [
127 ParamValidator::PARAM_TYPE => 'integer',
128 ParamValidator::PARAM_DEFAULT => -1,
130 'apihelp-query+imageinfo-param-urlwidth',
132 ],
133 ],
134 'urlheight' => [
135 ParamValidator::PARAM_TYPE => 'integer',
136 ParamValidator::PARAM_DEFAULT => -1,
137 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
138 ],
139 'urlparam' => [
140 ParamValidator::PARAM_TYPE => 'string',
141 ParamValidator::PARAM_DEFAULT => '',
142 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
143 ],
144 ];
145 }
146
148 protected function getExamplesMessages() {
149 return [
150 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
151 => 'apihelp-query+stashimageinfo-example-simple',
152 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
153 'siiurlwidth=120&siiprop=url'
154 => 'apihelp-query+stashimageinfo-example-params',
155 ];
156 }
157
159 public function getHelpUrls() {
160 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
161 }
162}
163
165class_alias( ApiQueryStashImageInfo::class, 'ApiQueryStashImageInfo' );
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1511
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:552
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:543
requireAtLeastOneParameter( $params,... $required)
Die if 0 of a certain set of parameters is set and not false.
Definition ApiBase.php:1025
getResult()
Get the result object.
Definition ApiBase.php:682
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:207
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition ApiBase.php:1524
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:167
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:823
A query action to get image information and upload history.
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
getScale( $params)
From parameters, construct a 'scale' array.
A query action to get image information from temporarily stashed files.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, string $moduleName, RepoGroup $repoGroup, Language $contentLanguage, BadFileLookup $badFileLookup)
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
static getPropertyNames( $filter=null)
Returns all possible parameters to siiprop.
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
This is the main query class.
Definition ApiQuery.php:36
Prioritized list of file repositories.
Definition RepoGroup.php:30
Base class for language-specific code.
Definition Language.php:70
Service for formatting and validating API parameters.