// One and only one of the following parameters is needed
$this->requireOnlyOneParameter( $this->mParams,
'sessionkey', 'file', 'url' );
+ // And this one is needed
+ if ( !isset( $this->mParams['filename'] ) ) {
+ $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
+ }
+
if ( $this->mParams['sessionkey'] ) {
- /**
- * Upload stashed in a previous request
- */
- // Check the session key
- if ( !isset( $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] ) ) {
+ // Upload stashed in a previous request
+ $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
+ if ( !UploadFromStash::isValidSessionKey( $this->mParams['sessionkey'], $sessionData ) ) {
$this->dieUsageMsg( array( 'invalid-session-key' ) );
}
$this->mUpload = new UploadFromStash();
$this->mUpload->initialize( $this->mParams['filename'],
$this->mParams['sessionkey'],
- $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] );
- } elseif ( isset( $this->mParams['filename'] ) ) {
- /**
- * Upload from URL, etc.
- * Parameter filename is required
- */
- if ( isset( $this->mParams['file'] ) ) {
- $this->mUpload = new UploadFromFile();
- $this->mUpload->initialize(
- $this->mParams['filename'],
- $request->getFileTempName( 'file' ),
- $request->getFileSize( 'file' )
- );
- } elseif ( isset( $this->mParams['url'] ) ) {
- // make sure upload by URL is enabled:
- if ( !$wgAllowCopyUploads ) {
- $this->dieUsageMsg( array( 'copyuploaddisabled' ) );
- }
+ $sessionData[$this->mParams['sessionkey']] );
+
+
+ } 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 ( !$wgAllowCopyUploads ) {
+ $this->dieUsageMsg( array( 'copyuploaddisabled' ) );
+ }
- // make sure the current user can upload
- if ( !$wgUser->isAllowed( 'upload_by_url' ) ) {
- $this->dieUsageMsg( array( 'badaccess-groups' ) );
- }
+ $this->mUpload = new UploadFromUrl;
+ $async = $this->mParams['asyncdownload'] ? 'async' : null;
+ $this->checkPermissions( $wgUser );
- $this->mUpload = new UploadFromUrl;
- $async = $this->mParams['asyncdownload'] ? 'async' : null;
-
- $result = $this->mUpload->initialize( $this->mParams['filename'],
- $this->mParams['url'],
- $this->mParams['comment'],
- $this->mParams['watchlist'],
- $this->mParams['ignorewarnings'],
- $async );
-
- $this->checkPermissions( $wgUser );
- if ( $async ) {
- $this->getResult()->addValue( null,
- $this->getModuleName(),
- array( 'queued' => $result ) );
- return;
- }
+ $result = $this->mUpload->initialize(
+ $this->mParams['filename'],
+ $this->mParams['url'],
+ $this->mParams['comment'],
+ $this->mParams['watchlist'],
+ $this->mParams['ignorewarnings'],
+ $async );
+
+ if ( $async ) {
+ $this->getResult()->addValue( null,
+ $this->getModuleName(),
+ array( 'queued' => $result ) );
+ return;
+ }
- $status = $this->mUpload->retrieveFileFromUrl();
- if ( !$status->isGood() ) {
- $this->getResult()->addValue( null,
- $this->getModuleName(),
- array( 'error' => $status ) );
- return;
- }
+ $status = $this->mUpload->retrieveFileFromUrl();
+ if ( !$status->isGood() ) {
+ $this->getResult()->addValue( null,
+ $this->getModuleName(),
+ array( 'error' => $status ) );
+ return;
}
- } else {
- $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
}
+
$this->checkPermissions( $wgUser );
* Implements regular file uploads
*/
class UploadFromFile extends UploadBase {
- protected $mWebUpload = null;
+ protected $mUpload = null;
function initializeFromRequest( &$request ) {
- $this->mWebUpload = $request->getUpload( 'wpUploadFile' );
-
+ $upload = $request->getUpload( 'wpUploadFile' );
$desiredDestName = $request->getText( 'wpDestFile' );
if( !$desiredDestName )
- $desiredDestName = $this->mWebUpload->getName();
- return $this->initializePathInfo(
- $desiredDestName,
- $this->mWebUpload->getTempName(),
- $this->mWebUpload->getSize()
- );
+ $desiredDestName = $upload->getName();
+
+ return $this->initialize( $desiredDestName, $upload );
}
+
/**
- * Entry point for upload from file.
+ * Initialize from a filename and a WebRequestUpload
*/
- function initialize( $name, $tempPath, $fileSize ) {
- return $this->initializePathInfo( $name, $tempPath, $fileSize );
+ function initialize( $name, $webRequestUpload ) {
+ $this->mUpload = $webRequestUpload;
+ return $this->initializePathInfo( $name,
+ $this->mUpload->getTempName(), $this->mUpload->getSize() );
}
static function isValidRequest( $request ) {
# Allow all requests, even if no file is present, so that an error
# 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->mWebUpload->isIniSizeOverflow() ) {
+ if ( $this->mUpload->isIniSizeOverflow() ) {
global $wgMaxUploadSize;
return array(
'status' => self::FILE_TOO_LARGE,