MediaWiki  1.34.0
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
66  } catch ( UploadStashFileNotFoundException $e ) {
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' => [
107  ApiBase::PARAM_ISMULTI => true,
108  ],
109  'sessionkey' => [
110  ApiBase::PARAM_ISMULTI => true,
112  ],
113  'prop' => [
114  ApiBase::PARAM_ISMULTI => true,
115  ApiBase::PARAM_DFLT => 'timestamp|url',
117  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
119  ],
120  'urlwidth' => [
121  ApiBase::PARAM_TYPE => 'integer',
122  ApiBase::PARAM_DFLT => -1,
124  'apihelp-query+imageinfo-param-urlwidth',
126  ],
127  ],
128  'urlheight' => [
129  ApiBase::PARAM_TYPE => 'integer',
130  ApiBase::PARAM_DFLT => -1,
131  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
132  ],
133  'urlparam' => [
134  ApiBase::PARAM_TYPE => 'string',
135  ApiBase::PARAM_DFLT => '',
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 }
$filter
$filter
Definition: profileinfo.php:344
ApiQueryStashImageInfo
A query action to get image information from temporarily stashed files.
Definition: ApiQueryStashImageInfo.php:28
ApiQueryStashImageInfo\getPropertyNames
static getPropertyNames( $filter=null)
Returns all possible parameters to siiprop.
Definition: ApiQueryStashImageInfo.php:84
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
RepoGroup\singleton
static singleton()
Definition: RepoGroup.php:60
UploadStashBadPathException
Definition: UploadStashBadPathException.php:26
ApiQueryImageInfo\mergeThumbParams
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
Definition: ApiQueryImageInfo.php:273
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:2014
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:131
ApiQueryStashImageInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryStashImageInfo.php:151
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:94
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:640
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
ApiQueryImageInfo
A query action to get image information and upload history.
Definition: ApiQueryImageInfo.php:30
ApiQueryImageInfo\getInfo
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
Definition: ApiQueryImageInfo.php:374
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:112
ApiBase\dieWithException
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition: ApiBase.php:2026
ApiQueryStashImageInfo\$propertyFilter
static $propertyFilter
Definition: ApiQueryStashImageInfo.php:73
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:761
ApiQueryStashImageInfo\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryStashImageInfo.php:30
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:528
ApiQueryImageInfo\TRANSFORM_LIMIT
const TRANSFORM_LIMIT
Definition: ApiQueryImageInfo.php:31
ApiQueryStashImageInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryStashImageInfo.php:34
UploadStashFileNotFoundException
Definition: UploadStashFileNotFoundException.php:26
ApiBase\requireAtLeastOneParameter
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:959
ApiQueryStashImageInfo\getPropertyMessages
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
Definition: ApiQueryStashImageInfo.php:97
ApiQueryStashImageInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryStashImageInfo.php:141
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
ApiQueryStashImageInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryStashImageInfo.php:104
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:520
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
ApiQueryImageInfo\getScale
getScale( $params)
From parameters, construct a 'scale' array.
Definition: ApiQueryImageInfo.php:244
ApiBase\PARAM_HELP_MSG_PER_VALUE
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