MediaWiki REL1_31
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
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' ] );
69 $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
70 }
71 }
72
73 private $propertyFilter = [
74 'user', 'userid', 'comment', 'parsedcomment',
75 'mediatype', 'archivename', 'uploadwarning',
76 ];
77
78 public function getAllowedParams() {
79 return [
80 'filekey' => [
82 ],
83 'sessionkey' => [
86 ],
87 'prop' => [
89 ApiBase::PARAM_DFLT => 'timestamp|url',
90 ApiBase::PARAM_TYPE => self::getPropertyNames( $this->propertyFilter ),
91 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
93 ],
94 'urlwidth' => [
95 ApiBase::PARAM_TYPE => 'integer',
98 'apihelp-query+imageinfo-param-urlwidth',
100 ],
101 ],
102 'urlheight' => [
103 ApiBase::PARAM_TYPE => 'integer',
105 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
106 ],
107 'urlparam' => [
108 ApiBase::PARAM_TYPE => 'string',
110 ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
111 ],
112 ];
113 }
114
115 protected function getExamplesMessages() {
116 return [
117 'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
118 => 'apihelp-query+stashimageinfo-example-simple',
119 'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
120 'siiurlwidth=120&siiprop=url'
121 => 'apihelp-query+stashimageinfo-example-params',
122 ];
123 }
124
125 public function getHelpUrls() {
126 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
127 }
128}
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition ApiBase.php:529
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:105
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1895
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
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:157
getResult()
Get the result object.
Definition ApiBase.php:641
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition ApiBase.php:1907
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:124
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition ApiBase.php:851
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
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 getPropertyNames( $filter=[])
Returns all possible parameters to iiprop.
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
static getPropertyMessages( $filter=[])
Returns messages for all possible parameters to iiprop.
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.
__construct(ApiQuery $query, $moduleName)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Definition ApiQuery.php:36
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
returning false will NOT prevent logging $e
Definition hooks.txt:2176
$params