3 * API for MediaWiki 1.27+
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Api
;
25 use Wikimedia\ParamValidator\ParamValidator
;
26 use Wikimedia\ParamValidator\TypeDef\IntegerDef
;
29 * action=query&list=mystashedfiles module, gets all stashed files for
34 class ApiQueryMyStashedFiles
extends ApiQueryBase
{
36 public function __construct( ApiQuery
$query, string $moduleName ) {
37 parent
::__construct( $query, $moduleName, 'msf' );
40 public function execute() {
41 $user = $this->getUser();
43 if ( !$user->isRegistered() ) {
44 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'stashnotloggedin' );
47 // Note: If user is logged in but cannot upload, they can still see
48 // the list of stashed uploads...but it will probably be empty.
50 $params = $this->extractRequestParams();
52 $this->addTables( 'uploadstash' );
54 $this->addFields( [ 'us_id', 'us_key', 'us_status' ] );
56 $this->addWhere( [ 'us_user' => $user->getId() ] );
58 if ( $params['continue'] !== null ) {
59 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] );
60 $this->addWhere( $this->getDB()->buildComparison( '>=', [
61 'us_id' => (int)$cont[0],
65 $this->addOption( 'LIMIT', $params['limit'] +
1 );
66 $this->addOption( 'ORDER BY', 'us_id' );
68 $prop = array_fill_keys( $params['prop'], true );
77 isset( $prop['size'] )
79 $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) );
81 $res = $this->select( __METHOD__
);
82 $result = $this->getResult();
85 foreach ( $res as $row ) {
86 if ( ++
$count > $params['limit'] ) {
87 // We've reached the one extra which shows that there are
88 // additional files to be had. Stop here...
89 $this->setContinueEnumParameter( 'continue', $row->us_id
);
94 'filekey' => $row->us_key
,
95 'status' => $row->us_status
,
98 if ( isset( $prop['size'] ) ) {
99 $item['size'] = (int)$row->us_size
;
100 $item['width'] = (int)$row->us_image_width
;
101 $item['height'] = (int)$row->us_image_height
;
102 $item['bits'] = (int)$row->us_image_bits
;
105 if ( isset( $prop['type'] ) ) {
106 $item['mimetype'] = $row->us_mime
;
107 $item['mediatype'] = $row->us_media_type
;
110 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $item );
113 $this->setContinueEnumParameter( 'continue', $row->us_id
);
118 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' );
121 public function getAllowedParams() {
124 ParamValidator
::PARAM_ISMULTI
=> true,
125 ParamValidator
::PARAM_DEFAULT
=> '',
126 ParamValidator
::PARAM_TYPE
=> [ 'size', 'type' ],
127 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
131 ParamValidator
::PARAM_TYPE
=> 'limit',
132 ParamValidator
::PARAM_DEFAULT
=> 10,
133 IntegerDef
::PARAM_MIN
=> 1,
134 IntegerDef
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
135 IntegerDef
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
,
139 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
144 protected function getExamplesMessages() {
146 'action=query&list=mystashedfiles&msfprop=size'
147 => 'apihelp-query+mystashedfiles-example-simple',
151 public function getHelpUrls() {
152 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:mystashedfiles';
156 /** @deprecated class alias since 1.43 */
157 class_alias( ApiQueryMyStashedFiles
::class, 'ApiQueryMyStashedFiles' );