public function run() { global $wgCopyUploadAsyncTimeout; # Initialize this object and the upload object $this->upload = new UploadFromUrl(); $this->upload->initialize($this->title->getText(), $this->params['url'], false); $this->user = User::newFromName($this->params['userName']); # Fetch the file $opts = array(); if ($wgCopyUploadAsyncTimeout) { $opts['timeout'] = $wgCopyUploadAsyncTimeout; } $status = $this->upload->fetchFile($opts); if (!$status->isOk()) { $this->leaveMessage($status); return true; } # Verify upload $result = $this->upload->verifyUpload(); if ($result['status'] != UploadBase::OK) { $status = $this->upload->convertVerifyErrorToStatus($result); $this->leaveMessage($status); return true; } # Check warnings if (!$this->params['ignoreWarnings']) { $warnings = $this->upload->checkWarnings(); if ($warnings) { # Stash the upload $key = $this->upload->stashFile(); // @todo FIXME: This has been broken for a while. // User::leaveUserMessage() does not exist. if ($this->params['leaveMessage']) { $this->user->leaveUserMessage(wfMessage('upload-warning-subj')->text(), wfMessage('upload-warning-msg', $key, $this->params['url'])->text()); } else { wfSetupSession($this->params['sessionId']); $this->storeResultInSession('Warning', 'warnings', $warnings); session_write_close(); } return true; } } # Perform the upload $status = $this->upload->performUpload($this->params['comment'], $this->params['pageText'], $this->params['watch'], $this->user); $this->leaveMessage($status); return true; }
public function run() { # Initialize this object and the upload object $this->upload = new UploadFromUrl(); $this->upload->initialize($this->title->getText(), $this->params['url'], false); $this->user = User::newFromName($this->params['userName']); # Fetch the file $status = $this->upload->fetchFile(); if (!$status->isOk()) { $this->leaveMessage($status); return true; } # Verify upload $result = $this->upload->verifyUpload(); if ($result['status'] != UploadBase::OK) { $status = $this->upload->convertVerifyErrorToStatus($result); $this->leaveMessage($status); return true; } # Check warnings if (!$this->params['ignoreWarnings']) { $warnings = $this->upload->checkWarnings(); if ($warnings) { # Stash the upload $key = $this->upload->stashFile(); if ($this->params['leaveMessage']) { $this->user->leaveUserMessage(wfMsg('upload-warning-subj'), wfMsg('upload-warning-msg', $key, $this->params['url'])); } else { wfSetupSession($this->params['sessionId']); $this->storeResultInSession('Warning', 'warnings', $warnings); session_write_close(); } return true; } } # Perform the upload $status = $this->upload->performUpload($this->params['comment'], $this->params['pageText'], $this->params['watch'], $this->user); $this->leaveMessage($status); return true; }
/** * @desc Uploads an image on a wiki * * @static * @param string $imageUrl url address to original file * @param Object $oImageData an object with obligatory field "name" and optional fields: "comment", "description" * @param User | null $user optional User's class instance (the file will be "uploaded" by this user) * * @return array */ public static function uploadImageFromUrl($imageUrl, $oImageData, $user = null) { // disable recentchange hooks global $wgHooks; $wgHooks['RecentChange_save'] = array(); $wgHooks['RecentChange_beforeSave'] = array(); /* prepare temporary file */ $data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $imageUrl, 'wpDestFile' => $oImageData->name); //validate of optional image data foreach (array(self::FILE_DATA_COMMENT_OPION_NAME, self::FILE_DATA_DESC_OPION_NAME) as $option) { if (!isset($oImageData->{$option})) { $oImageData->{$option} = $oImageData->name; } } $upload = new UploadFromUrl(); $upload->initializeFromRequest(new FauxRequest($data, true)); $fetchStatus = $upload->fetchFile(); if ($fetchStatus->isGood()) { $status = $upload->verifyUpload(); if (isset($status['status']) && $status['status'] == UploadBase::SUCCESS) { $file = self::createImagePage($oImageData->name); /** @var $file WikiaLocalFile */ $result = self::updateImageInfoInDb($file, $upload->getTempPath(), $oImageData, $user); /** @var $result */ return self::buildStatus($result->ok, $file->getTitle()->getArticleID(), $result->errors); } else { $errorMsg = 'Upload verification faild '; $errorMsg .= isset($status['status']) ? print_r($status, true) : ''; return self::buildStatus(false, null, $errorMsg); } } else { return self::buildStatus($fetchStatus->ok, null, $fetchStatus->errors); } }