public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $context = RequestContext::getMain();
     try {
         $user = $context->getUser();
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         if (count($_SESSION) === 0) {
             // Empty session probably indicates that we didn't associate
             // with the session correctly. Note that being able to load
             // the user does not necessarily mean the session was loaded.
             // Most likely cause by suhosin.session.encrypt = On.
             $this->setLastError("Error associating with user session. " . "Try setting suhosin.session.encrypt = Off");
             return false;
         }
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood()));
         $upload = new UploadFromChunks($user);
         $upload->continueChunks($this->params['filename'], $this->params['filekey'], $context->getRequest());
         // Combine all of the chunks into a local file and upload that to a new stash file
         $status = $upload->concatenateChunks();
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => $status));
             $this->setLastError($status->getWikiText());
             return false;
         }
         // We have a new filekey for the fully concatenated file
         $newFileKey = $upload->getLocalFile()->getFileKey();
         // Remove the old stash file row and first chunk file
         $upload->stash->removeFileNoAuth($this->params['filekey']);
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Success', 'stage' => 'assembling', 'filekey' => $newFileKey, 'imageinfo' => $imageInfo, 'status' => Status::newGood()));
     } catch (MWException $e) {
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => Status::newFatal('api-error-stashfailed')));
         $this->setLastError(get_class($e) . ": " . $e->getText());
         // To be extra robust.
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         return false;
     }
     return true;
 }
 public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $this->addTeardownCallback(function () use(&$scope) {
         ScopedCallback::consume($scope);
         // T126450
     });
     $context = RequestContext::getMain();
     $user = $context->getUser();
     try {
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood()]);
         $upload = new UploadFromChunks($user);
         $upload->continueChunks($this->params['filename'], $this->params['filekey'], new WebRequestUpload($context->getRequest(), 'null'));
         // Combine all of the chunks into a local file and upload that to a new stash file
         $status = $upload->concatenateChunks();
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Failure', 'stage' => 'assembling', 'status' => $status]);
             $this->setLastError($status->getWikiText(false, false, 'en'));
             return false;
         }
         // We can only get warnings like 'duplicate' after concatenating the chunks
         $status = Status::newGood();
         $status->value = ['warnings' => $upload->checkWarnings()];
         // We have a new filekey for the fully concatenated file
         $newFileKey = $upload->getStashFile()->getFileKey();
         // Remove the old stash file row and first chunk file
         $upload->stash->removeFileNoAuth($this->params['filekey']);
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Success', 'stage' => 'assembling', 'filekey' => $newFileKey, 'imageinfo' => $imageInfo, 'status' => $status]);
     } catch (Exception $e) {
         UploadBase::setSessionStatus($user, $this->params['filekey'], ['result' => 'Failure', 'stage' => 'assembling', 'status' => Status::newFatal('api-error-stashfailed')]);
         $this->setLastError(get_class($e) . ": " . $e->getMessage());
         // To be extra robust.
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         return false;
     }
     return true;
 }
 public function run()
 {
     $scope = RequestContext::importScopedSession($this->params['session']);
     $context = RequestContext::getMain();
     try {
         $user = $context->getUser();
         if (!$user->isLoggedIn()) {
             $this->setLastError("Could not load the author user from session.");
             return false;
         }
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Poll', 'stage' => 'assembling', 'status' => Status::newGood()));
         $upload = new UploadFromChunks($user);
         $upload->continueChunks($this->params['filename'], $this->params['filekey'], $context->getRequest());
         // Combine all of the chunks into a local file and upload that to a new stash file
         $status = $upload->concatenateChunks();
         if (!$status->isGood()) {
             UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => $status));
             $this->setLastError($status->getWikiText());
             return false;
         }
         // We have a new filekey for the fully concatenated file
         $newFileKey = $upload->getLocalFile()->getFileKey();
         // Remove the old stash file row and first chunk file
         $upload->stash->removeFileNoAuth($this->params['filekey']);
         // Build the image info array while we have the local reference handy
         $apiMain = new ApiMain();
         // dummy object (XXX)
         $imageInfo = $upload->getImageInfo($apiMain->getResult());
         // Cleanup any temporary local file
         $upload->cleanupTempFile();
         // Cache the info so the user doesn't have to wait forever to get the final info
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Success', 'stage' => 'assembling', 'filekey' => $newFileKey, 'imageinfo' => $imageInfo, 'status' => Status::newGood()));
     } catch (MWException $e) {
         UploadBase::setSessionStatus($this->params['filekey'], array('result' => 'Failure', 'stage' => 'assembling', 'status' => Status::newFatal('api-error-stashfailed')));
         $this->setLastError(get_class($e) . ": " . $e->getText());
         return false;
     }
     return true;
 }
Beispiel #4
0
 public function execute()
 {
     // Check whether upload is enabled
     if (!UploadBase::isEnabled()) {
         $this->dieUsageMsg('uploaddisabled');
     }
     $user = $this->getUser();
     // Parameter handling
     $this->mParams = $this->extractRequestParams();
     $request = $this->getMain()->getRequest();
     // Check if async mode is actually supported (jobs done in cli mode)
     $this->mParams['async'] = $this->mParams['async'] && $this->getConfig()->get('EnableAsyncUploads');
     // Add the uploaded file to the params array
     $this->mParams['file'] = $request->getFileName('file');
     $this->mParams['chunk'] = $request->getFileName('chunk');
     // Copy the session key to the file key, for backward compatibility.
     if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
         $this->mParams['filekey'] = $this->mParams['sessionkey'];
     }
     // Select an upload module
     try {
         if (!$this->selectUploadModule()) {
             return;
             // not a true upload, but a status request or similar
         } elseif (!isset($this->mUpload)) {
             $this->dieUsage('No upload module set', 'nomodule');
         }
     } catch (UploadStashException $e) {
         // XXX: don't spam exception log
         $this->handleStashException($e);
     }
     // First check permission to upload
     $this->checkPermissions($user);
     // Fetch the file (usually a no-op)
     /** @var $status Status */
     $status = $this->mUpload->fetchFile();
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray();
         $error = array_shift($errors[0]);
         $this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
     }
     // Check if the uploaded file is sane
     if ($this->mParams['chunk']) {
         $maxSize = UploadBase::getMaxUploadSize();
         if ($this->mParams['filesize'] > $maxSize) {
             $this->dieUsage('The file you submitted was too large', 'file-too-large');
         }
         if (!$this->mUpload->getTitle()) {
             $this->dieUsage('Invalid file title supplied', 'internal-error');
         }
     } elseif ($this->mParams['async'] && $this->mParams['filekey']) {
         // defer verification to background process
     } else {
         wfDebug(__METHOD__ . " about to verify\n");
         $this->verifyUpload();
     }
     // Check if the user has the rights to modify or overwrite the requested title
     // (This check is irrelevant if stashing is already requested, since the errors
     //  can always be fixed by changing the title)
     if (!$this->mParams['stash']) {
         $permErrors = $this->mUpload->verifyTitlePermissions($user);
         if ($permErrors !== true) {
             $this->dieRecoverableError($permErrors[0], 'filename');
         }
     }
     // Get the result based on the current upload context:
     try {
         $result = $this->getContextResult();
         if ($result['result'] === 'Success') {
             $result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
         }
     } catch (UploadStashException $e) {
         // XXX: don't spam exception log
         $this->handleStashException($e);
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
     // Cleanup any temporary mess
     $this->mUpload->cleanupTempFile();
 }