/** * Do the upload. * Checks are made in SpecialUpload::execute() */ protected function processUpload() { // Fetch the file if required $status = $this->mUpload->fetchFile(); if (!$status->isOK()) { $this->showUploadError($this->getOutput()->parse($status->getWikiText())); return; } if (!Hooks::run('UploadForm:BeforeProcessing', array(&$this))) { wfDebug("Hook 'UploadForm:BeforeProcessing' broke processing the file.\n"); // This code path is deprecated. If you want to break upload processing // do so by hooking into the appropriate hooks in UploadBase::verifyUpload // and UploadBase::verifyFile. // If you use this hook to break uploading, the user will be returned // an empty form with no error message whatsoever. return; } // Upload verification $details = $this->mUpload->verifyUpload(); if ($details['status'] != UploadBase::OK) { $this->processVerificationError($details); return; } // Verify permissions for this title $permErrors = $this->mUpload->verifyTitlePermissions($this->getUser()); if ($permErrors !== true) { $code = array_shift($permErrors[0]); $this->showRecoverableUploadError($this->msg($code, $permErrors[0])->parse()); return; } $this->mLocalFile = $this->mUpload->getLocalFile(); // Check warnings if necessary if (!$this->mIgnoreWarning) { $warnings = $this->mUpload->checkWarnings(); if ($this->showUploadWarning($warnings)) { return; } } // This is as late as we can throttle, after expected issues have been handled if (UploadBase::isThrottled($this->getUser())) { $this->showRecoverableUploadError($this->msg('actionthrottledtext')->escaped()); return; } // Get the page text if this is not a reupload if (!$this->mForReUpload) { $pageText = self::getInitialPageText($this->mComment, $this->mLicense, $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig()); } else { $pageText = false; } $status = $this->mUpload->performUpload($this->mComment, $pageText, $this->mWatchthis, $this->getUser()); if (!$status->isGood()) { $this->showUploadError($this->getOutput()->parse($status->getWikiText())); return; } // Success, redirect to description page $this->mUploadSuccessful = true; Hooks::run('SpecialUploadComplete', array(&$this)); $this->getOutput()->redirect($this->mLocalFile->getTitle()->getFullURL()); }
/** * Performs file verification, dies on error. */ protected function verifyUpload() { $verification = $this->mUpload->verifyUpload(); if ($verification['status'] === UploadBase::OK) { return; } $this->checkVerification($verification); }
/** * Performs file verification, dies on error. */ protected function verifyUpload() { global $wgFileExtensions; $verification = $this->mUpload->verifyUpload(); if ($verification['status'] === UploadBase::OK) { return; } // TODO: Move them to ApiBase's message map switch ($verification['status']) { // Recoverable errors case UploadBase::MIN_LENGTH_PARTNAME: $this->dieRecoverableError('filename-tooshort', 'filename'); break; case UploadBase::ILLEGAL_FILENAME: $this->dieRecoverableError('illegal-filename', 'filename', array('filename' => $verification['filtered'])); break; case UploadBase::FILENAME_TOO_LONG: $this->dieRecoverableError('filename-toolong', 'filename'); break; case UploadBase::FILETYPE_MISSING: $this->dieRecoverableError('filetype-missing', 'filename'); break; case UploadBase::WINDOWS_NONASCII_FILENAME: $this->dieRecoverableError('windows-nonascii-filename', 'filename'); break; // Unrecoverable errors // Unrecoverable errors case UploadBase::EMPTY_FILE: $this->dieUsage('The file you submitted was empty', 'empty-file'); break; case UploadBase::FILE_TOO_LARGE: $this->dieUsage('The file you submitted was too large', 'file-too-large'); break; case UploadBase::FILETYPE_BADTYPE: $extradata = array('filetype' => $verification['finalExt'], 'allowed' => $wgFileExtensions); $this->getResult()->setIndexedTagName($extradata['allowed'], 'ext'); $msg = "Filetype not permitted: "; if (isset($verification['blacklistedExt'])) { $msg .= join(', ', $verification['blacklistedExt']); $extradata['blacklisted'] = array_values($verification['blacklistedExt']); $this->getResult()->setIndexedTagName($extradata['blacklisted'], 'ext'); } else { $msg .= $verification['finalExt']; } $this->dieUsage($msg, 'filetype-banned', 0, $extradata); break; case UploadBase::VERIFICATION_ERROR: $this->getResult()->setIndexedTagName($verification['details'], 'detail'); $this->dieUsage('This file did not pass file verification', 'verification-error', 0, array('details' => $verification['details'])); break; case UploadBase::HOOK_ABORTED: $this->dieUsage("The modification you tried to make was aborted by an extension hook", 'hookaborted', 0, array('error' => $verification['error'])); break; default: $this->dieUsage('An unknown error occurred', 'unknown-error', 0, array('code' => $verification['status'])); break; } }
/** * @return array */ public function verifyUpload() { # Check for a post_max_size or upload_max_size overflow, so that a # proper error can be shown to the user if (is_null($this->mTempPath) || $this->isEmptyFile()) { if ($this->mUpload->isIniSizeOverflow()) { return array('status' => UploadBase::FILE_TOO_LARGE, 'max' => min(self::getMaxUploadSize($this->getSourceType()), wfShorthandToInteger(ini_get('upload_max_filesize')), wfShorthandToInteger(ini_get('post_max_size')))); } } return parent::verifyUpload(); }
/** * Wrapper around the parent function in order to defer verifying the * upload until the file really has been fetched. */ public function verifyUpload() { if ($this->mAsync) { return array('status' => UploadBase::OK); } return parent::verifyUpload(); }
/** * @param UploadBase $upload * @return array */ private function uploadImage($upload) { global $wgRequest, $wgUser, $wgEnableUploads; $uploadStatus = array("status" => "error"); if (empty($wgEnableUploads)) { $uploadStatus["errors"] = [wfMessage('themedesigner-upload-disabled')->plain()]; } else { $upload->initializeFromRequest($wgRequest); $permErrors = $upload->verifyPermissions($wgUser); if ($permErrors !== true) { $uploadStatus["errors"] = array(wfMsg('badaccess')); } else { $details = $upload->verifyUpload(); if ($details['status'] != UploadBase::OK) { $uploadStatus["errors"] = array($this->getUploadErrorMessage($details)); } else { $warnings = $upload->checkWarnings(); if (!empty($warnings)) { $uploadStatus["errors"] = $this->getUploadWarningMessages($warnings); } else { //save temp file $status = $upload->performUpload(); $uploadStatus["status"] = "uploadattempted"; $uploadStatus["isGood"] = $status->isGood(); } } } } return $uploadStatus; }
/** * Wrapper around the parent function in order to defer verifying the * upload until the file really has been fetched. */ public function verifyUpload() { return parent::verifyUpload(); }