Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryMyStashedFiles | |
0.00% |
0 / 73 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
72 | |||
| getAllowedParams | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * API for MediaWiki 1.27+ |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use Wikimedia\ParamValidator\ParamValidator; |
| 12 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
| 13 | |
| 14 | /** |
| 15 | * action=query&list=mystashedfiles module, gets all stashed files for |
| 16 | * the current user. |
| 17 | * |
| 18 | * @ingroup API |
| 19 | */ |
| 20 | class ApiQueryMyStashedFiles extends ApiQueryBase { |
| 21 | |
| 22 | public function __construct( ApiQuery $query, string $moduleName ) { |
| 23 | parent::__construct( $query, $moduleName, 'msf' ); |
| 24 | } |
| 25 | |
| 26 | public function execute() { |
| 27 | $user = $this->getUser(); |
| 28 | |
| 29 | if ( !$user->isRegistered() ) { |
| 30 | $this->dieWithError( 'apierror-mustbeloggedin-uploadstash', 'stashnotloggedin' ); |
| 31 | } |
| 32 | |
| 33 | // Note: If user is logged in but cannot upload, they can still see |
| 34 | // the list of stashed uploads...but it will probably be empty. |
| 35 | |
| 36 | $params = $this->extractRequestParams(); |
| 37 | |
| 38 | $this->addTables( 'uploadstash' ); |
| 39 | |
| 40 | $this->addFields( [ 'us_id', 'us_key', 'us_status' ] ); |
| 41 | |
| 42 | $this->addWhere( [ 'us_user' => $user->getId() ] ); |
| 43 | |
| 44 | if ( $params['continue'] !== null ) { |
| 45 | $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] ); |
| 46 | $this->addWhere( $this->getDB()->buildComparison( '>=', [ |
| 47 | 'us_id' => (int)$cont[0], |
| 48 | ] ) ); |
| 49 | } |
| 50 | |
| 51 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
| 52 | $this->addOption( 'ORDER BY', 'us_id' ); |
| 53 | |
| 54 | $prop = array_fill_keys( $params['prop'], true ); |
| 55 | $this->addFieldsIf( |
| 56 | [ |
| 57 | 'us_size', |
| 58 | 'us_image_width', |
| 59 | 'us_image_height', |
| 60 | 'us_image_bits' |
| 61 | ], |
| 62 | |
| 63 | isset( $prop['size'] ) |
| 64 | ); |
| 65 | $this->addFieldsIf( [ 'us_mime', 'us_media_type' ], isset( $prop['type'] ) ); |
| 66 | |
| 67 | $res = $this->select( __METHOD__ ); |
| 68 | $result = $this->getResult(); |
| 69 | $count = 0; |
| 70 | |
| 71 | foreach ( $res as $row ) { |
| 72 | if ( ++$count > $params['limit'] ) { |
| 73 | // We've reached the one extra which shows that there are |
| 74 | // additional files to be had. Stop here... |
| 75 | $this->setContinueEnumParameter( 'continue', $row->us_id ); |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | $item = [ |
| 80 | 'filekey' => $row->us_key, |
| 81 | 'status' => $row->us_status, |
| 82 | ]; |
| 83 | |
| 84 | if ( isset( $prop['size'] ) ) { |
| 85 | $item['size'] = (int)$row->us_size; |
| 86 | $item['width'] = (int)$row->us_image_width; |
| 87 | $item['height'] = (int)$row->us_image_height; |
| 88 | $item['bits'] = (int)$row->us_image_bits; |
| 89 | } |
| 90 | |
| 91 | if ( isset( $prop['type'] ) ) { |
| 92 | $item['mimetype'] = $row->us_mime; |
| 93 | $item['mediatype'] = $row->us_media_type; |
| 94 | } |
| 95 | |
| 96 | $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $item ); |
| 97 | |
| 98 | if ( !$fit ) { |
| 99 | $this->setContinueEnumParameter( 'continue', $row->us_id ); |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'file' ); |
| 105 | } |
| 106 | |
| 107 | /** @inheritDoc */ |
| 108 | public function getAllowedParams() { |
| 109 | return [ |
| 110 | 'prop' => [ |
| 111 | ParamValidator::PARAM_ISMULTI => true, |
| 112 | ParamValidator::PARAM_DEFAULT => '', |
| 113 | ParamValidator::PARAM_TYPE => [ 'size', 'type' ], |
| 114 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 115 | ], |
| 116 | |
| 117 | 'limit' => [ |
| 118 | ParamValidator::PARAM_TYPE => 'limit', |
| 119 | ParamValidator::PARAM_DEFAULT => 10, |
| 120 | IntegerDef::PARAM_MIN => 1, |
| 121 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 122 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2, |
| 123 | ], |
| 124 | |
| 125 | 'continue' => [ |
| 126 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 127 | ], |
| 128 | ]; |
| 129 | } |
| 130 | |
| 131 | /** @inheritDoc */ |
| 132 | protected function getExamplesMessages() { |
| 133 | return [ |
| 134 | 'action=query&list=mystashedfiles&msfprop=size' |
| 135 | => 'apihelp-query+mystashedfiles-example-simple', |
| 136 | ]; |
| 137 | } |
| 138 | |
| 139 | /** @inheritDoc */ |
| 140 | public function getHelpUrls() { |
| 141 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:mystashedfiles'; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** @deprecated class alias since 1.43 */ |
| 146 | class_alias( ApiQueryMyStashedFiles::class, 'ApiQueryMyStashedFiles' ); |