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
24 * action=query&list=mystashedfiles module, gets all stashed files for
29 class ApiQueryMyStashedFiles
extends ApiQueryBase
{
31 public function __construct( ApiQuery
$query, $moduleName ) {
32 parent
::__construct( $query, $moduleName, 'msf' );
35 public function execute() {
36 $user = $this->getUser();
38 if ( $user->isAnon() ) {
39 $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'stashnotloggedin' );
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.
45 $params = $this->extractRequestParams();
47 $this->addTables( 'uploadstash' );
49 $this->addFields( [ 'us_id', 'us_key', 'us_status' ] );
51 $this->addWhere( [ 'us_user' => $user->getId() ] );
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" );
61 $this->addOption( 'LIMIT', $params['limit'] +
1 );
62 $this->addOption( 'ORDER BY', 'us_id' );
64 $prop = array_flip( $params['prop'] );
73 isset( $prop['size'] )
75 $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) );
77 $res = $this->select( __METHOD__
);
78 $result = $this->getResult();
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
);
90 'filekey' => $row->us_key
,
91 'status' => $row->us_status
,
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
;
101 if ( isset( $prop['type'] ) ) {
102 $item['mimetype'] = $row->us_mime
;
103 $item['mediatype'] = $row->us_media_type
;
106 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $item );
109 $this->setContinueEnumParameter( 'continue', $row->us_id
);
114 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' );
117 public function getAllowedParams() {
120 ApiBase
::PARAM_ISMULTI
=> true,
121 ApiBase
::PARAM_DFLT
=> '',
122 ApiBase
::PARAM_TYPE
=> [ 'size', 'type' ],
123 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
127 ApiBase
::PARAM_TYPE
=> 'limit',
128 ApiBase
::PARAM_DFLT
=> 10,
129 ApiBase
::PARAM_MIN
=> 1,
130 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
131 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
,
135 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
140 protected function getExamplesMessages() {
142 'action=query&list=mystashedfiles&msfprop=size'
143 => 'apihelp-query+mystashedfiles-example-simple',
147 public function getHelpUrls() {
148 return 'https://www.mediawiki.org/wiki/API:mystashedfiles';