MediaWiki master
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Api;
24
27use RepoGroup;
31
38
39 private RepoGroup $repoGroup;
40
48 public function __construct(
49 ApiQuery $query,
50 $moduleName,
51 RepoGroup $repoGroup,
52 Language $contentLanguage,
53 BadFileLookup $badFileLookup
54 ) {
55 parent::__construct(
56 $query,
57 $moduleName,
58 'sii',
59 $repoGroup,
60 $contentLanguage,
61 $badFileLookup
62 );
63 $this->repoGroup = $repoGroup;
64 }
65
66 public function execute() {
67 if ( !$this->getUser()->isRegistered() ) {
68 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
69 }
70
72 $modulePrefix = $this->getModulePrefix();
73
74 $prop = array_fill_keys( $params['prop'], true );
75
76 $scale = $this->getScale( $params );
77
78 $result = $this->getResult();
79
80 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
81
82 // Alias sessionkey to filekey, but give an existing filekey precedence.
83 if ( !$params['filekey'] && $params['sessionkey'] ) {
84 $params['filekey'] = $params['sessionkey'];
85 }
86
87 try {
88 $stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() );
89
90 foreach ( $params['filekey'] as $filekey ) {
91 $file = $stash->getFile( $filekey );
92 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
93 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
94 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
95 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
96 }
97 // @todo Update exception handling here to understand current getFile exceptions
99 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
100 } catch ( UploadStashBadPathException $e ) {
101 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
102 }
103 }
104
105 private const PROPERTY_FILTER = [
106 'user', 'userid', 'comment', 'parsedcomment',
107 'mediatype', 'archivename', 'uploadwarning',
108 ];
109
116 public static function getPropertyNames( $filter = null ) {
117 return parent::getPropertyNames( $filter ?? self::PROPERTY_FILTER );
118 }
119
126 public static function getPropertyMessages( $filter = null ) {
127 return parent::getPropertyMessages( $filter ?? self::PROPERTY_FILTER );
128 }
129
130 public function getAllowedParams() {
131 return [
132 'filekey' => [
133 ParamValidator::PARAM_ISMULTI => true,
134 ],
135 'sessionkey' => [
136 ParamValidator::PARAM_ISMULTI => true,
137 ParamValidator::PARAM_DEPRECATED => true,
138 ],
139 'prop' => [
140 ParamValidator::PARAM_ISMULTI => true,
141 ParamValidator::PARAM_DEFAULT => 'timestamp|url',
142 ParamValidator::PARAM_TYPE => self::getPropertyNames(),
143 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
145 ],
146 'urlwidth' => [
147 ParamValidator::PARAM_TYPE => 'integer',
148 ParamValidator::PARAM_DEFAULT => -1,
150 'apihelp-query+imageinfo-param-urlwidth',
152 ],
153 ],
154 'urlheight' => [
155 ParamValidator::PARAM_TYPE => 'integer',
156 ParamValidator::PARAM_DEFAULT => -1,
157 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
158 ],
159 'urlparam' => [
160 ParamValidator::PARAM_TYPE => 'string',
161 ParamValidator::PARAM_DEFAULT => '',
162 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
163 ],
164 ];
165 }
166
167 protected function getExamplesMessages() {
168 return [
169 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
170 => 'apihelp-query+stashimageinfo-example-simple',
171 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
172 'siiurlwidth=120&siiprop=url'
173 => 'apihelp-query+stashimageinfo-example-params',
174 ];
175 }
176
177 public function getHelpUrls() {
178 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
179 }
180}
181
183class_alias( ApiQueryStashImageInfo::class, 'ApiQueryStashImageInfo' );
array $params
The job parameters.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1577
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:580
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:571
requireAtLeastOneParameter( $params,... $required)
Die if 0 of a certain set of parameters is set and not false.
Definition ApiBase.php:1050
getResult()
Get the result object.
Definition ApiBase.php:710
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:224
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition ApiBase.php:1590
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:184
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:851
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, $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.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Definition ApiQuery.php:48
Base class for language-specific code.
Definition Language.php:79
Prioritized list of file repositories.
Definition RepoGroup.php:32
Service for formatting and validating API parameters.