Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -147,14 +147,15 @@ |
148 | 148 | * @return bool |
149 | 149 | */ |
150 | 150 | protected function selectUploadModule() { |
151 | | - global $wgAllowAsyncCopyUploads; |
152 | 151 | $request = $this->getMain()->getRequest(); |
153 | 152 | |
154 | 153 | // One and only one of the following parameters is needed |
155 | 154 | $this->requireOnlyOneParameter( $this->mParams, |
156 | 155 | 'sessionkey', 'file', 'url', 'statuskey' ); |
157 | 156 | |
158 | | - if ( $wgAllowAsyncCopyUploads && $this->mParams['statuskey'] ) { |
| 157 | + if ( $this->mParams['statuskey'] ) { |
| 158 | + $this->checkAsyncDownloadEnabled(); |
| 159 | + |
159 | 160 | // Status request for an async upload |
160 | 161 | $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] ); |
161 | 162 | if ( !isset( $sessionData['result'] ) ) { |
— | — | @@ -200,6 +201,8 @@ |
201 | 202 | |
202 | 203 | $async = false; |
203 | 204 | if ( $this->mParams['asyncdownload'] ) { |
| 205 | + $this->checkAsyncDownloadEnabled(); |
| 206 | + |
204 | 207 | if ( $this->mParams['leavemessage'] && !$this->mParams['ignorewarnings'] ) { |
205 | 208 | $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported', |
206 | 209 | 'missing-ignorewarnings' ); |
— | — | @@ -376,6 +379,16 @@ |
377 | 380 | |
378 | 381 | return $result; |
379 | 382 | } |
| 383 | + |
| 384 | + /** |
| 385 | + * Checks if asynchronous copy uploads are enabled and throws an error if they are not. |
| 386 | + */ |
| 387 | + protected function checkAsyncDownloadEnabled() { |
| 388 | + global $wgAllowAsyncCopyUploads; |
| 389 | + if ( !$wgAllowAsyncCopyUploads ) { |
| 390 | + $this->dieUsage( 'Asynchronous copy uploads disabled', 'asynccopyuploaddisabled'); |
| 391 | + } |
| 392 | + } |
380 | 393 | |
381 | 394 | public function mustBePosted() { |
382 | 395 | return true; |
— | — | @@ -412,16 +425,12 @@ |
413 | 426 | 'url' => null, |
414 | 427 | 'sessionkey' => null, |
415 | 428 | 'stash' => false, |
| 429 | + |
| 430 | + 'asyncdownload' => false, |
| 431 | + 'leavemessage' => false, |
| 432 | + 'statuskey' => null, |
416 | 433 | ); |
417 | 434 | |
418 | | - global $wgAllowAsyncCopyUploads; |
419 | | - if ( $wgAllowAsyncCopyUploads ) { |
420 | | - $params += array( |
421 | | - 'asyncdownload' => false, |
422 | | - 'leavemessage' => false, |
423 | | - 'statuskey' => null, |
424 | | - ); |
425 | | - } |
426 | 435 | return $params; |
427 | 436 | } |
428 | 437 | |
— | — | @@ -437,18 +446,13 @@ |
438 | 447 | 'file' => 'File contents', |
439 | 448 | 'url' => 'Url to fetch the file from', |
440 | 449 | 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.', |
441 | | - 'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.' |
| 450 | + 'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.', |
| 451 | + |
| 452 | + 'asyncdownload' => 'Make fetching a URL asynchronous', |
| 453 | + 'leavemessage' => 'If asyncdownload is used, leave a message on the user talk page if finished', |
| 454 | + 'statuskey' => 'Fetch the upload status for this session key', |
442 | 455 | ); |
443 | 456 | |
444 | | - global $wgAllowAsyncCopyUploads; |
445 | | - if ( $wgAllowAsyncCopyUploads ) { |
446 | | - $params += array( |
447 | | - 'asyncdownload' => 'Make fetching a URL asynchronous', |
448 | | - 'leavemessage' => 'If asyncdownload is used, leave a message on the user talk page if finished', |
449 | | - 'statuskey' => 'Fetch the upload status for this session key', |
450 | | - ); |
451 | | - } |
452 | | - |
453 | 457 | return $params; |
454 | 458 | |
455 | 459 | } |
— | — | @@ -483,6 +487,7 @@ |
484 | 488 | array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ), |
485 | 489 | array( 'code' => 'missingparam', 'info' => 'One of the parameters sessionkey, file, url, statuskey is required' ), |
486 | 490 | array( 'code' => 'invalidparammix', 'info' => 'The parameters sessionkey, file, url, statuskey can not be used together' ), |
| 491 | + array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ), |
487 | 492 | ) ); |
488 | 493 | } |
489 | 494 | |