Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiQueryMyStashedFiles.php
blobace3a26ab167402d68872652e1f7375d657c1dde
1 <?php
2 /**
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
20 * @file
23 namespace MediaWiki\Api;
25 use Wikimedia\ParamValidator\ParamValidator;
26 use Wikimedia\ParamValidator\TypeDef\IntegerDef;
28 /**
29 * action=query&list=mystashedfiles module, gets all stashed files for
30 * the current user.
32 * @ingroup API
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],
62 ] ) );
65 $this->addOption( 'LIMIT', $params['limit'] + 1 );
66 $this->addOption( 'ORDER BY', 'us_id' );
68 $prop = array_fill_keys( $params['prop'], true );
69 $this->addFieldsIf(
71 'us_size',
72 'us_image_width',
73 'us_image_height',
74 'us_image_bits'
77 isset( $prop['size'] )
79 $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) );
81 $res = $this->select( __METHOD__ );
82 $result = $this->getResult();
83 $count = 0;
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 );
90 break;
93 $item = [
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 );
112 if ( !$fit ) {
113 $this->setContinueEnumParameter( 'continue', $row->us_id );
114 break;
118 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' );
121 public function getAllowedParams() {
122 return [
123 'prop' => [
124 ParamValidator::PARAM_ISMULTI => true,
125 ParamValidator::PARAM_DEFAULT => '',
126 ParamValidator::PARAM_TYPE => [ 'size', 'type' ],
127 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
130 'limit' => [
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,
138 'continue' => [
139 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
144 protected function getExamplesMessages() {
145 return [
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' );