MediaWiki REL1_34
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1<?php
29
30 public function __construct( ApiQuery $query, $moduleName ) {
31 parent::__construct( $query, $moduleName, 'sii' );
32 }
33
34 public function execute() {
35 if ( !$this->getUser()->isLoggedIn() ) {
36 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
37 }
38
39 $params = $this->extractRequestParams();
40 $modulePrefix = $this->getModulePrefix();
41
42 $prop = array_flip( $params['prop'] );
43
44 $scale = $this->getScale( $params );
45
46 $result = $this->getResult();
47
48 $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
49
50 // Alias sessionkey to filekey, but give an existing filekey precedence.
51 if ( !$params['filekey'] && $params['sessionkey'] ) {
52 $params['filekey'] = $params['sessionkey'];
53 }
54
55 try {
56 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
57
58 foreach ( $params['filekey'] as $filekey ) {
59 $file = $stash->getFile( $filekey );
60 $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
61 $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
62 $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
63 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
64 }
65 // @todo Update exception handling here to understand current getFile exceptions
67 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
68 } catch ( UploadStashBadPathException $e ) {
69 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
70 }
71 }
72
73 private static $propertyFilter = [
74 'user', 'userid', 'comment', 'parsedcomment',
75 'mediatype', 'archivename', 'uploadwarning',
76 ];
77
84 public static function getPropertyNames( $filter = null ) {
85 if ( $filter === null ) {
87 }
88 return parent::getPropertyNames( $filter );
89 }
90
97 public static function getPropertyMessages( $filter = null ) {
98 if ( $filter === null ) {
100 }
101 return parent::getPropertyMessages( $filter );
102 }
103
104 public function getAllowedParams() {
105 return [
106 'filekey' => [
108 ],
109 'sessionkey' => [
112 ],
113 'prop' => [
115 ApiBase::PARAM_DFLT => 'timestamp|url',
117 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
119 ],
120 'urlwidth' => [
121 ApiBase::PARAM_TYPE => 'integer',
124 'apihelp-query+imageinfo-param-urlwidth',
126 ],
127 ],
128 'urlheight' => [
129 ApiBase::PARAM_TYPE => 'integer',
131 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
132 ],
133 'urlparam' => [
134 ApiBase::PARAM_TYPE => 'string',
136 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
137 ],
138 ];
139 }
140
141 protected function getExamplesMessages() {
142 return [
143 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
144 => 'apihelp-query+stashimageinfo-example-simple',
145 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
146 'siiurlwidth=120&siiprop=url'
147 => 'apihelp-query+stashimageinfo-example-params',
148 ];
149 }
150
151 public function getHelpUrls() {
152 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
153 }
154}
getUser()
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:528
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:112
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:2014
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:94
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:55
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:164
getResult()
Get the result object.
Definition ApiBase.php:640
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:761
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition ApiBase.php:2026
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:131
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition ApiBase.php:959
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:520
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:58
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)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Definition ApiQuery.php:37
$filter
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42