MediaWiki  master
ApiQueryStashImageInfo.php
Go to the documentation of this file.
1 <?php
24 
31 
33  private $repoGroup;
34 
42  public function __construct(
43  ApiQuery $query,
44  $moduleName,
48  ) {
49  parent::__construct(
50  $query,
51  $moduleName,
52  'sii',
53  $repoGroup,
56  );
57  $this->repoGroup = $repoGroup;
58  }
59 
60  public function execute() {
61  if ( !$this->getUser()->isRegistered() ) {
62  $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'notloggedin' );
63  }
64 
65  $params = $this->extractRequestParams();
66  $modulePrefix = $this->getModulePrefix();
67 
68  $prop = array_fill_keys( $params['prop'], true );
69 
70  $scale = $this->getScale( $params );
71 
72  $result = $this->getResult();
73 
74  $this->requireAtLeastOneParameter( $params, 'filekey', 'sessionkey' );
75 
76  // Alias sessionkey to filekey, but give an existing filekey precedence.
77  if ( !$params['filekey'] && $params['sessionkey'] ) {
78  $params['filekey'] = $params['sessionkey'];
79  }
80 
81  try {
82  $stash = $this->repoGroup->getLocalRepo()->getUploadStash( $this->getUser() );
83 
84  foreach ( $params['filekey'] as $filekey ) {
85  $file = $stash->getFile( $filekey );
86  $finalThumbParam = $this->mergeThumbParams( $file, $scale, $params['urlparam'] );
87  $imageInfo = ApiQueryImageInfo::getInfo( $file, $prop, $result, $finalThumbParam );
88  $result->addValue( [ 'query', $this->getModuleName() ], null, $imageInfo );
89  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], $modulePrefix );
90  }
91  // @todo Update exception handling here to understand current getFile exceptions
92  } catch ( UploadStashFileNotFoundException $e ) {
93  $this->dieWithException( $e, [ 'wrap' => 'apierror-stashedfilenotfound' ] );
94  } catch ( UploadStashBadPathException $e ) {
95  $this->dieWithException( $e, [ 'wrap' => 'apierror-stashpathinvalid' ] );
96  }
97  }
98 
99  private static $propertyFilter = [
100  'user', 'userid', 'comment', 'parsedcomment',
101  'mediatype', 'archivename', 'uploadwarning',
102  ];
103 
110  public static function getPropertyNames( $filter = null ) {
111  if ( $filter === null ) {
112  $filter = self::$propertyFilter;
113  }
114  return parent::getPropertyNames( $filter );
115  }
116 
123  public static function getPropertyMessages( $filter = null ) {
124  if ( $filter === null ) {
125  $filter = self::$propertyFilter;
126  }
127  return parent::getPropertyMessages( $filter );
128  }
129 
130  public function getAllowedParams() {
131  return [
132  'filekey' => [
133  ApiBase::PARAM_ISMULTI => true,
134  ],
135  'sessionkey' => [
136  ApiBase::PARAM_ISMULTI => true,
138  ],
139  'prop' => [
140  ApiBase::PARAM_ISMULTI => true,
141  ApiBase::PARAM_DFLT => 'timestamp|url',
143  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
145  ],
146  'urlwidth' => [
147  ApiBase::PARAM_TYPE => 'integer',
148  ApiBase::PARAM_DFLT => -1,
150  'apihelp-query+imageinfo-param-urlwidth',
152  ],
153  ],
154  'urlheight' => [
155  ApiBase::PARAM_TYPE => 'integer',
156  ApiBase::PARAM_DFLT => -1,
157  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlheight',
158  ],
159  'urlparam' => [
160  ApiBase::PARAM_TYPE => 'string',
161  ApiBase::PARAM_DFLT => '',
162  ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-urlparam',
163  ],
164  ];
165  }
166 
167  protected function getExamplesMessages() {
168  return [
169  'action=query&prop=stashimageinfo&siifilekey=124sd34rsdf567'
170  => 'apihelp-query+stashimageinfo-example-simple',
171  'action=query&prop=stashimageinfo&siifilekey=b34edoe3|bceffd4&' .
172  'siiurlwidth=120&siiprop=url'
173  => 'apihelp-query+stashimageinfo-example-params',
174  ];
175  }
176 
177  public function getHelpUrls() {
178  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Stashimageinfo';
179  }
180 }
ApiQueryStashImageInfo\$repoGroup
RepoGroup $repoGroup
Definition: ApiQueryStashImageInfo.php:33
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:110
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
UploadStashBadPathException
@newable
Definition: UploadStashBadPathException.php:27
ApiQueryImageInfo\$contentLanguage
Language $contentLanguage
Definition: ApiQueryImageInfo.php:39
ApiQueryImageInfo\mergeThumbParams
mergeThumbParams( $image, $thumbParams, $otherParams)
Validate and merge scale parameters with handler thumb parameters, give error if invalid.
Definition: ApiQueryImageInfo.php:309
MediaWiki\BadFileLookup
Definition: BadFileLookup.php:13
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1379
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:105
ApiQueryStashImageInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryStashImageInfo.php:177
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:72
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:571
$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:31
ApiQueryImageInfo\getInfo
static getInfo( $file, $prop, $result, $thumbParams=null, $opts=false)
Get result information for an image revision.
Definition: ApiQueryImageInfo.php:410
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
Definition: ApiBase.php:77
ApiQueryStashImageInfo\__construct
__construct(ApiQuery $query, $moduleName, RepoGroup $repoGroup, Language $contentLanguage, BadFileLookup $badFileLookup)
Definition: ApiQueryStashImageInfo.php:42
ApiQueryStashImageInfo\$propertyFilter
static $propertyFilter
Definition: ApiQueryStashImageInfo.php:99
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
ApiBase\requireAtLeastOneParameter
requireAtLeastOneParameter( $params,... $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:904
ApiQueryImageInfo\$badFileLookup
BadFileLookup $badFileLookup
Definition: ApiQueryImageInfo.php:42
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:448
ApiQueryImageInfo\TRANSFORM_LIMIT
const TRANSFORM_LIMIT
Definition: ApiQueryImageInfo.php:32
ApiQueryStashImageInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryStashImageInfo.php:60
UploadStashFileNotFoundException
@newable
Definition: UploadStashFileNotFoundException.php:27
ApiQueryStashImageInfo\getPropertyMessages
static getPropertyMessages( $filter=null)
Returns messages for all possible parameters to siiprop.
Definition: ApiQueryStashImageInfo.php:123
ApiQueryStashImageInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryStashImageInfo.php:167
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:70
ApiBase\dieWithException
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition: ApiBase.php:1391
ApiQueryStashImageInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryStashImageInfo.php:130
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:440
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:71
RepoGroup
Prioritized list of file repositories.
Definition: RepoGroup.php:32
ApiQueryImageInfo\getScale
getScale( $params)
From parameters, construct a 'scale' array.
Definition: ApiQueryImageInfo.php:280
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:138
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42