MediaWiki  1.34.0
ApiQueryMyStashedFiles.php
Go to the documentation of this file.
1 <?php
30 
31  public function __construct( ApiQuery $query, $moduleName ) {
32  parent::__construct( $query, $moduleName, 'msf' );
33  }
34 
35  public function execute() {
36  $user = $this->getUser();
37 
38  if ( $user->isAnon() ) {
39  $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'stashnotloggedin' );
40  }
41 
42  // Note: If user is logged in but cannot upload, they can still see
43  // the list of stashed uploads...but it will probably be empty.
44 
45  $params = $this->extractRequestParams();
46 
47  $this->addTables( 'uploadstash' );
48 
49  $this->addFields( [ 'us_id', 'us_key', 'us_status' ] );
50 
51  $this->addWhere( [ 'us_user' => $user->getId() ] );
52 
53  if ( $params['continue'] !== null ) {
54  $cont = explode( '|', $params['continue'] );
55  $this->dieContinueUsageIf( count( $cont ) != 1 );
56  $cont_from = (int)$cont[0];
57  $this->dieContinueUsageIf( strval( $cont_from ) !== $cont[0] );
58  $this->addWhere( "us_id >= $cont_from" );
59  }
60 
61  $this->addOption( 'LIMIT', $params['limit'] + 1 );
62  $this->addOption( 'ORDER BY', 'us_id' );
63 
64  $prop = array_flip( $params['prop'] );
65  $this->addFieldsIf(
66  [
67  'us_size',
68  'us_image_width',
69  'us_image_height',
70  'us_image_bits'
71  ],
72 
73  isset( $prop['size'] )
74  );
75  $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) );
76 
77  $res = $this->select( __METHOD__ );
78  $result = $this->getResult();
79  $count = 0;
80 
81  foreach ( $res as $row ) {
82  if ( ++$count > $params['limit'] ) {
83  // We've reached the one extra which shows that there are
84  // additional files to be had. Stop here...
85  $this->setContinueEnumParameter( 'continue', $row->us_id );
86  break;
87  }
88 
89  $item = [
90  'filekey' => $row->us_key,
91  'status' => $row->us_status,
92  ];
93 
94  if ( isset( $prop['size'] ) ) {
95  $item['size'] = (int)$row->us_size;
96  $item['width'] = (int)$row->us_image_width;
97  $item['height'] = (int)$row->us_image_height;
98  $item['bits'] = (int)$row->us_image_bits;
99  }
100 
101  if ( isset( $prop['type'] ) ) {
102  $item['mimetype'] = $row->us_mime;
103  $item['mediatype'] = $row->us_media_type;
104  }
105 
106  $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $item );
107 
108  if ( !$fit ) {
109  $this->setContinueEnumParameter( 'continue', $row->us_id );
110  break;
111  }
112  }
113 
114  $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' );
115  }
116 
117  public function getAllowedParams() {
118  return [
119  'prop' => [
120  ApiBase::PARAM_ISMULTI => true,
121  ApiBase::PARAM_DFLT => '',
122  ApiBase::PARAM_TYPE => [ 'size', 'type' ],
124  ],
125 
126  'limit' => [
127  ApiBase::PARAM_TYPE => 'limit',
128  ApiBase::PARAM_DFLT => 10,
129  ApiBase::PARAM_MIN => 1,
132  ],
133 
134  'continue' => [
135  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
136  ],
137  ];
138  }
139 
140  protected function getExamplesMessages() {
141  return [
142  'action=query&list=mystashedfiles&msfprop=size'
143  => 'apihelp-query+mystashedfiles-example-simple',
144  ];
145  }
146 
147  public function getHelpUrls() {
148  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:mystashedfiles';
149  }
150 }
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:193
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
ApiQueryMyStashedFiles\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryMyStashedFiles.php:140
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
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
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:350
$res
$res
Definition: testCompression.php:52
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:207
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:106
ApiQueryMyStashedFiles\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryMyStashedFiles.php:31
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:259
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:97
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:161
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:375
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:761
ApiQueryMyStashedFiles\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryMyStashedFiles.php:147
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2208
ApiQueryMyStashedFiles
action=query&list=mystashedfiles module, gets all stashed files for the current user.
Definition: ApiQueryMyStashedFiles.php:29
ApiQueryMyStashedFiles\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryMyStashedFiles.php:35
ApiQueryMyStashedFiles\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryMyStashedFiles.php:117
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:261
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:55
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
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:103
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:228
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:492
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