/** * Select an upload module and set it to mUpload. Dies on failure. If the * request was a status request and not a true upload, returns false; * otherwise true * * @return bool */ protected function selectUploadModule() { global $wgAllowAsyncCopyUploads; $request = $this->getMain()->getRequest(); // One and only one of the following parameters is needed $this->requireOnlyOneParameter($this->mParams, 'sessionkey', 'file', 'url', 'statuskey'); if ($wgAllowAsyncCopyUploads && $this->mParams['statuskey']) { // Status request for an async upload $sessionData = UploadFromUrlJob::getSessionData($this->mParams['statuskey']); if (!isset($sessionData['result'])) { $this->dieUsage('No result in session data', 'missingresult'); } if ($sessionData['result'] == 'Warning') { $sessionData['warnings'] = $this->transformWarnings($sessionData['warnings']); $sessionData['sessionkey'] = $this->mParams['statuskey']; } $this->getResult()->addValue(null, $this->getModuleName(), $sessionData); return false; } // The following modules all require the filename parameter to be set if (is_null($this->mParams['filename'])) { $this->dieUsageMsg(array('missingparam', 'filename')); } if ($this->mParams['sessionkey']) { // Upload stashed in a previous request $sessionData = $request->getSessionData(UploadBase::getSessionKeyName()); if (!UploadFromStash::isValidSessionKey($this->mParams['sessionkey'], $sessionData)) { $this->dieUsageMsg(array('invalid-session-key')); } $this->mUpload = new UploadFromStash(); $this->mUpload->initialize($this->mParams['filename'], $this->mParams['sessionkey'], $sessionData[$this->mParams['sessionkey']]); } elseif (isset($this->mParams['file'])) { $this->mUpload = new UploadFromFile(); $this->mUpload->initialize($this->mParams['filename'], $request->getUpload('file')); } elseif (isset($this->mParams['url'])) { // Make sure upload by URL is enabled: if (!UploadFromUrl::isEnabled()) { $this->dieUsageMsg(array('copyuploaddisabled')); } $async = false; if ($this->mParams['asyncdownload']) { if ($this->mParams['leavemessage'] && !$this->mParams['ignorewarnings']) { $this->dieUsage('Using leavemessage without ignorewarnings is not supported', 'missing-ignorewarnings'); } if ($this->mParams['leavemessage']) { $async = 'async-leavemessage'; } else { $async = 'async'; } } $this->mUpload = new UploadFromUrl(); $this->mUpload->initialize($this->mParams['filename'], $this->mParams['url'], $async); } return true; }