Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -1087,6 +1087,10 @@ |
1088 | 1088 | 'nouploadmodule' => array( 'code' => 'nouploadmodule', 'info' => 'No upload module set' ), |
1089 | 1089 | 'uploaddisabled' => array( 'code' => 'uploaddisabled', 'info' => 'Uploads are not enabled. Make sure $wgEnableUploads is set to true in LocalSettings.php and the PHP ini setting file_uploads is true' ), |
1090 | 1090 | 'copyuploaddisabled' => array( 'code' => 'copyuploaddisabled', 'info' => 'Uploads by URL is not enabled. Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.' ), |
| 1091 | + |
| 1092 | + 'filename-tooshort' => array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ), |
| 1093 | + 'illegal-filename' => array( 'code' => 'illegal-filename', 'info' => 'The filename is not allowed' ), |
| 1094 | + 'filetype-missing' => array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ), |
1091 | 1095 | ); |
1092 | 1096 | |
1093 | 1097 | /** |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -82,14 +82,14 @@ |
83 | 83 | // Check if the uploaded file is sane |
84 | 84 | $this->verifyUpload(); |
85 | 85 | |
| 86 | + |
86 | 87 | // Check if the user has the rights to modify or overwrite the requested title |
87 | 88 | // (This check is irrelevant if stashing is already requested, since the errors |
88 | 89 | // can always be fixed by changing the title) |
89 | 90 | if ( ! $this->mParams['stash'] ) { |
90 | 91 | $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser ); |
91 | 92 | if ( $permErrors !== true ) { |
92 | | - // TODO: stash the upload and allow choosing a new name |
93 | | - $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 93 | + $this->dieRecoverableError( $permErrors[0], 'filename' ); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
— | — | @@ -146,6 +146,27 @@ |
147 | 147 | } |
148 | 148 | return $sessionKey; |
149 | 149 | } |
| 150 | + |
| 151 | + /** |
| 152 | + * Throw an error that the user can recover from by providing a better |
| 153 | + * value for $parameter |
| 154 | + * |
| 155 | + * @param $error array Error array suitable for passing to dieUsageMsg() |
| 156 | + * @param $parameter string Parameter that needs revising |
| 157 | + * @param $data array Optional extra data to pass to the user |
| 158 | + * @throws UsageException |
| 159 | + */ |
| 160 | + function dieRecoverableError( $error, $parameter, $data = array() ) { |
| 161 | + try { |
| 162 | + $data['sessionkey'] = $this->performStash(); |
| 163 | + } catch ( MWException $e ) { |
| 164 | + $data['stashfailed'] = $e->getMessage(); |
| 165 | + } |
| 166 | + $data['invalidparameter'] = $parameter; |
| 167 | + |
| 168 | + $parsed = $this->parseMsg( $error ); |
| 169 | + $this->dieUsage( $parsed['info'], $parsed['code'], 0, $data ); |
| 170 | + } |
150 | 171 | |
151 | 172 | /** |
152 | 173 | * Select an upload module and set it to mUpload. Dies on failure. If the |
— | — | @@ -262,15 +283,26 @@ |
263 | 284 | |
264 | 285 | // TODO: Move them to ApiBase's message map |
265 | 286 | switch( $verification['status'] ) { |
| 287 | + // Recoverable errors |
| 288 | + case UploadBase::MIN_LENGTH_PARTNAME: |
| 289 | + $this->dieRecoverableError( 'filename-tooshort', 'filename' ); |
| 290 | + break; |
| 291 | + case UploadBase::ILLEGAL_FILENAME: |
| 292 | + $this->dieRecoverableError( 'illegal-filename', 'filename', |
| 293 | + array( 'filename' => $verification['filtered'] ) ); |
| 294 | + break; |
| 295 | + case UploadBase::FILETYPE_MISSING: |
| 296 | + $this->dieRecoverableError( 'filetype-missing', 'filename' ); |
| 297 | + break; |
| 298 | + |
| 299 | + // Unrecoverable errors |
266 | 300 | case UploadBase::EMPTY_FILE: |
267 | 301 | $this->dieUsage( 'The file you submitted was empty', 'empty-file' ); |
268 | 302 | break; |
269 | 303 | case UploadBase::FILE_TOO_LARGE: |
270 | 304 | $this->dieUsage( 'The file you submitted was too large', 'file-too-large' ); |
271 | 305 | break; |
272 | | - case UploadBase::FILETYPE_MISSING: |
273 | | - $this->dieUsage( 'The file is missing an extension', 'filetype-missing' ); |
274 | | - break; |
| 306 | + |
275 | 307 | case UploadBase::FILETYPE_BADTYPE: |
276 | 308 | $this->dieUsage( 'This type of file is banned', 'filetype-banned', |
277 | 309 | 0, array( |
— | — | @@ -278,13 +310,6 @@ |
279 | 311 | 'allowed' => $wgFileExtensions |
280 | 312 | ) ); |
281 | 313 | break; |
282 | | - case UploadBase::MIN_LENGTH_PARTNAME: |
283 | | - $this->dieUsage( 'The filename is too short', 'filename-tooshort' ); |
284 | | - break; |
285 | | - case UploadBase::ILLEGAL_FILENAME: |
286 | | - $this->dieUsage( 'The filename is not allowed', 'illegal-filename', |
287 | | - 0, array( 'filename' => $verification['filtered'] ) ); |
288 | | - break; |
289 | 314 | case UploadBase::VERIFICATION_ERROR: |
290 | 315 | $this->getResult()->setIndexedTagName( $verification['details'], 'detail' ); |
291 | 316 | $this->dieUsage( 'This file did not pass file verification', 'verification-error', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -285,6 +285,8 @@ |
286 | 286 | * (bug 28226) prop=extlinks&eloffset should be an integer |
287 | 287 | * (bug 28070) Fix watchlist RSS for databases that store timestamps in a |
288 | 288 | real timestamp field. |
| 289 | +* API upload errors may now return the parameter that needs to be changed and |
| 290 | + a sessionkey to fix the error. |
289 | 291 | |
290 | 292 | === Languages updated in 1.18 === |
291 | 293 | |