MediaWiki  master
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1 <?php
24 
31 
32  public function __construct( ApiQuery $query, $moduleName ) {
33  parent::__construct( $query, $moduleName, 'sii' );
34  }
35 
36  public function execute() {
37  if ( !$this->getUser()->isLoggedIn() ) {
38  $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
39  }
40 
41  $params = $this->extractRequestParams();
42  $modulePrefix = $this->getModulePrefix();
43 
44  $prop = array_flip( $params['prop'] );
45 
46  $scale = $this->getScale( $params );
47 
48  $result = $this->getResult();
49 
50  $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
51 
52  // Alias sessionkey to filekey, but give an existing filekey precedence.
53  if ( !$params['filekey'] && $params['sessionkey'] ) {
54  $params['filekey'] = $params['sessionkey'];
55  }
56 
57  try {
58  $stash = MediaWikiServices::getInstance()->getRepoGroup()
59  ->getLocalRepo()->getUploadStash( $this->getUser() );
60 
61  foreach ( $params['filekey'] as $filekey ) {
62  $file = $stash->getFile( $filekey );
63  $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
64  $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
65  $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
66  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
67  }
68  // @todo Update exception handling here to understand current getFile exceptions
69  } catch ( UploadStashFileNotFoundException $e ) {
70  $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
71  } catch ( UploadStashBadPathException $e ) {
72  $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
73  }
74  }
75 
76  private static $propertyFilter = [
77  'user', 'userid', 'comment', 'parsedcomment',
78  'mediatype', 'archivename', 'uploadwarning',
79  ];
80 
87  public static function getPropertyNames( $filter = null ) {
88  if ( $filter === null ) {
89  $filter = self::$propertyFilter;
90  }
91  return parent::getPropertyNames( $filter );
92  }
93 
100  public static function getPropertyMessages( $filter = null ) {
101  if ( $filter === null ) {
102  $filter = self::$propertyFilter;
103  }
104  return parent::getPropertyMessages( $filter );
105  }
106 
107  public function getAllowedParams() {
108  return [
109  'filekey' => [
110  ApiBase::PARAM_ISMULTI => true,
111  ],
112  'sessionkey' => [
113  ApiBase::PARAM_ISMULTI => true,
115  ],
116  'prop' => [
117  ApiBase::PARAM_ISMULTI => true,
118  ApiBase::PARAM_DFLT => 'timestamp|url',
120  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
122  ],
123  'urlwidth' => [
124  ApiBase::PARAM_TYPE => 'integer',
125  ApiBase::PARAM_DFLT => -1,
127  'apihelp-query+imageinfo-param-urlwidth',
129  ],
130  ],
131  'urlheight' => [
132  ApiBase::PARAM_TYPE => 'integer',
133  ApiBase::PARAM_DFLT => -1,
134  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
135  ],
136  'urlparam' => [
137  ApiBase::PARAM_TYPE => 'string',
138  ApiBase::PARAM_DFLT => '',
139  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
140  ],
141  ];
142  }
143 
144  protected function getExamplesMessages() {
145  return [
146  'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
147  => 'apihelp-query+stashimageinfo-example-simple',
148  'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
149  'siiurlwidth=120&siiprop=url'
150  => 'apihelp-query+stashimageinfo-example-params',
151  ];
152  }
153 
154  public function getHelpUrls() {
155  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
156  }
157 }
ApiQueryStashImageInfo
A query action to get image information from temporarily stashed files.
Definition: ApiQueryStashImageInfo.php:30
ApiQueryStashImageInfo\getPropertyNames
static getPropertyNames( $filter=null)
Returns all possible parameters to siiprop.
Definition: ApiQueryStashImageInfo.php:87
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
UploadStashBadPathException
@newable
Definition: UploadStashBadPathException.php:27
ApiQueryImageInfo\mergeThumbParams
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
Definition: ApiQueryImageInfo.php:274
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:160
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1381
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:106
ApiQueryStashImageInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryStashImageInfo.php:154
ApiBase\PARAM_TYPE
const PARAM_TYPE
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:70
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:564
$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:375
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:134
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:75
ApiQueryStashImageInfo\$propertyFilter
static $propertyFilter
Definition: ApiQueryStashImageInfo.php:76
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:716
ApiQueryStashImageInfo\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryStashImageInfo.php:32
ApiBase\requireAtLeastOneParameter
requireAtLeastOneParameter( $params,... $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:913
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:451
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:36
UploadStashFileNotFoundException
@newable
Definition: UploadStashFileNotFoundException.php:27
ApiQueryStashImageInfo\getPropertyMessages
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
Definition: ApiQueryStashImageInfo.php:100
ApiQueryStashImageInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryStashImageInfo.php:144
ApiBase\PARAM_DFLT
const PARAM_DFLT
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:68
ApiBase\dieWithException
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition: ApiBase.php:1393
ApiQueryStashImageInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryStashImageInfo.php:107
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:443
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:69
ApiQueryImageInfo\getScale
getScale( $params)
From parameters, construct a 'scale' array.
Definition: ApiQueryImageInfo.php:245
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:139