Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * @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);
     }
 }
Пример #4
0
 /**
  * This function loads the image details page
  *
  * @return string
  */
 function chooseImage()
 {
     global $wgRequest, $wgUser;
     $itemId = $wgRequest->getVal('itemId');
     $sourceId = $wgRequest->getInt('sourceId');
     if ($sourceId == 0) {
         $file = wfFindFile(Title::newFromText($itemId, 6));
         $props = array();
         $props['file'] = $file;
         $props['mwname'] = $itemId;
         $props['default_caption'] = !empty($file) ? Wikia::getProps($file->getTitle()->getArticleID(), 'default_caption') : '';
     } else {
         if ($sourceId == 1) {
             $flickrResult = $this->getFlickrPhotoInfo($itemId);
             $url = "http://farm{$flickrResult['farm']}.static.flickr.com/{$flickrResult['server']}/{$flickrResult['id']}_{$flickrResult['secret']}.jpg";
             $data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $url);
             $upload = new UploadFromUrl();
             $upload->initializeFromRequest(new FauxRequest($data, true));
             $upload->fetchFile();
             $tempname = $this->tempFileName($wgUser);
             $file = new FakeLocalFile(Title::newFromText($tempname, 6), RepoGroup::singleton()->getLocalRepo());
             $file->upload($upload->getTempPath(), '', '');
             $tempid = $this->tempFileStoreInfo($tempname);
             $props = array();
             $props['file'] = $file;
             $props['name'] = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', trim($flickrResult['title']) . '.jpg');
             $props['mwname'] = $tempname;
             $props['extraId'] = $itemId;
             $props['tempid'] = $tempid;
         }
     }
     return $this->detailsPage($props);
 }
Пример #5
0
 /**
  * @param $url
  * @return array
  */
 public function uploadFromUrl($url)
 {
     $uploader = new UploadFromUrl();
     $uploader->initializeFromRequest(new FauxRequest(['wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $url], true));
     $status = $uploader->fetchFile();
     if ($status->isGood()) {
         return [$uploader->getTempPath(), true];
     } else {
         return [$uploader->getTempPath(), false, $this->getUploadUrlErrorMessage($status)];
     }
 }