MediaWiki master
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1<?php
25
32
33 private RepoGroup $repoGroup;
34
42 public function __construct(
43 ApiQuery $query,
44 $moduleName,
45 RepoGroup $repoGroup,
46 Language $contentLanguage,
47 BadFileLookup $badFileLookup
48 ) {
49 parent::__construct(
50 $query,
51 $moduleName,
52 'sii',
53 $repoGroup,
54 $contentLanguage,
55 $badFileLookup
56 );
57 $this->repoGroup = $repoGroup;
58 }
59
60 public function execute() {
61 if ( !$this->getUser()->isRegistered() ) {
62 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
63 }
64
66 $modulePrefix = $this->getModulePrefix();
67
68 $prop = array_fill_keys( $params['prop'], true );
69
70 $scale = $this->getScale( $params );
71
72 $result = $this->getResult();
73
74 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
75
76 // Alias sessionkey to filekey, but give an existing filekey precedence.
77 if ( !$params['filekey'] && $params['sessionkey'] ) {
78 $params['filekey'] = $params['sessionkey'];
79 }
80
81 try {
82 $stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() );
83
84 foreach ( $params['filekey'] as $filekey ) {
85 $file = $stash->getFile( $filekey );
86 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
87 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
88 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
89 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
90 }
91 // @todo Update exception handling here to understand current getFile exceptions
93 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
94 } catch ( UploadStashBadPathException $e ) {
95 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
96 }
97 }
98
99 private static $propertyFilter = [
100 'user', 'userid', 'comment', 'parsedcomment',
101 'mediatype', 'archivename', 'uploadwarning',
102 ];
103
110 public static function getPropertyNames( $filter = null ) {
111 return parent::getPropertyNames( $filter ?? self::$propertyFilter );
112 }
113
120 public static function getPropertyMessages( $filter = null ) {
121 return parent::getPropertyMessages( $filter ?? self::$propertyFilter );
122 }
123
124 public function getAllowedParams() {
125 return [
126 'filekey' => [
127 ParamValidator::PARAM_ISMULTI => true,
128 ],
129 'sessionkey' => [
130 ParamValidator::PARAM_ISMULTI => true,
131 ParamValidator::PARAM_DEPRECATED => true,
132 ],
133 'prop' => [
134 ParamValidator::PARAM_ISMULTI => true,
135 ParamValidator::PARAM_DEFAULT => 'timestamp|url',
136 ParamValidator::PARAM_TYPE => self::getPropertyNames(),
137 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
139 ],
140 'urlwidth' => [
141 ParamValidator::PARAM_TYPE => 'integer',
142 ParamValidator::PARAM_DEFAULT => -1,
144 'apihelp-query+imageinfo-param-urlwidth',
146 ],
147 ],
148 'urlheight' => [
149 ParamValidator::PARAM_TYPE => 'integer',
150 ParamValidator::PARAM_DEFAULT => -1,
151 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
152 ],
153 'urlparam' => [
154 ParamValidator::PARAM_TYPE => 'string',
155 ParamValidator::PARAM_DEFAULT => '',
156 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
157 ],
158 ];
159 }
160
161 protected function getExamplesMessages() {
162 return [
163 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
164 => 'apihelp-query+stashimageinfo-example-simple',
165 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
166 'siiurlwidth=120&siiprop=url'
167 => 'apihelp-query+stashimageinfo-example-params',
168 ];
169 }
170
171 public function getHelpUrls() {
172 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
173 }
174}
getUser()
array $params
The job parameters.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1542
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:550
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:211
requireAtLeastOneParameter( $params,... $required)
Die if 0 of a certain set of parameters is set and not false.
Definition ApiBase.php:1019
getResult()
Get the result object.
Definition ApiBase.php:680
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:820
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:171
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:541
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition ApiBase.php:1555
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.
getScale( $params)
From parameters, construct a 'scale' array.
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
A query action to get image information from temporarily stashed files.
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...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
static getPropertyNames( $filter=null)
Returns all possible parameters to siiprop.
__construct(ApiQuery $query, $moduleName, RepoGroup $repoGroup, Language $contentLanguage, BadFileLookup $badFileLookup)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Definition ApiQuery.php:43
Base class for language-specific code.
Definition Language.php:63
Prioritized list of file repositories.
Definition RepoGroup.php:30
Service for formatting and validating API parameters.