3a9b5c5642c91b4e11e5f1e4ace9f6b9c04b361c
[lhc/web/wiklou.git] / includes / api / ApiUpload.php
1 <?php
2 /**
3 *
4 *
5 * Created on Aug 21, 2008
6 *
7 * Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @file
25 */
26
27 /**
28 * @ingroup API
29 */
30 class ApiUpload extends ApiBase {
31
32 /**
33 * @var UploadBase
34 */
35 protected $mUpload = null;
36
37 protected $mParams;
38
39 public function __construct( $main, $action ) {
40 parent::__construct( $main, $action );
41 }
42
43 public function execute() {
44 // Check whether upload is enabled
45 if ( !UploadBase::isEnabled() ) {
46 $this->dieUsageMsg( 'uploaddisabled' );
47 }
48
49 $user = $this->getUser();
50
51 // Parameter handling
52 $this->mParams = $this->extractRequestParams();
53 $request = $this->getMain()->getRequest();
54 // Add the uploaded file to the params array
55 $this->mParams['file'] = $request->getFileName( 'file' );
56 $this->mParams['chunk'] = $request->getFileName( 'chunk' );
57
58 // Copy the session key to the file key, for backward compatibility.
59 if( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) {
60 $this->mParams['filekey'] = $this->mParams['sessionkey'];
61 }
62
63 // Select an upload module
64 if ( !$this->selectUploadModule() ) {
65 // This is not a true upload, but a status request or similar
66 return;
67 }
68 if ( !isset( $this->mUpload ) ) {
69 $this->dieUsage( 'No upload module set', 'nomodule' );
70 }
71
72 // First check permission to upload
73 $this->checkPermissions( $user );
74
75 // Fetch the file
76 $status = $this->mUpload->fetchFile();
77 if ( !$status->isGood() ) {
78 $errors = $status->getErrorsArray();
79 $error = array_shift( $errors[0] );
80 $this->dieUsage( 'Error fetching file from remote source', $error, 0, $errors[0] );
81 }
82
83 // Check if the uploaded file is sane
84 if ( $this->mParams['chunk'] ) {
85 $maxSize = $this->mUpload->getMaxUploadSize( );
86 if( $this->mParams['filesize'] > $maxSize ) {
87 $this->dieUsage( 'The file you submitted was too large', 'file-too-large' );
88 }
89 } else {
90 $this->verifyUpload();
91 }
92
93 // Check if the user has the rights to modify or overwrite the requested title
94 // (This check is irrelevant if stashing is already requested, since the errors
95 // can always be fixed by changing the title)
96 if ( ! $this->mParams['stash'] ) {
97 $permErrors = $this->mUpload->verifyTitlePermissions( $user );
98 if ( $permErrors !== true ) {
99 $this->dieRecoverableError( $permErrors[0], 'filename' );
100 }
101 }
102 // Get the result based on the current upload context:
103 $result = $this->getContextResult();
104
105 if ( $result['result'] === 'Success' ) {
106 $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() );
107 }
108
109 $this->getResult()->addValue( null, $this->getModuleName(), $result );
110
111 // Cleanup any temporary mess
112 $this->mUpload->cleanupTempFile();
113 }
114 /**
115 * Get an uplaod result based on upload context
116 * @return array
117 */
118 private function getContextResult(){
119 $warnings = $this->getApiWarnings();
120 if ( $warnings && !$this->mParams['ignorewarnings'] ) {
121 // Get warnings formated in result array format
122 return $this->getWarningsResult( $warnings );
123 } elseif ( $this->mParams['chunk'] ) {
124 // Add chunk, and get result
125 return $this->getChunkResult( $warnings );
126 } elseif ( $this->mParams['stash'] ) {
127 // Stash the file and get stash result
128 return $this->getStashResult( $warnings );
129 }
130 // This is the most common case -- a normal upload with no warnings
131 // performUpload will return a formatted properly for the API with status
132 return $this->performUpload( $warnings );
133 }
134 /**
135 * Get Stash Result, throws an expetion if the file could not be stashed.
136 * @param $warnings array Array of Api upload warnings
137 * @return array
138 */
139 private function getStashResult( $warnings ){
140 $result = array ();
141 // Some uploads can request they be stashed, so as not to publish them immediately.
142 // In this case, a failure to stash ought to be fatal
143 try {
144 $result['result'] = 'Success';
145 $result['filekey'] = $this->performStash();
146 $result['sessionkey'] = $result['filekey']; // backwards compatibility
147 if ( $warnings && count( $warnings ) > 0 ) {
148 $result['warnings'] = $warnings;
149 }
150 } catch ( MWException $e ) {
151 $this->dieUsage( $e->getMessage(), 'stashfailed' );
152 }
153 return $result;
154 }
155 /**
156 * Get Warnings Result
157 * @param $warnings array Array of Api upload warnings
158 * @return array
159 */
160 private function getWarningsResult( $warnings ){
161 $result = array();
162 $result['result'] = 'Warning';
163 $result['warnings'] = $warnings;
164 // in case the warnings can be fixed with some further user action, let's stash this upload
165 // and return a key they can use to restart it
166 try {
167 $result['filekey'] = $this->performStash();
168 $result['sessionkey'] = $result['filekey']; // backwards compatibility
169 } catch ( MWException $e ) {
170 $result['warnings']['stashfailed'] = $e->getMessage();
171 }
172 return $result;
173 }
174 /**
175 * Get the result of a chunk upload.
176 * @param $warnings array Array of Api upload warnings
177 * @return array
178 */
179 private function getChunkResult( $warnings ){
180 $result = array();
181
182 $result['result'] = 'Continue';
183 if ( $warnings && count( $warnings ) > 0 ) {
184 $result['warnings'] = $warnings;
185 }
186 $request = $this->getMain()->getRequest();
187 $chunkPath = $request->getFileTempname( 'chunk' );
188 $chunkSize = $request->getUpload( 'chunk' )->getSize();
189 if ($this->mParams['offset'] == 0) {
190 $result['filekey'] = $this->performStash();
191 } else {
192 $status = $this->mUpload->addChunk($chunkPath, $chunkSize,
193 $this->mParams['offset']);
194 if ( !$status->isGood() ) {
195 $this->dieUsage( $status->getWikiText(), 'stashfailed' );
196 return array();
197 }
198
199 // Check we added the last chunk:
200 if( $this->mParams['offset'] + $chunkSize == $this->mParams['filesize'] ) {
201 $status = $this->mUpload->concatenateChunks();
202
203 if ( !$status->isGood() ) {
204 $this->dieUsage( $status->getWikiText(), 'stashfailed' );
205 return array();
206 }
207
208 // We have a new filekey for the fully concatenated file.
209 $result['filekey'] = $this->mUpload->getLocalFile()->getFileKey();
210
211 // Remove chunk from stash. (Checks against user ownership of chunks.)
212 $this->mUpload->stash->removeFile( $this->mParams['filekey'] );
213
214 $result['result'] = 'Success';
215
216 } else {
217
218 // Continue passing through the filekey for adding further chunks.
219 $result['filekey'] = $this->mParams['filekey'];
220 }
221 }
222 $result['offset'] = $this->mParams['offset'] + $chunkSize;
223 return $result;
224 }
225
226 /**
227 * Stash the file and return the file key
228 * Also re-raises exceptions with slightly more informative message strings (useful for API)
229 * @throws MWException
230 * @return String file key
231 */
232 function performStash() {
233 try {
234 $stashFile = $this->mUpload->stashFile();
235
236 if ( !$stashFile ) {
237 throw new MWException( 'Invalid stashed file' );
238 }
239 $fileKey = $stashFile->getFileKey();
240 } catch ( MWException $e ) {
241 $message = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage();
242 wfDebug( __METHOD__ . ' ' . $message . "\n");
243 throw new MWException( $message );
244 }
245 return $fileKey;
246 }
247
248 /**
249 * Throw an error that the user can recover from by providing a better
250 * value for $parameter
251 *
252 * @param $error array Error array suitable for passing to dieUsageMsg()
253 * @param $parameter string Parameter that needs revising
254 * @param $data array Optional extra data to pass to the user
255 * @throws UsageException
256 */
257 function dieRecoverableError( $error, $parameter, $data = array() ) {
258 try {
259 $data['filekey'] = $this->performStash();
260 $data['sessionkey'] = $data['filekey'];
261 } catch ( MWException $e ) {
262 $data['stashfailed'] = $e->getMessage();
263 }
264 $data['invalidparameter'] = $parameter;
265
266 $parsed = $this->parseMsg( $error );
267 $this->dieUsage( $parsed['info'], $parsed['code'], 0, $data );
268 }
269
270 /**
271 * Select an upload module and set it to mUpload. Dies on failure. If the
272 * request was a status request and not a true upload, returns false;
273 * otherwise true
274 *
275 * @return bool
276 */
277 protected function selectUploadModule() {
278 $request = $this->getMain()->getRequest();
279
280 // chunk or one and only one of the following parameters is needed
281 if( !$this->mParams['chunk'] ) {
282 $this->requireOnlyOneParameter( $this->mParams,
283 'filekey', 'file', 'url', 'statuskey' );
284 }
285
286 if ( $this->mParams['statuskey'] ) {
287 $this->checkAsyncDownloadEnabled();
288
289 // Status request for an async upload
290 $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] );
291 if ( !isset( $sessionData['result'] ) ) {
292 $this->dieUsage( 'No result in session data', 'missingresult' );
293 }
294 if ( $sessionData['result'] == 'Warning' ) {
295 $sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] );
296 $sessionData['sessionkey'] = $this->mParams['statuskey'];
297 }
298 $this->getResult()->addValue( null, $this->getModuleName(), $sessionData );
299 return false;
300
301 }
302
303 // The following modules all require the filename parameter to be set
304 if ( is_null( $this->mParams['filename'] ) ) {
305 $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
306 }
307
308 if ( $this->mParams['chunk'] ) {
309 // Chunk upload
310 $this->mUpload = new UploadFromChunks();
311 if( isset( $this->mParams['filekey'] ) ){
312 // handle new chunk
313 $this->mUpload->continueChunks(
314 $this->mParams['filename'],
315 $this->mParams['filekey'],
316 $request->getUpload( 'chunk' )
317 );
318 } else {
319 // handle first chunk
320 $this->mUpload->initialize(
321 $this->mParams['filename'],
322 $request->getUpload( 'chunk' )
323 );
324 }
325 } elseif ( isset( $this->mParams['filekey'] ) ) {
326 // Upload stashed in a previous request
327 if ( !UploadFromStash::isValidKey( $this->mParams['filekey'] ) ) {
328 $this->dieUsageMsg( 'invalid-file-key' );
329 }
330
331 $this->mUpload = new UploadFromStash( $this->getUser() );
332
333 $this->mUpload->initialize( $this->mParams['filekey'], $this->mParams['filename'] );
334 } elseif ( isset( $this->mParams['file'] ) ) {
335 $this->mUpload = new UploadFromFile();
336 $this->mUpload->initialize(
337 $this->mParams['filename'],
338 $request->getUpload( 'file' )
339 );
340 } elseif ( isset( $this->mParams['url'] ) ) {
341 // Make sure upload by URL is enabled:
342 if ( !UploadFromUrl::isEnabled() ) {
343 $this->dieUsageMsg( 'copyuploaddisabled' );
344 }
345
346 if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
347 $this->dieUsageMsg( 'copyuploadbaddomain' );
348 }
349
350 $async = false;
351 if ( $this->mParams['asyncdownload'] ) {
352 $this->checkAsyncDownloadEnabled();
353
354 if ( $this->mParams['leavemessage'] && !$this->mParams['ignorewarnings'] ) {
355 $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported',
356 'missing-ignorewarnings' );
357 }
358
359 if ( $this->mParams['leavemessage'] ) {
360 $async = 'async-leavemessage';
361 } else {
362 $async = 'async';
363 }
364 }
365 $this->mUpload = new UploadFromUrl;
366 $this->mUpload->initialize( $this->mParams['filename'],
367 $this->mParams['url'], $async );
368 }
369
370 return true;
371 }
372
373 /**
374 * Checks that the user has permissions to perform this upload.
375 * Dies with usage message on inadequate permissions.
376 * @param $user User The user to check.
377 */
378 protected function checkPermissions( $user ) {
379 // Check whether the user has the appropriate permissions to upload anyway
380 $permission = $this->mUpload->isAllowed( $user );
381
382 if ( $permission !== true ) {
383 if ( !$user->isLoggedIn() ) {
384 $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
385 } else {
386 $this->dieUsageMsg( 'badaccess-groups' );
387 }
388 }
389 }
390
391 /**
392 * Performs file verification, dies on error.
393 */
394 protected function verifyUpload( ) {
395 global $wgFileExtensions;
396
397 $verification = $this->mUpload->verifyUpload( );
398 if ( $verification['status'] === UploadBase::OK ) {
399 return;
400 }
401
402 // TODO: Move them to ApiBase's message map
403 switch( $verification['status'] ) {
404 // Recoverable errors
405 case UploadBase::MIN_LENGTH_PARTNAME:
406 $this->dieRecoverableError( 'filename-tooshort', 'filename' );
407 break;
408 case UploadBase::ILLEGAL_FILENAME:
409 $this->dieRecoverableError( 'illegal-filename', 'filename',
410 array( 'filename' => $verification['filtered'] ) );
411 break;
412 case UploadBase::FILENAME_TOO_LONG:
413 $this->dieRecoverableError( 'filename-toolong', 'filename' );
414 break;
415 case UploadBase::FILETYPE_MISSING:
416 $this->dieRecoverableError( 'filetype-missing', 'filename' );
417 break;
418 case UploadBase::WINDOWS_NONASCII_FILENAME:
419 $this->dieRecoverableError( 'windows-nonascii-filename', 'filename' );
420 break;
421
422 // Unrecoverable errors
423 case UploadBase::EMPTY_FILE:
424 $this->dieUsage( 'The file you submitted was empty', 'empty-file' );
425 break;
426 case UploadBase::FILE_TOO_LARGE:
427 $this->dieUsage( 'The file you submitted was too large', 'file-too-large' );
428 break;
429
430 case UploadBase::FILETYPE_BADTYPE:
431 $extradata = array(
432 'filetype' => $verification['finalExt'],
433 'allowed' => $wgFileExtensions
434 );
435 $this->getResult()->setIndexedTagName( $extradata['allowed'], 'ext' );
436
437 $msg = "Filetype not permitted: ";
438 if ( isset( $verification['blacklistedExt'] ) ) {
439 $msg .= join( ', ', $verification['blacklistedExt'] );
440 $extradata['blacklisted'] = array_values( $verification['blacklistedExt'] );
441 $this->getResult()->setIndexedTagName( $extradata['blacklisted'], 'ext' );
442 } else {
443 $msg .= $verification['finalExt'];
444 }
445 $this->dieUsage( $msg, 'filetype-banned', 0, $extradata );
446 break;
447 case UploadBase::VERIFICATION_ERROR:
448 $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
449 $this->dieUsage( 'This file did not pass file verification', 'verification-error',
450 0, array( 'details' => $verification['details'] ) );
451 break;
452 case UploadBase::HOOK_ABORTED:
453 $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
454 'hookaborted', 0, array( 'error' => $verification['error'] ) );
455 break;
456 default:
457 $this->dieUsage( 'An unknown error occurred', 'unknown-error',
458 0, array( 'code' => $verification['status'] ) );
459 break;
460 }
461 }
462
463
464 /**
465 * Check warnings.
466 * Returns a suitable array for inclusion into API results if there were warnings
467 * Returns the empty array if there were no warnings
468 *
469 * @return array
470 */
471 protected function getApiWarnings() {
472 $warnings = $this->mUpload->checkWarnings();
473
474 return $this->transformWarnings( $warnings );
475 }
476
477 protected function transformWarnings( $warnings ) {
478 if ( $warnings ) {
479 // Add indices
480 $result = $this->getResult();
481 $result->setIndexedTagName( $warnings, 'warning' );
482
483 if ( isset( $warnings['duplicate'] ) ) {
484 $dupes = array();
485 foreach ( $warnings['duplicate'] as $dupe ) {
486 $dupes[] = $dupe->getName();
487 }
488 $result->setIndexedTagName( $dupes, 'duplicate' );
489 $warnings['duplicate'] = $dupes;
490 }
491
492 if ( isset( $warnings['exists'] ) ) {
493 $warning = $warnings['exists'];
494 unset( $warnings['exists'] );
495 $warnings[$warning['warning']] = $warning['file']->getName();
496 }
497 }
498 return $warnings;
499 }
500
501
502 /**
503 * Perform the actual upload. Returns a suitable result array on success;
504 * dies on failure.
505 *
506 * @param $warnings array Array of Api upload warnings
507 * @return array
508 */
509 protected function performUpload( $warnings ) {
510 // Use comment as initial page text by default
511 if ( is_null( $this->mParams['text'] ) ) {
512 $this->mParams['text'] = $this->mParams['comment'];
513 }
514
515 $file = $this->mUpload->getLocalFile();
516 $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() );
517
518 // Deprecated parameters
519 if ( $this->mParams['watch'] ) {
520 $watch = true;
521 }
522
523 // No errors, no warnings: do the upload
524 $status = $this->mUpload->performUpload( $this->mParams['comment'],
525 $this->mParams['text'], $watch, $this->getUser() );
526
527 if ( !$status->isGood() ) {
528 $error = $status->getErrorsArray();
529
530 if ( count( $error ) == 1 && $error[0][0] == 'async' ) {
531 // The upload can not be performed right now, because the user
532 // requested so
533 return array(
534 'result' => 'Queued',
535 'statuskey' => $error[0][1],
536 );
537 } else {
538 $this->getResult()->setIndexedTagName( $error, 'error' );
539
540 $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
541 }
542 }
543
544 $file = $this->mUpload->getLocalFile();
545
546 $result['result'] = 'Success';
547 $result['filename'] = $file->getName();
548 if ( $warnings && count( $warnings ) > 0 ) {
549 $result['warnings'] = $warnings;
550 }
551
552 return $result;
553 }
554
555 /**
556 * Checks if asynchronous copy uploads are enabled and throws an error if they are not.
557 */
558 protected function checkAsyncDownloadEnabled() {
559 global $wgAllowAsyncCopyUploads;
560 if ( !$wgAllowAsyncCopyUploads ) {
561 $this->dieUsage( 'Asynchronous copy uploads disabled', 'asynccopyuploaddisabled');
562 }
563 }
564
565 public function mustBePosted() {
566 return true;
567 }
568
569 public function isWriteMode() {
570 return true;
571 }
572
573 public function getAllowedParams() {
574 $params = array(
575 'filename' => array(
576 ApiBase::PARAM_TYPE => 'string',
577 ),
578 'comment' => array(
579 ApiBase::PARAM_DFLT => ''
580 ),
581 'text' => null,
582 'token' => array(
583 ApiBase::PARAM_TYPE => 'string',
584 ApiBase::PARAM_REQUIRED => true
585 ),
586 'watch' => array(
587 ApiBase::PARAM_DFLT => false,
588 ApiBase::PARAM_DEPRECATED => true,
589 ),
590 'watchlist' => array(
591 ApiBase::PARAM_DFLT => 'preferences',
592 ApiBase::PARAM_TYPE => array(
593 'watch',
594 'preferences',
595 'nochange'
596 ),
597 ),
598 'ignorewarnings' => false,
599 'file' => null,
600 'url' => null,
601 'filekey' => null,
602 'sessionkey' => array(
603 ApiBase::PARAM_DFLT => null,
604 ApiBase::PARAM_DEPRECATED => true,
605 ),
606 'stash' => false,
607
608 'filesize' => null,
609 'offset' => null,
610 'chunk' => null,
611
612 'asyncdownload' => false,
613 'leavemessage' => false,
614 'statuskey' => null,
615 );
616
617 return $params;
618 }
619
620 public function getParamDescription() {
621 $params = array(
622 'filename' => 'Target filename',
623 'token' => 'Edit token. You can get one of these through prop=info',
624 'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified',
625 'text' => 'Initial page text for new files',
626 'watch' => 'Watch the page',
627 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
628 'ignorewarnings' => 'Ignore any warnings',
629 'file' => 'File contents',
630 'url' => 'URL to fetch the file from',
631 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.',
632 'sessionkey' => 'Same as filekey, maintained for backward compatibility.',
633 'stash' => 'If set, the server will not add the file to the repository and stash it temporarily.',
634
635 'chunk' => 'Chunk contents',
636 'offset' => 'Offset of chunk in bytes',
637 'filesize' => 'Filesize of entire upload',
638
639 'asyncdownload' => 'Make fetching a URL asynchronous',
640 'leavemessage' => 'If asyncdownload is used, leave a message on the user talk page if finished',
641 'statuskey' => 'Fetch the upload status for this file key',
642 );
643
644 return $params;
645
646 }
647
648 public function getResultProperties() {
649 return array(
650 '' => array(
651 'result' => array(
652 ApiBase::PROP_TYPE => array(
653 'Success',
654 'Warning',
655 'Continue',
656 'Queued'
657 ),
658 ),
659 'filekey' => array(
660 ApiBase::PROP_TYPE => 'string',
661 ApiBase::PROP_NULLABLE => true
662 ),
663 'sessionkey' => array(
664 ApiBase::PROP_TYPE => 'string',
665 ApiBase::PROP_NULLABLE => true
666 ),
667 'offset' => array(
668 ApiBase::PROP_TYPE => 'integer',
669 ApiBase::PROP_NULLABLE => true
670 ),
671 'statuskey' => array(
672 ApiBase::PROP_TYPE => 'string',
673 ApiBase::PROP_NULLABLE => true
674 ),
675 'filename' => array(
676 ApiBase::PROP_TYPE => 'string',
677 ApiBase::PROP_NULLABLE => true
678 )
679 )
680 );
681 }
682
683 public function getDescription() {
684 return array(
685 'Upload a file, or get the status of pending uploads. Several methods are available:',
686 ' * Upload file contents directly, using the "file" parameter',
687 ' * Have the MediaWiki server fetch a file from a URL, using the "url" parameter',
688 ' * Complete an earlier upload that failed due to warnings, using the "filekey" parameter',
689 'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
690 'sending the "file". Also you must get and send an edit token before doing any upload stuff'
691 );
692 }
693
694 public function getPossibleErrors() {
695 return array_merge( parent::getPossibleErrors(),
696 $this->getRequireOnlyOneParameterErrorMessages( array( 'filekey', 'file', 'url', 'statuskey' ) ),
697 array(
698 array( 'uploaddisabled' ),
699 array( 'invalid-file-key' ),
700 array( 'uploaddisabled' ),
701 array( 'mustbeloggedin', 'upload' ),
702 array( 'badaccess-groups' ),
703 array( 'code' => 'fetchfileerror', 'info' => '' ),
704 array( 'code' => 'nomodule', 'info' => 'No upload module set' ),
705 array( 'code' => 'empty-file', 'info' => 'The file you submitted was empty' ),
706 array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ),
707 array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ),
708 array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ),
709 array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ),
710 array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ),
711 array( 'code' => 'asynccopyuploaddisabled', 'info' => 'Asynchronous copy uploads disabled' ),
712 array( 'fileexists-forbidden' ),
713 array( 'fileexists-shared-forbidden' ),
714 )
715 );
716 }
717
718 public function needsToken() {
719 return true;
720 }
721
722 public function getTokenSalt() {
723 return '';
724 }
725
726 public function getExamples() {
727 return array(
728 'api.php?action=upload&filename=Wiki.png&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
729 => 'Upload from a URL',
730 'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1'
731 => 'Complete an upload that failed due to warnings',
732 );
733 }
734
735 public function getHelpUrls() {
736 return 'https://www.mediawiki.org/wiki/API:Upload';
737 }
738
739 public function getVersion() {
740 return __CLASS__ . ': $Id$';
741 }
742 }