$this->dieUsageMsg( array( 'uploaddisabled' ) );
}
+ // Parameter handling
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
-
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName( 'file' );
+ // Select an upload module
+ $this->selectUploadModule();
+ if ( !isset( $this->mUpload ) ) {
+ $this->dieUsage( 'No upload module set', 'nomodule' );
+ }
+
+ // First check permission to upload
+ $this->checkPermissions( $wgUser );
+ // Check permission to upload this file
+ $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ if ( $permErrors !== true ) {
+ // Todo: more specific error message
+ $this->dieUsageMsg( array( 'badaccess-groups' ) );
+ }
+
+ // Fetch the file
+ $status = $this->mUpload->fetchFile();
+ if ( !$status->isGood() ) {
+ $errors = $status->getErrorsArray();
+ $error = array_shift( $errors[0] );
+ $this->dieUsage( 'Error fetching file from remote source', $error, 0, $errors[0] );
+ }
+
+ // Check if the uploaded file is sane
+ $this->verifyUpload();
+
+ // Check warnings if necessary
+ $warnings = $this->checkForWarnings();
+ if ( $warnings ) {
+ $this->getResult()->addValue( null, $this->getModuleName(), $warnings );
+ } else {
+ // Perform the upload
+ $result = $this->performUpload();
+ $this->getResult()->addValue( null, $this->getModuleName(), $result );
+ }
+
+ // Cleanup any temporary mess
+ $this->mUpload->cleanupTempFile();
+ }
+
+ /**
+ * Select an upload module and set it to mUpload. Dies on failure.
+ */
+ protected function selectUploadModule() {
+ $request = $this->getMain()->getRequest();
+
// One and only one of the following parameters is needed
$this->requireOnlyOneParameter( $this->mParams,
'sessionkey', 'file', 'url' );
if ( $this->mParams['sessionkey'] ) {
// Upload stashed in a previous request
- $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
+ $sessionData = $request->getSessionData( UploadBase::getSessionKeyName() );
if ( !UploadFromStash::isValidSessionKey( $this->mParams['sessionkey'], $sessionData ) ) {
$this->dieUsageMsg( array( 'invalid-session-key' ) );
}
$this->mParams['url'], $async );
}
- if ( !isset( $this->mUpload ) ) {
- $this->dieUsage( 'No upload module set', 'nomodule' );
- }
-
- // First check permission to upload
- $this->checkPermissions( $wgUser );
- // Check permission to upload this file
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if ( $permErrors !== true ) {
- // Todo: more specific error message
- $this->dieUsageMsg( array( 'badaccess-groups' ) );
- }
-
- // Fetch the file
- $status = $this->mUpload->fetchFile();
- if ( !$status->isGood() ) {
- $errors = $status->getErrorsArray();
- $error = array_shift( $errors[0] );
- $this->dieUsage( 'Error fetching file from remote source', $error, 0, $errors[0] );
- }
-
- // Check if the uploaded file is sane
- $this->verifyUpload();
-
- // Check warnings if necessary
- $warnings = $this->checkForWarnings();
- if ( $warnings ) {
- $this->getResult()->addValue( null, $this->getModuleName(), $warnings );
- } else {
- // Perform the upload
- $result = $this->performUpload();
- $this->getResult()->addValue( null, $this->getModuleName(), $result );
- }
-
- // Cleanup any temporary mess
- $this->mUpload->cleanupTempFile();
}
/**
/**
* Performs file verification, dies on error.
*/
- public function verifyUpload( ) {
+ protected function verifyUpload( ) {
$verification = $this->mUpload->verifyUpload( );
if ( $verification['status'] === UploadBase::OK ) {
- return $verification;
+ return;
}
- $this->getVerificationError( $verification );
- }
-
- /**
- * Produce the usage error
- *
- * @param $verification array an associative array with the status
- * key
- */
- public function getVerificationError( $verification ) {
// TODO: Move them to ApiBase's message map
switch( $verification['status'] ) {
case UploadBase::EMPTY_FILE:
}
}
+ /**
+ * Check warnings if ignorewarnings is not set.
+ * Returns a suitable result array if there were warnings
+ */
protected function checkForWarnings() {
$result = array();
return;
}
+ /**
+ * Perform the actual upload. Returns a suitable result array on success;
+ * dies on failure.
+ */
protected function performUpload() {
global $wgUser;
if ( !$status->isGood() ) {
$error = $status->getErrorsArray();
- $this->getResult()->setIndexedTagName( $result['details'], 'error' );
+ $this->getResult()->setIndexedTagName( $error, 'error' );
$this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}