MediaWiki REL1_37
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1<?php
24
31
33 private $repoGroup;
34
42 public function __construct(
43 ApiQuery $query,
44 $moduleName,
48 ) {
49 parent::__construct(
50 $query,
51 $moduleName,
52 'sii',
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
65 $params = $this->extractRequestParams();
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 if ( $filter === null ) {
112 $filter = self::$propertyFilter;
113 }
114 return parent::getPropertyNames( $filter );
115 }
116
123 public static function getPropertyMessages( $filter = null ) {
124 if ( $filter === null ) {
125 $filter = self::$propertyFilter;
126 }
127 return parent::getPropertyMessages( $filter );
128 }
129
130 public function getAllowedParams() {
131 return [
132 'filekey' => [
134 ],
135 'sessionkey' => [
138 ],
139 'prop' => [
141 ApiBase::PARAM_DFLT => 'timestamp|url',
143 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
145 ],
146 'urlwidth' => [
147 ApiBase::PARAM_TYPE => 'integer',
150 'apihelp-query+imageinfo-param-urlwidth',
152 ],
153 ],
154 'urlheight' => [
155 ApiBase::PARAM_TYPE => 'integer',
157 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
158 ],
159 'urlparam' => [
160 ApiBase::PARAM_TYPE => 'string',
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}
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1436
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:505
const PARAM_DEPRECATED
Definition ApiBase.php:101
const PARAM_TYPE
Definition ApiBase.php:81
const PARAM_DFLT
Definition ApiBase.php:73
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:195
requireAtLeastOneParameter( $params,... $required)
Die if none of a certain set of parameters is set and not false.
Definition ApiBase.php:961
getResult()
Get the result object.
Definition ApiBase.php:628
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:764
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:162
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:497
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition ApiBase.php:1448
const PARAM_ISMULTI
Definition ApiBase.php:77
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.
BadFileLookup $badFileLookup
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:37
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:42
Prioritized list of file repositories.
Definition RepoGroup.php:33
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42