MediaWiki
REL1_24
|
00001 <?php 00030 class ApiUpload extends ApiBase { 00032 protected $mUpload = null; 00033 00034 protected $mParams; 00035 00036 public function execute() { 00037 // Check whether upload is enabled 00038 if ( !UploadBase::isEnabled() ) { 00039 $this->dieUsageMsg( 'uploaddisabled' ); 00040 } 00041 00042 $user = $this->getUser(); 00043 00044 // Parameter handling 00045 $this->mParams = $this->extractRequestParams(); 00046 $request = $this->getMain()->getRequest(); 00047 // Check if async mode is actually supported (jobs done in cli mode) 00048 $this->mParams['async'] = ( $this->mParams['async'] && $this->getConfig()->get( 'EnableAsyncUploads' ) ); 00049 // Add the uploaded file to the params array 00050 $this->mParams['file'] = $request->getFileName( 'file' ); 00051 $this->mParams['chunk'] = $request->getFileName( 'chunk' ); 00052 00053 // Copy the session key to the file key, for backward compatibility. 00054 if ( !$this->mParams['filekey'] && $this->mParams['sessionkey'] ) { 00055 $this->logFeatureUsage( 'action=upload&sessionkey' ); 00056 $this->mParams['filekey'] = $this->mParams['sessionkey']; 00057 } 00058 00059 // Select an upload module 00060 try { 00061 if ( !$this->selectUploadModule() ) { 00062 return; // not a true upload, but a status request or similar 00063 } elseif ( !isset( $this->mUpload ) ) { 00064 $this->dieUsage( 'No upload module set', 'nomodule' ); 00065 } 00066 } catch ( UploadStashException $e ) { // XXX: don't spam exception log 00067 $this->dieUsage( get_class( $e ) . ": " . $e->getMessage(), 'stasherror' ); 00068 } 00069 00070 // First check permission to upload 00071 $this->checkPermissions( $user ); 00072 00073 // Fetch the file (usually a no-op) 00075 $status = $this->mUpload->fetchFile(); 00076 if ( !$status->isGood() ) { 00077 $errors = $status->getErrorsArray(); 00078 $error = array_shift( $errors[0] ); 00079 $this->dieUsage( 'Error fetching file from remote source', $error, 0, $errors[0] ); 00080 } 00081 00082 // Check if the uploaded file is sane 00083 if ( $this->mParams['chunk'] ) { 00084 $maxSize = $this->mUpload->getMaxUploadSize(); 00085 if ( $this->mParams['filesize'] > $maxSize ) { 00086 $this->dieUsage( 'The file you submitted was too large', 'file-too-large' ); 00087 } 00088 if ( !$this->mUpload->getTitle() ) { 00089 $this->dieUsage( 'Invalid file title supplied', 'internal-error' ); 00090 } 00091 } elseif ( $this->mParams['async'] && $this->mParams['filekey'] ) { 00092 // defer verification to background process 00093 } else { 00094 wfDebug( __METHOD__ . " about to verify\n" ); 00095 $this->verifyUpload(); 00096 } 00097 00098 // Check if the user has the rights to modify or overwrite the requested title 00099 // (This check is irrelevant if stashing is already requested, since the errors 00100 // can always be fixed by changing the title) 00101 if ( !$this->mParams['stash'] ) { 00102 $permErrors = $this->mUpload->verifyTitlePermissions( $user ); 00103 if ( $permErrors !== true ) { 00104 $this->dieRecoverableError( $permErrors[0], 'filename' ); 00105 } 00106 } 00107 00108 // Get the result based on the current upload context: 00109 try { 00110 $result = $this->getContextResult(); 00111 if ( $result['result'] === 'Success' ) { 00112 $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); 00113 } 00114 } catch ( UploadStashException $e ) { // XXX: don't spam exception log 00115 $this->dieUsage( get_class( $e ) . ": " . $e->getMessage(), 'stasherror' ); 00116 } 00117 00118 $this->getResult()->addValue( null, $this->getModuleName(), $result ); 00119 00120 // Cleanup any temporary mess 00121 $this->mUpload->cleanupTempFile(); 00122 } 00123 00128 private function getContextResult() { 00129 $warnings = $this->getApiWarnings(); 00130 if ( $warnings && !$this->mParams['ignorewarnings'] ) { 00131 // Get warnings formatted in result array format 00132 return $this->getWarningsResult( $warnings ); 00133 } elseif ( $this->mParams['chunk'] ) { 00134 // Add chunk, and get result 00135 return $this->getChunkResult( $warnings ); 00136 } elseif ( $this->mParams['stash'] ) { 00137 // Stash the file and get stash result 00138 return $this->getStashResult( $warnings ); 00139 } 00140 00141 // This is the most common case -- a normal upload with no warnings 00142 // performUpload will return a formatted properly for the API with status 00143 return $this->performUpload( $warnings ); 00144 } 00145 00151 private function getStashResult( $warnings ) { 00152 $result = array(); 00153 // Some uploads can request they be stashed, so as not to publish them immediately. 00154 // In this case, a failure to stash ought to be fatal 00155 try { 00156 $result['result'] = 'Success'; 00157 $result['filekey'] = $this->performStash(); 00158 $result['sessionkey'] = $result['filekey']; // backwards compatibility 00159 if ( $warnings && count( $warnings ) > 0 ) { 00160 $result['warnings'] = $warnings; 00161 } 00162 } catch ( MWException $e ) { 00163 $this->dieUsage( $e->getMessage(), 'stashfailed' ); 00164 } 00165 00166 return $result; 00167 } 00168 00174 private function getWarningsResult( $warnings ) { 00175 $result = array(); 00176 $result['result'] = 'Warning'; 00177 $result['warnings'] = $warnings; 00178 // in case the warnings can be fixed with some further user action, let's stash this upload 00179 // and return a key they can use to restart it 00180 try { 00181 $result['filekey'] = $this->performStash(); 00182 $result['sessionkey'] = $result['filekey']; // backwards compatibility 00183 } catch ( MWException $e ) { 00184 $result['warnings']['stashfailed'] = $e->getMessage(); 00185 } 00186 00187 return $result; 00188 } 00189 00195 private function getChunkResult( $warnings ) { 00196 $result = array(); 00197 00198 $result['result'] = 'Continue'; 00199 if ( $warnings && count( $warnings ) > 0 ) { 00200 $result['warnings'] = $warnings; 00201 } 00202 $request = $this->getMain()->getRequest(); 00203 $chunkPath = $request->getFileTempname( 'chunk' ); 00204 $chunkSize = $request->getUpload( 'chunk' )->getSize(); 00205 if ( $this->mParams['offset'] == 0 ) { 00206 try { 00207 $filekey = $this->performStash(); 00208 } catch ( MWException $e ) { 00209 // FIXME: Error handling here is wrong/different from rest of this 00210 $this->dieUsage( $e->getMessage(), 'stashfailed' ); 00211 } 00212 } else { 00213 $filekey = $this->mParams['filekey']; 00214 $status = $this->mUpload->addChunk( 00215 $chunkPath, $chunkSize, $this->mParams['offset'] ); 00216 if ( !$status->isGood() ) { 00217 $this->dieUsage( $status->getWikiText(), 'stashfailed' ); 00218 00219 return array(); 00220 } 00221 } 00222 00223 // Check we added the last chunk: 00224 if ( $this->mParams['offset'] + $chunkSize == $this->mParams['filesize'] ) { 00225 if ( $this->mParams['async'] ) { 00226 $progress = UploadBase::getSessionStatus( $filekey ); 00227 if ( $progress && $progress['result'] === 'Poll' ) { 00228 $this->dieUsage( "Chunk assembly already in progress.", 'stashfailed' ); 00229 } 00230 UploadBase::setSessionStatus( 00231 $filekey, 00232 array( 'result' => 'Poll', 00233 'stage' => 'queued', 'status' => Status::newGood() ) 00234 ); 00235 JobQueueGroup::singleton()->push( new AssembleUploadChunksJob( 00236 Title::makeTitle( NS_FILE, $filekey ), 00237 array( 00238 'filename' => $this->mParams['filename'], 00239 'filekey' => $filekey, 00240 'session' => $this->getContext()->exportSession() 00241 ) 00242 ) ); 00243 $result['result'] = 'Poll'; 00244 $result['stage'] = 'queued'; 00245 } else { 00246 $status = $this->mUpload->concatenateChunks(); 00247 if ( !$status->isGood() ) { 00248 $this->dieUsage( $status->getWikiText(), 'stashfailed' ); 00249 00250 return array(); 00251 } 00252 00253 // The fully concatenated file has a new filekey. So remove 00254 // the old filekey and fetch the new one. 00255 $this->mUpload->stash->removeFile( $filekey ); 00256 $filekey = $this->mUpload->getLocalFile()->getFileKey(); 00257 00258 $result['result'] = 'Success'; 00259 } 00260 } 00261 $result['filekey'] = $filekey; 00262 $result['offset'] = $this->mParams['offset'] + $chunkSize; 00263 00264 return $result; 00265 } 00266 00273 private function performStash() { 00274 try { 00275 $stashFile = $this->mUpload->stashFile(); 00276 00277 if ( !$stashFile ) { 00278 throw new MWException( 'Invalid stashed file' ); 00279 } 00280 $fileKey = $stashFile->getFileKey(); 00281 } catch ( MWException $e ) { 00282 $message = 'Stashing temporary file failed: ' . get_class( $e ) . ' ' . $e->getMessage(); 00283 wfDebug( __METHOD__ . ' ' . $message . "\n" ); 00284 throw new MWException( $message ); 00285 } 00286 00287 return $fileKey; 00288 } 00289 00299 private function dieRecoverableError( $error, $parameter, $data = array() ) { 00300 try { 00301 $data['filekey'] = $this->performStash(); 00302 $data['sessionkey'] = $data['filekey']; 00303 } catch ( MWException $e ) { 00304 $data['stashfailed'] = $e->getMessage(); 00305 } 00306 $data['invalidparameter'] = $parameter; 00307 00308 $parsed = $this->parseMsg( $error ); 00309 $this->dieUsage( $parsed['info'], $parsed['code'], 0, $data ); 00310 } 00311 00319 protected function selectUploadModule() { 00320 $request = $this->getMain()->getRequest(); 00321 00322 // chunk or one and only one of the following parameters is needed 00323 if ( !$this->mParams['chunk'] ) { 00324 $this->requireOnlyOneParameter( $this->mParams, 00325 'filekey', 'file', 'url', 'statuskey' ); 00326 } 00327 00328 // Status report for "upload to stash"/"upload from stash" 00329 if ( $this->mParams['filekey'] && $this->mParams['checkstatus'] ) { 00330 $progress = UploadBase::getSessionStatus( $this->mParams['filekey'] ); 00331 if ( !$progress ) { 00332 $this->dieUsage( 'No result in status data', 'missingresult' ); 00333 } elseif ( !$progress['status']->isGood() ) { 00334 $this->dieUsage( $progress['status']->getWikiText(), 'stashfailed' ); 00335 } 00336 if ( isset( $progress['status']->value['verification'] ) ) { 00337 $this->checkVerification( $progress['status']->value['verification'] ); 00338 } 00339 unset( $progress['status'] ); // remove Status object 00340 $this->getResult()->addValue( null, $this->getModuleName(), $progress ); 00341 00342 return false; 00343 } 00344 00345 if ( $this->mParams['statuskey'] ) { 00346 $this->checkAsyncDownloadEnabled(); 00347 00348 // Status request for an async upload 00349 $sessionData = UploadFromUrlJob::getSessionData( $this->mParams['statuskey'] ); 00350 if ( !isset( $sessionData['result'] ) ) { 00351 $this->dieUsage( 'No result in session data', 'missingresult' ); 00352 } 00353 if ( $sessionData['result'] == 'Warning' ) { 00354 $sessionData['warnings'] = $this->transformWarnings( $sessionData['warnings'] ); 00355 $sessionData['sessionkey'] = $this->mParams['statuskey']; 00356 } 00357 $this->getResult()->addValue( null, $this->getModuleName(), $sessionData ); 00358 00359 return false; 00360 } 00361 00362 // The following modules all require the filename parameter to be set 00363 if ( is_null( $this->mParams['filename'] ) ) { 00364 $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); 00365 } 00366 00367 if ( $this->mParams['chunk'] ) { 00368 // Chunk upload 00369 $this->mUpload = new UploadFromChunks(); 00370 if ( isset( $this->mParams['filekey'] ) ) { 00371 // handle new chunk 00372 $this->mUpload->continueChunks( 00373 $this->mParams['filename'], 00374 $this->mParams['filekey'], 00375 $request->getUpload( 'chunk' ) 00376 ); 00377 } else { 00378 // handle first chunk 00379 $this->mUpload->initialize( 00380 $this->mParams['filename'], 00381 $request->getUpload( 'chunk' ) 00382 ); 00383 } 00384 } elseif ( isset( $this->mParams['filekey'] ) ) { 00385 // Upload stashed in a previous request 00386 if ( !UploadFromStash::isValidKey( $this->mParams['filekey'] ) ) { 00387 $this->dieUsageMsg( 'invalid-file-key' ); 00388 } 00389 00390 $this->mUpload = new UploadFromStash( $this->getUser() ); 00391 // This will not download the temp file in initialize() in async mode. 00392 // We still have enough information to call checkWarnings() and such. 00393 $this->mUpload->initialize( 00394 $this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async'] 00395 ); 00396 } elseif ( isset( $this->mParams['file'] ) ) { 00397 $this->mUpload = new UploadFromFile(); 00398 $this->mUpload->initialize( 00399 $this->mParams['filename'], 00400 $request->getUpload( 'file' ) 00401 ); 00402 } elseif ( isset( $this->mParams['url'] ) ) { 00403 // Make sure upload by URL is enabled: 00404 if ( !UploadFromUrl::isEnabled() ) { 00405 $this->dieUsageMsg( 'copyuploaddisabled' ); 00406 } 00407 00408 if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) { 00409 $this->dieUsageMsg( 'copyuploadbaddomain' ); 00410 } 00411 00412 if ( !UploadFromUrl::isAllowedUrl( $this->mParams['url'] ) ) { 00413 $this->dieUsageMsg( 'copyuploadbadurl' ); 00414 } 00415 00416 $async = false; 00417 if ( $this->mParams['asyncdownload'] ) { 00418 $this->checkAsyncDownloadEnabled(); 00419 00420 if ( $this->mParams['leavemessage'] && !$this->mParams['ignorewarnings'] ) { 00421 $this->dieUsage( 'Using leavemessage without ignorewarnings is not supported', 00422 'missing-ignorewarnings' ); 00423 } 00424 00425 if ( $this->mParams['leavemessage'] ) { 00426 $async = 'async-leavemessage'; 00427 } else { 00428 $async = 'async'; 00429 } 00430 } 00431 $this->mUpload = new UploadFromUrl; 00432 $this->mUpload->initialize( $this->mParams['filename'], 00433 $this->mParams['url'], $async ); 00434 } 00435 00436 return true; 00437 } 00438 00444 protected function checkPermissions( $user ) { 00445 // Check whether the user has the appropriate permissions to upload anyway 00446 $permission = $this->mUpload->isAllowed( $user ); 00447 00448 if ( $permission !== true ) { 00449 if ( !$user->isLoggedIn() ) { 00450 $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) ); 00451 } 00452 00453 $this->dieUsageMsg( 'badaccess-groups' ); 00454 } 00455 } 00456 00460 protected function verifyUpload() { 00461 $verification = $this->mUpload->verifyUpload(); 00462 if ( $verification['status'] === UploadBase::OK ) { 00463 return; 00464 } 00465 00466 $this->checkVerification( $verification ); 00467 } 00468 00473 protected function checkVerification( array $verification ) { 00474 // @todo Move them to ApiBase's message map 00475 switch ( $verification['status'] ) { 00476 // Recoverable errors 00477 case UploadBase::MIN_LENGTH_PARTNAME: 00478 $this->dieRecoverableError( 'filename-tooshort', 'filename' ); 00479 break; 00480 case UploadBase::ILLEGAL_FILENAME: 00481 $this->dieRecoverableError( 'illegal-filename', 'filename', 00482 array( 'filename' => $verification['filtered'] ) ); 00483 break; 00484 case UploadBase::FILENAME_TOO_LONG: 00485 $this->dieRecoverableError( 'filename-toolong', 'filename' ); 00486 break; 00487 case UploadBase::FILETYPE_MISSING: 00488 $this->dieRecoverableError( 'filetype-missing', 'filename' ); 00489 break; 00490 case UploadBase::WINDOWS_NONASCII_FILENAME: 00491 $this->dieRecoverableError( 'windows-nonascii-filename', 'filename' ); 00492 break; 00493 00494 // Unrecoverable errors 00495 case UploadBase::EMPTY_FILE: 00496 $this->dieUsage( 'The file you submitted was empty', 'empty-file' ); 00497 break; 00498 case UploadBase::FILE_TOO_LARGE: 00499 $this->dieUsage( 'The file you submitted was too large', 'file-too-large' ); 00500 break; 00501 00502 case UploadBase::FILETYPE_BADTYPE: 00503 $extradata = array( 00504 'filetype' => $verification['finalExt'], 00505 'allowed' => array_values( array_unique( $this->getConfig()->get( 'FileExtensions' ) ) ) 00506 ); 00507 $this->getResult()->setIndexedTagName( $extradata['allowed'], 'ext' ); 00508 00509 $msg = "Filetype not permitted: "; 00510 if ( isset( $verification['blacklistedExt'] ) ) { 00511 $msg .= join( ', ', $verification['blacklistedExt'] ); 00512 $extradata['blacklisted'] = array_values( $verification['blacklistedExt'] ); 00513 $this->getResult()->setIndexedTagName( $extradata['blacklisted'], 'ext' ); 00514 } else { 00515 $msg .= $verification['finalExt']; 00516 } 00517 $this->dieUsage( $msg, 'filetype-banned', 0, $extradata ); 00518 break; 00519 case UploadBase::VERIFICATION_ERROR: 00520 $this->getResult()->setIndexedTagName( $verification['details'], 'detail' ); 00521 $this->dieUsage( 'This file did not pass file verification', 'verification-error', 00522 0, array( 'details' => $verification['details'] ) ); 00523 break; 00524 case UploadBase::HOOK_ABORTED: 00525 $this->dieUsage( "The modification you tried to make was aborted by an extension hook", 00526 'hookaborted', 0, array( 'error' => $verification['error'] ) ); 00527 break; 00528 default: 00529 $this->dieUsage( 'An unknown error occurred', 'unknown-error', 00530 0, array( 'code' => $verification['status'] ) ); 00531 break; 00532 } 00533 } 00534 00542 protected function getApiWarnings() { 00543 $warnings = $this->mUpload->checkWarnings(); 00544 00545 return $this->transformWarnings( $warnings ); 00546 } 00547 00548 protected function transformWarnings( $warnings ) { 00549 if ( $warnings ) { 00550 // Add indices 00551 $result = $this->getResult(); 00552 $result->setIndexedTagName( $warnings, 'warning' ); 00553 00554 if ( isset( $warnings['duplicate'] ) ) { 00555 $dupes = array(); 00557 foreach ( $warnings['duplicate'] as $dupe ) { 00558 $dupes[] = $dupe->getName(); 00559 } 00560 $result->setIndexedTagName( $dupes, 'duplicate' ); 00561 $warnings['duplicate'] = $dupes; 00562 } 00563 00564 if ( isset( $warnings['exists'] ) ) { 00565 $warning = $warnings['exists']; 00566 unset( $warnings['exists'] ); 00568 $localFile = isset( $warning['normalizedFile'] ) 00569 ? $warning['normalizedFile'] 00570 : $warning['file']; 00571 $warnings[$warning['warning']] = $localFile->getName(); 00572 } 00573 } 00574 00575 return $warnings; 00576 } 00577 00585 protected function performUpload( $warnings ) { 00586 // Use comment as initial page text by default 00587 if ( is_null( $this->mParams['text'] ) ) { 00588 $this->mParams['text'] = $this->mParams['comment']; 00589 } 00590 00592 $file = $this->mUpload->getLocalFile(); 00593 00594 // For preferences mode, we want to watch if 'watchdefault' is set or 00595 // if the *file* doesn't exist and 'watchcreations' is set. But 00596 // getWatchlistValue()'s automatic handling checks if the *title* 00597 // exists or not, so we need to check both prefs manually. 00598 $watch = $this->getWatchlistValue( 00599 $this->mParams['watchlist'], $file->getTitle(), 'watchdefault' 00600 ); 00601 if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) { 00602 $watch = $this->getWatchlistValue( 00603 $this->mParams['watchlist'], $file->getTitle(), 'watchcreations' 00604 ); 00605 } 00606 00607 // Deprecated parameters 00608 if ( $this->mParams['watch'] ) { 00609 $this->logFeatureUsage( 'action=upload&watch' ); 00610 $watch = true; 00611 } 00612 00613 // No errors, no warnings: do the upload 00614 if ( $this->mParams['async'] ) { 00615 $progress = UploadBase::getSessionStatus( $this->mParams['filekey'] ); 00616 if ( $progress && $progress['result'] === 'Poll' ) { 00617 $this->dieUsage( "Upload from stash already in progress.", 'publishfailed' ); 00618 } 00619 UploadBase::setSessionStatus( 00620 $this->mParams['filekey'], 00621 array( 'result' => 'Poll', 'stage' => 'queued', 'status' => Status::newGood() ) 00622 ); 00623 JobQueueGroup::singleton()->push( new PublishStashedFileJob( 00624 Title::makeTitle( NS_FILE, $this->mParams['filename'] ), 00625 array( 00626 'filename' => $this->mParams['filename'], 00627 'filekey' => $this->mParams['filekey'], 00628 'comment' => $this->mParams['comment'], 00629 'text' => $this->mParams['text'], 00630 'watch' => $watch, 00631 'session' => $this->getContext()->exportSession() 00632 ) 00633 ) ); 00634 $result['result'] = 'Poll'; 00635 $result['stage'] = 'queued'; 00636 } else { 00638 $status = $this->mUpload->performUpload( $this->mParams['comment'], 00639 $this->mParams['text'], $watch, $this->getUser() ); 00640 00641 if ( !$status->isGood() ) { 00642 $error = $status->getErrorsArray(); 00643 00644 if ( count( $error ) == 1 && $error[0][0] == 'async' ) { 00645 // The upload can not be performed right now, because the user 00646 // requested so 00647 return array( 00648 'result' => 'Queued', 00649 'statuskey' => $error[0][1], 00650 ); 00651 } 00652 00653 $this->getResult()->setIndexedTagName( $error, 'error' ); 00654 $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error ); 00655 } 00656 $result['result'] = 'Success'; 00657 } 00658 00659 $result['filename'] = $file->getName(); 00660 if ( $warnings && count( $warnings ) > 0 ) { 00661 $result['warnings'] = $warnings; 00662 } 00663 00664 return $result; 00665 } 00666 00670 protected function checkAsyncDownloadEnabled() { 00671 if ( !$this->getConfig()->get( 'AllowAsyncCopyUploads' ) ) { 00672 $this->dieUsage( 'Asynchronous copy uploads disabled', 'asynccopyuploaddisabled' ); 00673 } 00674 } 00675 00676 public function mustBePosted() { 00677 return true; 00678 } 00679 00680 public function isWriteMode() { 00681 return true; 00682 } 00683 00684 public function getAllowedParams() { 00685 $params = array( 00686 'filename' => array( 00687 ApiBase::PARAM_TYPE => 'string', 00688 ), 00689 'comment' => array( 00690 ApiBase::PARAM_DFLT => '' 00691 ), 00692 'text' => null, 00693 'watch' => array( 00694 ApiBase::PARAM_DFLT => false, 00695 ApiBase::PARAM_DEPRECATED => true, 00696 ), 00697 'watchlist' => array( 00698 ApiBase::PARAM_DFLT => 'preferences', 00699 ApiBase::PARAM_TYPE => array( 00700 'watch', 00701 'preferences', 00702 'nochange' 00703 ), 00704 ), 00705 'ignorewarnings' => false, 00706 'file' => array( 00707 ApiBase::PARAM_TYPE => 'upload', 00708 ), 00709 'url' => null, 00710 'filekey' => null, 00711 'sessionkey' => array( 00712 ApiBase::PARAM_DFLT => null, 00713 ApiBase::PARAM_DEPRECATED => true, 00714 ), 00715 'stash' => false, 00716 00717 'filesize' => null, 00718 'offset' => null, 00719 'chunk' => array( 00720 ApiBase::PARAM_TYPE => 'upload', 00721 ), 00722 00723 'async' => false, 00724 'asyncdownload' => false, 00725 'leavemessage' => false, 00726 'statuskey' => null, 00727 'checkstatus' => false, 00728 ); 00729 00730 return $params; 00731 } 00732 00733 public function getParamDescription() { 00734 $params = array( 00735 'filename' => 'Target filename', 00736 'comment' => 'Upload comment. Also used as the initial page text for new ' . 00737 'files if "text" is not specified', 00738 'text' => 'Initial page text for new files', 00739 'watch' => 'Watch the page', 00740 'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' . 00741 'use preferences or do not change watch', 00742 'ignorewarnings' => 'Ignore any warnings', 00743 'file' => 'File contents', 00744 'url' => 'URL to fetch the file from', 00745 'filekey' => 'Key that identifies a previous upload that was stashed temporarily.', 00746 'sessionkey' => 'Same as filekey, maintained for backward compatibility.', 00747 'stash' => 'If set, the server will not add the file to the repository ' . 00748 'and stash it temporarily.', 00749 00750 'chunk' => 'Chunk contents', 00751 'offset' => 'Offset of chunk in bytes', 00752 'filesize' => 'Filesize of entire upload', 00753 00754 'async' => 'Make potentially large file operations asynchronous when possible', 00755 'asyncdownload' => 'Make fetching a URL asynchronous', 00756 'leavemessage' => 'If asyncdownload is used, leave a message on the user talk page if finished', 00757 'statuskey' => 'Fetch the upload status for this file key (upload by URL)', 00758 'checkstatus' => 'Only fetch the upload status for the given file key', 00759 ); 00760 00761 return $params; 00762 } 00763 00764 public function getDescription() { 00765 return array( 00766 'Upload a file, or get the status of pending uploads. Several methods are available:', 00767 ' * Upload file contents directly, using the "file" parameter', 00768 ' * Have the MediaWiki server fetch a file from a URL, using the "url" parameter', 00769 ' * Complete an earlier upload that failed due to warnings, using the "filekey" parameter', 00770 'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when', 00771 'sending the "file".', 00772 ); 00773 } 00774 00775 public function needsToken() { 00776 return 'csrf'; 00777 } 00778 00779 public function getExamples() { 00780 return array( 00781 'api.php?action=upload&filename=Wiki.png' . 00782 '&url=http%3A//upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png&token=123ABC' 00783 => 'Upload from a URL', 00784 'api.php?action=upload&filename=Wiki.png&filekey=filekey&ignorewarnings=1&token=123ABC' 00785 => 'Complete an upload that failed due to warnings', 00786 ); 00787 } 00788 00789 public function getHelpUrls() { 00790 return 'https://www.mediawiki.org/wiki/API:Upload'; 00791 } 00792 }