MediaWiki master
ApiQueryMyStashedFiles.php
Go to the documentation of this file.
1<?php
9namespace MediaWiki\Api;
10
13
21
22 public function __construct( ApiQuery $query, string $moduleName ) {
23 parent::__construct( $query, $moduleName, 'msf' );
24 }
25
26 public function execute() {
27 $user = $this->getUser();
28
29 if ( !$user->isRegistered() ) {
30 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'stashnotloggedin' );
31 }
32
33 // Note: If user is logged in but cannot upload, they can still see
34 // the list of stashed uploads...but it will probably be empty.
35
36 $params = $this->extractRequestParams();
37
38 $this->addTables( 'uploadstash' );
39
40 $this->addFields( [ 'us_id', 'us_key', 'us_status' ] );
41
42 $this->addWhere( [ 'us_user' => $user->getId() ] );
43
44 if ( $params['continue'] !== null ) {
45 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] );
46 $this->addWhere( $this->getDB()->buildComparison( '>=', [
47 'us_id' => (int)$cont[0],
48 ] ) );
49 }
50
51 $this->addOption( 'LIMIT', $params['limit'] + 1 );
52 $this->addOption( 'ORDER BY', 'us_id' );
53
54 $prop = array_fill_keys( $params['prop'], true );
55 $this->addFieldsIf(
56 [
57 'us_size',
58 'us_image_width',
59 'us_image_height',
60 'us_image_bits'
61 ],
62
63 isset( $prop['size'] )
64 );
65 $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) );
66
67 $res = $this->select( __METHOD__ );
68 $result = $this->getResult();
69 $count = 0;
70
71 foreach ( $res as $row ) {
72 if ( ++$count > $params['limit'] ) {
73 // We've reached the one extra which shows that there are
74 // additional files to be had. Stop here...
75 $this->setContinueEnumParameter( 'continue', $row->us_id );
76 break;
77 }
78
79 $item = [
80 'filekey' => $row->us_key,
81 'status' => $row->us_status,
82 ];
83
84 if ( isset( $prop['size'] ) ) {
85 $item['size'] = (int)$row->us_size;
86 $item['width'] = (int)$row->us_image_width;
87 $item['height'] = (int)$row->us_image_height;
88 $item['bits'] = (int)$row->us_image_bits;
89 }
90
91 if ( isset( $prop['type'] ) ) {
92 $item['mimetype'] = $row->us_mime;
93 $item['mediatype'] = $row->us_media_type;
94 }
95
96 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $item );
97
98 if ( !$fit ) {
99 $this->setContinueEnumParameter( 'continue', $row->us_id );
100 break;
101 }
102 }
103
104 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' );
105 }
106
108 public function getAllowedParams() {
109 return [
110 'prop' => [
111 ParamValidator::PARAM_ISMULTI => true,
112 ParamValidator::PARAM_DEFAULT => '',
113 ParamValidator::PARAM_TYPE => [ 'size', 'type' ],
115 ],
116
117 'limit' => [
118 ParamValidator::PARAM_TYPE => 'limit',
119 ParamValidator::PARAM_DEFAULT => 10,
120 IntegerDef::PARAM_MIN => 1,
121 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
122 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
123 ],
124
125 'continue' => [
126 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
127 ],
128 ];
129 }
130
132 protected function getExamplesMessages() {
133 return [
134 'action=query&list=mystashedfiles&msfprop=size'
135 => 'apihelp-query+mystashedfiles-example-simple',
136 ];
137 }
138
140 public function getHelpUrls() {
141 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:mystashedfiles';
142 }
143}
144
146class_alias( ApiQueryMyStashedFiles::class, 'ApiQueryMyStashedFiles' );
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1507
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:543
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1692
getResult()
Get the result object.
Definition ApiBase.php:682
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
Definition ApiBase.php:207
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:167
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:234
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:823
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:232
This is a base class for all Query modules.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only).
select( $method, $extraQuery=[], ?array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addFields( $value)
Add a set of fields to select to the internal array.
action=query&list=mystashedfiles module, gets all stashed files for the current user.
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
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, string $moduleName)
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
This is the main query class.
Definition ApiQuery.php:36
Service for formatting and validating API parameters.
Type definition for integer types.