protected function tmpUpload($urlFrom)
 {
     wfProfileIn(__METHOD__);
     $data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $urlFrom);
     $upload = new UploadFromUrl();
     /* @var $upload UploadFromUrl */
     $upload->initializeFromRequest(new FauxRequest($data, true));
     wfProfileOut(__METHOD__);
     return $upload;
 }
 /**
  * @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);
     }
 }
 /**
  * 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);
 }
 /**
  * @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)];
     }
 }