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;
 }
Example #2
0
	/**
	 * Leave a message on the user talk page or in the session according to
	 * $params['leaveMessage'].
	 *
	 * @param $status Status
	 */
	protected function leaveMessage( $status ) {
		if ( $this->params['leaveMessage'] ) {
			if ( $status->isGood() ) {
				$this->user->leaveUserMessage( wfMessage( 'upload-success-subj' )->text(),
					wfMessage( 'upload-success-msg',
						$this->upload->getTitle()->getText(),
						$this->params['url']
					)->text() );
			} else {
				$this->user->leaveUserMessage( wfMessage( 'upload-failure-subj' )->text(),
					wfMessage( 'upload-failure-msg',
						$status->getWikiText(),
						$this->params['url']
					)->text() );
			}
		} else {
			wfSetupSession( $this->params['sessionId'] );
			if ( $status->isOk() ) {
				$this->storeResultInSession( 'Success',
					'filename', $this->upload->getLocalFile()->getName() );
			} else {
				$this->storeResultInSession( 'Failure',
					'errors', $status->getErrorsArray() );
			}
			session_write_close();
		}
	}
Example #3
0
 /**
  * Leave a message on the user talk page or in the session according to
  * $params['leaveMessage'].
  *
  * @param Status $status
  */
 protected function leaveMessage($status)
 {
     if ($this->params['leaveMessage']) {
         if ($status->isGood()) {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-success-subj')->text(), wfMessage('upload-success-msg', $this->upload->getTitle()->getText(), $this->params['url'])->text());
         } else {
             // @todo FIXME: user->leaveUserMessage does not exist.
             $this->user->leaveUserMessage(wfMessage('upload-failure-subj')->text(), wfMessage('upload-failure-msg', $status->getWikiText(), $this->params['url'])->text());
         }
     } else {
         $session = MediaWiki\Session\SessionManager::singleton()->getSessionById($this->params['sessionId']);
         if ($status->isOk()) {
             $this->storeResultInSession($session, 'Success', 'filename', $this->upload->getLocalFile()->getName());
         } else {
             $this->storeResultInSession($session, 'Failure', 'errors', $status->getErrorsArray());
         }
     }
 }
Example #4
0
 /**
  * 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()
 {
     $request = $this->getMain()->getRequest();
     // chunk or one and only one of the following parameters is needed
     if (!$this->mParams['chunk']) {
         $this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url');
     }
     // Status report for "upload to stash"/"upload from stash"
     if ($this->mParams['filekey'] && $this->mParams['checkstatus']) {
         $progress = UploadBase::getSessionStatus($this->getUser(), $this->mParams['filekey']);
         if (!$progress) {
             $this->dieUsage('No result in status data', 'missingresult');
         } elseif (!$progress['status']->isGood()) {
             $this->dieUsage($progress['status']->getWikiText(false, false, 'en'), 'stashfailed');
         }
         if (isset($progress['status']->value['verification'])) {
             $this->checkVerification($progress['status']->value['verification']);
         }
         unset($progress['status']);
         // remove Status object
         $this->getResult()->addValue(null, $this->getModuleName(), $progress);
         return false;
     }
     // The following modules all require the filename parameter to be set
     if (is_null($this->mParams['filename'])) {
         $this->dieUsageMsg(['missingparam', 'filename']);
     }
     if ($this->mParams['chunk']) {
         // Chunk upload
         $this->mUpload = new UploadFromChunks();
         if (isset($this->mParams['filekey'])) {
             if ($this->mParams['offset'] === 0) {
                 $this->dieUsage('Cannot supply a filekey when offset is 0', 'badparams');
             }
             // handle new chunk
             $this->mUpload->continueChunks($this->mParams['filename'], $this->mParams['filekey'], $request->getUpload('chunk'));
         } else {
             if ($this->mParams['offset'] !== 0) {
                 $this->dieUsage('Must supply a filekey when offset is non-zero', 'badparams');
             }
             // handle first chunk
             $this->mUpload->initialize($this->mParams['filename'], $request->getUpload('chunk'));
         }
     } elseif (isset($this->mParams['filekey'])) {
         // Upload stashed in a previous request
         if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
             $this->dieUsageMsg('invalid-file-key');
         }
         $this->mUpload = new UploadFromStash($this->getUser());
         // This will not download the temp file in initialize() in async mode.
         // We still have enough information to call checkWarnings() and such.
         $this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']);
     } 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('copyuploaddisabled');
         }
         if (!UploadFromUrl::isAllowedHost($this->mParams['url'])) {
             $this->dieUsageMsg('copyuploadbaddomain');
         }
         if (!UploadFromUrl::isAllowedUrl($this->mParams['url'])) {
             $this->dieUsageMsg('copyuploadbadurl');
         }
         $this->mUpload = new UploadFromUrl();
         $this->mUpload->initialize($this->mParams['filename'], $this->mParams['url']);
     }
     return true;
 }
	/**
	 * Get the descriptor of the fieldset that contains the file source
	 * selection. The section is 'source'
	 *
	 * @return array Descriptor array
	 */
	protected function getSourceSection() {
		global $wgUser, $wgRequest;

		if ( $this->mSessionKey ) {
			return array(
				'wpSessionKey' => array(
					'type' => 'hidden',
					'default' => $this->mSessionKey,
				),
				'wpSourceType' => array(
					'type' => 'hidden',
					'default' => 'Stash',
				),
			);
		}

		$canUploadByUrl = UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' );
		$radio = $canUploadByUrl;
		$selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );

		$descriptor = array();
		$descriptor['UploadFile'] = array(
			'class' => 'UploadSourceField',
			'section' => 'source',
			'type' => 'file',
			'id' => 'wpUploadFile',
			'size' => 30, // added for PictureGame
			'label-message' => 'sourcefilename',
			'upload-type' => 'File',
			'radio' => &$radio,
			// help removed, we don't need any tl,dr on this mini-upload form
			'checked' => $selectedSourceType == 'file',
		);
		if ( $canUploadByUrl ) {
			$descriptor['UploadFileURL'] = array(
				'class' => 'UploadSourceField',
				'section' => 'source',
				'id' => 'wpUploadFileURL',
				'label-message' => 'sourceurl',
				'upload-type' => 'url',
				'radio' => &$radio,
				'checked' => $selectedSourceType == 'url',
			);
		}

		return $descriptor;
	}
