PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / api / ApiQueryMyStashedFiles.php
blobd33dbfd1f8e2d2db8f692d9cf8ca17a20860b5f5
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 /**
24 * action=query&list=mystashedfiles module, gets all stashed files for
25 * the current user.
27 * @ingroup API
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->dieUsage( 'The upload stash is only available to logged-in users.', '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 $db = $this->getDB();
46 $params = $this->extractRequestParams();
48 $this->addTables( 'uploadstash' );
50 $this->addFields( array( 'us_id', 'us_key', 'us_status' ) );
52 $this->addWhere( array( 'us_user' => $user->getId() ) );
54 if ( $params['continue'] !== null ) {
55 $cont = explode( '|', $params['continue'] );
56 $this->dieContinueUsageIf( count( $cont ) != 1 );
57 $cont_from = (int)$cont[0];
58 $this->dieContinueUsageIf( strval( $cont_from ) !== $cont[0] );
59 $this->addWhere( "us_id >= $cont_from" );
62 $this->addOption( 'LIMIT', $params['limit'] + 1 );
63 $this->addOption( 'ORDER BY', 'us_id' );
65 $prop = array_flip( $params['prop'] );
66 $this->addFieldsIf(
67 array(
68 'us_size',
69 'us_image_width',
70 'us_image_height',
71 'us_image_bits'
74 isset( $prop['size'] )
76 $this->addFieldsIf( array( 'us_mime', 'us_media_type' ), isset( $prop['type'] ) );
78 $res = $this->select( __METHOD__ );
79 $result = $this->getResult();
80 $count = 0;
82 foreach ( $res as $row ) {
83 if ( ++$count > $params['limit'] ) {
84 // We've reached the one extra which shows that there are
85 // additional files to be had. Stop here...
86 $this->setContinueEnumParameter( 'continue', $row->us_id );
87 break;
90 $item = array(
91 'filekey' => $row->us_key,
92 'status' => $row->us_status,
95 if ( isset( $prop['size'] ) ) {
96 $item['size'] = (int) $row->us_size;
97 $item['width'] = (int) $row->us_image_width;
98 $item['height'] = (int) $row->us_image_height;
99 $item['bits'] = (int) $row->us_image_bits;
102 if ( isset( $prop['type'] ) ) {
103 $item['mimetype'] = $row->us_mime;
104 $item['mediatype'] = $row->us_media_type;
107 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item );
109 if ( !$fit ) {
110 $this->setContinueEnumParameter( 'continue', $row->us_id );
111 break;
115 $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'file' );
118 public function getAllowedParams() {
119 return array(
120 'prop' => array(
121 ApiBase::PARAM_ISMULTI => true,
122 ApiBase::PARAM_DFLT => '',
123 ApiBase::PARAM_TYPE => array( 'size', 'type' ),
124 ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
127 'limit' => array(
128 ApiBase::PARAM_TYPE => 'limit',
129 ApiBase::PARAM_DFLT => 10,
130 ApiBase::PARAM_MIN => 1,
131 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
132 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
135 'continue' => array(
136 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
141 protected function getExamplesMessages() {
142 return array(
143 'action=query&list=mystashedfiles&msfprop=size'
144 => 'apihelp-query+mystashedfiles-example-simple',
148 public function getHelpUrls() {
149 return 'https://www.mediawiki.org/wiki/API:mystashedfiles';