MediaWiki  master
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 ) {
86  $filter = self::$propertyFilter;
87  }
88  return parent::getPropertyNames( $filter );
89  }
90 
97  public static function getPropertyMessages( $filter = null ) {
98  if ( $filter === null ) {
99  $filter = self::$propertyFilter;
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',
116  ApiBase::PARAM_TYPE => self::getPropertyNames(),
117  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
118  ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages()
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 }
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
requireAtLeastOneParameter( $params,... $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:953
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:94
getResult()
Get the result object.
Definition: ApiBase.php:640
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:2005
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:2017
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
static getPropertyNames( $filter=null)
Returns all possible parameters to siiprop.
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
static singleton()
Definition: RepoGroup.php:60
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:520
$filter
A query action to get image information and upload history.
This is the main query class.
Definition: ApiQuery.php:37
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
Definition: ApiBase.php:131
getScale( $params)
From parameters, construct a &#39;scale&#39; array.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:528
__construct(ApiQuery $query, $moduleName)
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:112
A query action to get image information from temporarily stashed files.