Example #6
0
 /**
  * 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()
 {
     $request = $this->getMain()->getRequest();
     // chunk or one and only one of the following parameters is needed
     if (!$this->mParams['chunk']) {
         $this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url', 'statuskey');
     }
     if ($this->mParams['statuskey']) {
         $this->checkAsyncDownloadEnabled();
         // 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['chunk']) {
         // Chunk upload
         $this->mUpload = new UploadFromChunks();
         if (isset($this->mParams['filekey'])) {
             // handle new chunk
             $this->mUpload->continueChunks($this->mParams['filename'], $this->mParams['filekey'], $request->getUpload('chunk'));
         } else {
             // handle first chunk
             $this->mUpload->initialize($this->mParams['filename'], $request->getUpload('chunk'));
         }
     } elseif (isset($this->mParams['filekey'])) {
         // Upload stashed in a previous request
         if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
             $this->dieUsageMsg('invalid-file-key');
         }
         $this->mUpload = new UploadFromStash($this->getUser());
         $this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename']);
     } 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('copyuploaddisabled');
         }
         $async = false;
         if ($this->mParams['asyncdownload']) {
             $this->checkAsyncDownloadEnabled();
             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;
 }
Example #7
0
 /**
  * Get the descriptor of the fieldset that contains the file source 
  * selection. The section is 'source'
  * 
  * @return array Descriptor array
  */
 protected function getSourceSection()
 {
     if ($this->mSessionKey) {
         return array('wpSessionKey' => array('type' => 'hidden', 'default' => $this->mSessionKey), 'wpSourceType' => array('type' => 'hidden', 'default' => 'Stash'));
     }
     $canUploadByUrl = UploadFromUrl::isEnabled() && $this->getUser()->isAllowed('upload_by_url');
     $radio = $canUploadByUrl;
     $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File'));
     $descriptor = array();
     if ($this->mTextTop) {
         $descriptor['UploadFormTextTop'] = array('type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true);
     }
     $descriptor['UploadFile'] = array('class' => 'SFUploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => wfMessage('upload-maxfilesize', $this->getLanguage()->formatSize(wfShorthandToInteger(ini_get('upload_max_filesize'))))->parse() . ' ' . wfMessage('upload_source_file')->escaped(), 'checked' => $selectedSourceType == 'file');
     if ($canUploadByUrl) {
         global $wgMaxUploadSize;
         $descriptor['UploadFileURL'] = array('class' => 'SFUploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'label-message' => 'sourceurl', 'upload-type' => 'Url', 'radio' => &$radio, 'help' => wfMessage('upload-maxfilesize', $this->getLanguage()->formatSize($wgMaxUploadSize))->parse() . ' ' . wfMessage('upload_source_url')->escaped(), 'checked' => $selectedSourceType == 'url');
     }
     Hooks::run('UploadFormSourceDescriptors', array(&$descriptor, &$radio, $selectedSourceType));
     $descriptor['Extensions'] = array('type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true);
     return $descriptor;
 }
 /**
  * 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)];
     }
 }
Example #10
0
	/**
	 * 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() {
		$request = $this->getMain()->getRequest();

		// chunk or one and only one of the following parameters is needed
		if ( !$this->mParams['chunk'] ) {
			$this->requireOnlyOneParameter( $this->mParams,
				'filekey', 'file', 'url', 'statuskey' );
		}

		// Status report for "upload to stash"/"upload from stash"
		if ( $this->mParams['filekey'] && $this->mParams['checkstatus'] ) {
			$progress = UploadBase::getSessionStatus( $this->mParams['filekey'] );
			if ( !$progress ) {
				$this->dieUsage( 'No result in status data', 'missingresult' );
			} elseif ( !$progress['status']->isGood() ) {
				$this->dieUsage( $progress['status']->getWikiText(), 'stashfailed' );
			}
			if ( isset( $progress['status']->value['verification'] ) ) {
				$this->checkVerification( $progress['status']->value['verification'] );
			}
			unset( $progress['status'] ); // remove Status object
			$this->getResult()->addValue( null, $this->getModuleName(), $progress );
			return false;
		}

		if ( $this->mParams['statuskey'] ) {
			$this->checkAsyncDownloadEnabled();

			// 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['chunk'] ) {
			// Chunk upload
			$this->mUpload = new UploadFromChunks();
			if ( isset( $this->mParams['filekey'] ) ) {
				// handle new chunk
				$this->mUpload->continueChunks(
					$this->mParams['filename'],
					$this->mParams['filekey'],
					$request->getUpload( 'chunk' )
				);
			} else {
				// handle first chunk
				$this->mUpload->initialize(
					$this->mParams['filename'],
					$request->getUpload( 'chunk' )
				);
			}
		} elseif ( isset( $this->mParams['filekey'] ) ) {
			// Upload stashed in a previous request
			if ( !UploadFromStash::isValidKey( $this->mParams['filekey'] ) ) {
				$this->dieUsageMsg( 'invalid-file-key' );
			}

			$this->mUpload = new UploadFromStash( $this->getUser() );
			// This will not download the temp file in initialize() in async mode.
			// We still have enough information to call checkWarnings() and such.
			$this->mUpload->initialize(
				$this->mParams['filekey'], $this->mParams['filename'], !$this->mParams['async']
			);
		} 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( 'copyuploaddisabled' );
			}

			if ( !UploadFromUrl::isAllowedHost( $this->mParams['url'] ) ) {
				$this->dieUsageMsg( 'copyuploadbaddomain' );
			}

			if ( !UploadFromUrl::isAllowedUrl( $this->mParams['url'] ) ) {
				$this->dieUsageMsg( 'copyuploadbadurl' );
			}

			$async = false;
			if ( $this->mParams['asyncdownload'] ) {
				$this->checkAsyncDownloadEnabled();

				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;
	}
Example #11
0
 /**
  * Get the descriptor of the fieldset that contains the file source
  * selection. The section is 'source'
  *
  * @return array Descriptor array
  */
 protected function getSourceSection()
 {
     if ($this->mSessionKey) {
         return ['SessionKey' => ['type' => 'hidden', 'default' => $this->mSessionKey], 'SourceType' => ['type' => 'hidden', 'default' => 'Stash']];
     }
     $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed($this->getUser()) === true && $this->getConfig()->get('CopyUploadsFromSpecialUpload');
     $radio = $canUploadByUrl;
     $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File'));
     $descriptor = [];
     if ($this->mTextTop) {
         $descriptor['UploadFormTextTop'] = ['type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true];
     }
     $this->mMaxUploadSize['file'] = min(UploadBase::getMaxUploadSize('file'), UploadBase::getMaxPhpUploadSize());
     $help = $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['file']))->parse();
     // If the user can also upload by URL, there are 2 different file size limits.
     // This extra message helps stress which limit corresponds to what.
     if ($canUploadByUrl) {
         $help .= $this->msg('word-separator')->escaped();
         $help .= $this->msg('upload_source_file')->parse();
     }
     $descriptor['UploadFile'] = ['class' => 'UploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'radio-id' => 'wpSourceTypeFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => $help, 'checked' => $selectedSourceType == 'file'];
     if ($canUploadByUrl) {
         $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize('url');
         $descriptor['UploadFileURL'] = ['class' => 'UploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'radio-id' => 'wpSourceTypeurl', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['url']))->parse() . $this->msg('word-separator')->escaped() . $this->msg('upload_source_url')->parse(), 'checked' => $selectedSourceType == 'url'];
     }
     Hooks::run('UploadFormSourceDescriptors', [&$descriptor, &$radio, $selectedSourceType]);
     $descriptor['Extensions'] = ['type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true];
     return $descriptor;
 }
Example #12
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);
     }
 }
Example #13
0
 /**
  * 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()
 {
     $request = $this->getMain()->getRequest();
     // chunk or one and only one of the following parameters is needed
     if (!$this->mParams['chunk']) {
         $this->requireOnlyOneParameter($this->mParams, 'filekey', 'file', 'url', 'statuskey');
     }
     // 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['chunk']) {
         // Chunk upload
         $this->mUpload = new UploadFromChunks();
         if (isset($this->mParams['filekey'])) {
             // handle new chunk
             $this->mUpload->continueChunks($this->mParams['filename'], $this->mParams['filekey'], $request->getUpload('chunk'));
         } else {
             // handle first chunk
             $this->mUpload->initialize($this->mParams['filename'], $request->getUpload('chunk'));
         }
     } elseif (isset($this->mParams['filekey'])) {
         // Upload stashed in a previous request
         if (!UploadFromStash::isValidKey($this->mParams['filekey'])) {
             $this->dieUsageMsg('invalid-file-key');
         }
         $this->mUpload = new UploadFromStash($this->getUser());
         $this->mUpload->initialize($this->mParams['filekey'], $this->mParams['filename']);
     } 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('copyuploaddisabled');
         }
         $this->mUpload = new UploadFromUrl();
         $this->mUpload->initialize($this->mParams['filename'], $this->mParams['url']);
     }
     return true;
 }
Example #14
0
 /**
  * Get the descriptor of the fieldset that contains the file source
  * selection. The section is 'source'
  *
  * @return Array: descriptor array
  */
 protected function getSourceSection()
 {
     if ($this->mSessionKey) {
         return array('SessionKey' => array('type' => 'hidden', 'default' => $this->mSessionKey), 'SourceType' => array('type' => 'hidden', 'default' => 'Stash'));
     }
     $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed($this->getUser());
     $radio = $canUploadByUrl;
     $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File'));
     $descriptor = array();
     if ($this->mTextTop) {
         $descriptor['UploadFormTextTop'] = array('type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true);
     }
     $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize('file');
     # Limit to upload_max_filesize unless we are running under HipHop and
     # that setting doesn't exist
     if (!wfIsHipHop()) {
         $this->mMaxUploadSize['file'] = min($this->mMaxUploadSize['file'], wfShorthandToInteger(ini_get('upload_max_filesize')), wfShorthandToInteger(ini_get('post_max_size')));
     }
     $descriptor['UploadFile'] = array('class' => 'UploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['file']))->parse() . ' ' . $this->msg('upload_source_file')->escaped(), 'checked' => $selectedSourceType == 'file');
     if ($canUploadByUrl) {
         $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize('url');
         $descriptor['UploadFileURL'] = array('class' => 'UploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['url']))->parse() . ' ' . $this->msg('upload_source_url')->escaped(), 'checked' => $selectedSourceType == 'url');
     }
     wfRunHooks('UploadFormSourceDescriptors', array(&$descriptor, &$radio, $selectedSourceType));
     $descriptor['Extensions'] = array('type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true);
     return $descriptor;
 }
Example #15
0
 /**
  * Get the descriptor of the fieldset that contains the file source
  * selection. The section is 'source'
  *
  * @return array Descriptor array
  */
 protected function getSourceSection()
 {
     if (sizeof($this->mSessionKeys) > 0) {
         $data = array('wpSourceType' => array('type' => 'hidden', 'default' => 'Stash'));
         $index = 0;
         foreach ($this->mDestFiles as $k => $v) {
             if ($v == '') {
                 continue;
             }
             $data['wpDestFile' . $index] = array('type' => 'hidden', 'default' => $v);
             $data['wpSessionKey' . $index] = array('type' => 'hidden', 'default' => $this->mSessionKeys['sessionkey' . $v]);
             $index++;
         }
         return $data;
     }
     $canUploadByUrl = UploadFromUrl::isEnabled() && $this->getUser()->isAllowed('upload_by_url');
     $radio = $canUploadByUrl;
     $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File'));
     $descriptor = array();
     if ($this->mTextTop) {
         $descriptor['UploadFormTextTop'] = array('type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true);
     }
     for ($i = 0; $i < MultipleUpload::getMaxUploadFiles(); $i++) {
         $descriptor['UploadFile' . $i] = array('class' => 'UploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile' . $i, 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'checked' => $selectedSourceType == 'file');
         $descriptor['DestFile' . $i] = array('type' => 'text', 'section' => 'source', 'id' => 'wpDestFile' . $i, 'label-message' => 'destfilename', 'size' => 60, 'default' => $this->mDestFiles[$i], 'nodata' => strval($this->mDestFile) !== '');
         if ($canUploadByUrl) {
             global $wgMaxUploadSize;
             $descriptor['UploadFileURL'] = array('class' => 'UploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => wfMsgExt('upload-maxfilesize', array('parseinline', 'escapenoentities'), $this->getLang()->formatSize($wgMaxUploadSize)) . ' ' . wfMsgHtml('upload_source_url'), 'checked' => $selectedSourceType == 'url');
         }
     }
     wfRunHooks('UploadFormSourceDescriptors', array(&$descriptor, &$radio, $selectedSourceType));
     $descriptor['Extensions'] = array('type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true, 'help' => wfMsgExt('upload-maxfilesize', array('parseinline', 'escapenoentities'), $this->getLang()->formatSize(wfShorthandToInteger(ini_get('upload_max_filesize')))) . ' ' . wfMsgHtml('upload_source_file'));
     return $descriptor;
 }
Example #16
0
 /**
  * Get the descriptor of the fieldset that contains the file source
  * selection. The section is 'source'
  *
  * @return array Descriptor array
  */
 protected function getSourceSection()
 {
     if ($this->mSessionKey) {
         return array('SessionKey' => array('type' => 'hidden', 'default' => $this->mSessionKey), 'SourceType' => array('type' => 'hidden', 'default' => 'Stash'));
     }
     $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed($this->getUser()) === true && $this->getConfig()->get('CopyUploadsFromSpecialUpload');
     $radio = $canUploadByUrl;
     $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File'));
     $descriptor = array();
     if ($this->mTextTop) {
         $descriptor['UploadFormTextTop'] = array('type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true);
     }
     $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize('file');
     # Limit to upload_max_filesize unless we are running under HipHop and
     # that setting doesn't exist
     if (!wfIsHHVM()) {
         $this->mMaxUploadSize['file'] = min($this->mMaxUploadSize['file'], wfShorthandToInteger(ini_get('upload_max_filesize')), wfShorthandToInteger(ini_get('post_max_size')));
     }
     $help = $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['file']))->parse();
     // If the user can also upload by URL, there are 2 different file size limits.
     // This extra message helps stress which limit corresponds to what.
     if ($canUploadByUrl) {
         $help .= $this->msg('word-separator')->escaped();
         $help .= $this->msg('upload_source_file')->parse();
     }
     $descriptor['UploadFile'] = array('class' => 'UploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'radio-id' => 'wpSourceTypeFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => $help, 'checked' => $selectedSourceType == 'file');
     if ($canUploadByUrl) {
         $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize('url');
         $descriptor['UploadFileURL'] = array('class' => 'UploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'radio-id' => 'wpSourceTypeurl', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['url']))->parse() . $this->msg('word-separator')->escaped() . $this->msg('upload_source_url')->parse(), 'checked' => $selectedSourceType == 'url');
     }
     Hooks::run('UploadFormSourceDescriptors', array(&$descriptor, &$radio, $selectedSourceType));
     $descriptor['Extensions'] = array('type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true);
     return $descriptor;
 }
Example #17
0
 protected function saveTempBase64()
 {
     $buffer = base64_decode(UploadFromUrl::getBase64($this->mUrl));
     $this->saveTempFileChunk(null, $buffer);
     return new Status();
 }