// Check whether upload is enabled
if ( !UploadBase::isEnabled() )
$this->dieUsageMsg( array( 'uploaddisabled' ) );
-
+
// One and only one of the following parameters is needed
$this->requireOnlyOneParameter( $this->mParams,
- 'sessionkey', 'file', 'url', 'enablechunks' );
-
+ 'sessionkey', 'file', 'url', 'enablechunks' );
+
if ( $this->mParams['enablechunks'] ) {
/**
* Chunked upload mode
/**
* Return the status of the given background upload session_key:
*/
-
// Check the session key
if( !isset( $_SESSION['wsDownload'][$this->mParams['sessionkey']] ) )
return $this->dieUsageMsg( array( 'invalid-session-key' ) );
-
+
$sd =& $_SESSION['wsDownload'][$this->mParams['sessionkey']];
// Keep passing down the upload sessionkey
$statusResult = array(
);
// put values into the final apiResult if available
- if( isset( $sd['apiUploadResult'] ) )
+ if( isset( $sd['apiUploadResult'] ) )
$statusResult['apiUploadResult'] = $sd['apiUploadResult'];
- if( isset( $sd['loaded'] ) )
+ if( isset( $sd['loaded'] ) )
$statusResult['loaded'] = $sd['loaded'];
- if( isset( $sd['content_length'] ) )
+ if( isset( $sd['content_length'] ) )
$statusResult['content_length'] = $sd['content_length'];
- return $this->getResult()->addValue( null,
+ return $this->getResult()->addValue( null,
$this->getModuleName(), $statusResult );
-
+
} elseif( $this->mParams['sessionkey'] ) {
/**
* Upload stashed in a previous request
*/
$this->mUpload = new UploadFromStash();
- $this->mUpload->initialize( $this->mParams['filename'],
+ $this->mUpload->initialize( $this->mParams['filename'],
$_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
} else {
/**
);
} elseif ( isset( $this->mParams['url'] ) ) {
$this->mUpload = new UploadFromUrl();
- $this->mUpload->initialize( $this->mParams['filename'],
+ $this->mUpload->initialize( $this->mParams['filename'],
$this->mParams['url'], $this->mParams['asyncdownload'] );
$status = $this->mUpload->fetchFile();
if( !$status->isOK() ) {
return $this->dieUsage( 'fetchfileerror', $status->getWikiText() );
}
-
+
// check if we doing a async request set session info and return the upload_session_key)
if( $this->mUpload->isAsync() ){
$upload_session_key = $status->value;
}
}
}
-
+
if( !isset( $this->mUpload ) )
$this->dieUsage( 'No upload module set', 'nomodule' );
-
-
+
+
// Finish up the exec command:
$this->doExecUpload();
if( $permErrors !== true ) {
$this->dieUsageMsg( array( 'baddaccess-groups' ) );
}
-
+
// TODO: Move them to ApiBase's message map
$verification = $this->mUpload->verifyUpload();
if( $verification['status'] !== UploadBase::OK ) {
break;
case UploadBase::FILETYPE_BADTYPE:
global $wgFileExtensions;
- $this->dieUsage( 'This type of file is banned', 'filetype-banned',
- 0, array(
+ $this->dieUsage( 'This type of file is banned', 'filetype-banned',
+ 0, array(
'filetype' => $verification['finalExt'],
'allowed' => $wgFileExtensions
) );
$this->dieUsage( 'Overwriting an existing file is not allowed', 'overwrite' );
break;
case UploadBase::VERIFICATION_ERROR:
- $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
+ $this->getResult()->setIndexedTagName( $verification['details'], 'detail' );
$this->dieUsage( 'This file did not pass file verification', 'verification-error',
0, array( 'details' => $verification['details'] ) );
break;
case UploadBase::UPLOAD_VERIFICATION_ERROR:
- $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
+ $this->dieUsage( "The modification you tried to make was aborted by an extension hook",
'hookaborted', 0, array( 'error' => $verification['error'] ) );
break;
default:
}
return $result;
}
-
if( !$this->mParams['ignorewarnings'] ) {
$warnings = $this->mUpload->checkWarnings();
if( $warnings ) {
-
// Add indices
$this->getResult()->setIndexedTagName( $warnings, 'warning' );
-
+
if( isset( $warnings['duplicate'] ) ) {
$dupes = array();
foreach( $warnings['duplicate'] as $key => $dupe )
if( isset( $warnings['exists'] ) ) {
$warning = $warnings['exists'];
unset( $warnings['exists'] );
- $warnings[$warning['warning']] = $warning['file']->getName();
+ $warnings[$warning['warning']] = $warning['file']->getName();
}
-
+
$result['result'] = 'Warning';
$result['warnings'] = $warnings;
$sessionKey = $this->mUpload->stashSession();
- if ( !$sessionKey )
+ if ( !$sessionKey )
$this->dieUsage( 'Stashing temporary file failed', 'stashfailed' );
+
$result['sessionkey'] = $sessionKey;
+
return $result;
}
}
if( !$status->isGood() ) {
$error = $status->getErrorsArray();
$this->getResult()->setIndexedTagName( $result['details'], 'error' );
-
- $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
+
+ $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
}
$file = $this->mUpload->getLocalFile();
// check for the file:
return (bool)$request->getFileTempName( 'file' );
}
-
/* check warnings depending on chunk_mode */
function checkWarnings(){
- $warning = array();
- return $warning;
+ if( $this->chunk_mode == UploadFromChunks::DONE ){
+ return parent::checkWarnings();
+ }else{
+ return array();
+ }
}
-
function isEmptyFile(){
// does not apply to chunk init
if( $this->chunk_mode == UploadFromChunks::INIT ){
return parent::isEmptyFile();
}
}
-
/**
* Verify whether the upload is sane.
* Returns self::OK or else an array with error information
*/
function verifyUpload() {
- // no checks on chunk upload mode:
- if( $this->chunk_mode == UploadFromChunks::INIT )
- return array( 'status' => self::OK );
-
- // verify on init and last chunk request
- if( $this->chunk_mode == UploadFromChunks::CHUNK ||
- $this->chunk_mode == UploadFromChunks::DONE )
+ // verify once DONE uploading chunks
+ if( $this->chunk_mode == UploadFromChunks::DONE ){
return parent::verifyUpload();
+ }else{
+ return array( 'status' => self::OK );
+ }
}
// only run verifyFile on completed uploaded chunks
return $status;
}
} else if( $this->chunk_mode == UploadFromChunks::DONE ){
- // update the values from the local (session init) if not paseed again)
+ // update the values from the local (session init) if not passed again)
if( $summary == '' )
$summary = $this->mSummary;
if( $watch == '' )
$watch = $this->mWatch;
+
$status = parent::performUpload( $summary, $comment, $watch, $user );
+
if( !$status->isGood() ) {
return $status;
}
)
);
exit( 0 );
-
}
}
_this.processApiResult( data );
});
},
- doAjaxWarningIgnore:function(){
- var _this = this;
- if( !_this.upload_session_key )
- return js_error('missing upload_session_key (can\'t ignore warnigns');
- //do the ignore warnings submit to the api:
- var req = {
- 'ignorewarnings' : 'true',
- 'sessionkey' :!_this.upload_session_key
- };
- //add token if present:
- if(this.etoken)
- req['token'] = this.etoken;
-
- do_api_req({
- 'data':req,
- 'url': _this.api_url
- },function(data){
- _this.processApiResult(data);
- });
- },
doAjaxUploadStatus:function() {
var _this = this;
error_code = apiRes.error.code;
}else if( apiRes.upload.code ){
if(typeof apiRes.upload.code == 'object'){
- if(apiRes.upload.code[0]){
+ if( apiRes.upload.code[0] ){
error_code = apiRes.upload.code[0];
}
- if(apiRes.upload.code['status']){
+ if( apiRes.upload.code['status'] ){
error_code = apiRes.upload.code['status'];
if(apiRes.upload.code['filtered'])
errorReplaceArg =apiRes.upload.code['filtered'];
wmsg+='</li>';
}
wmsg+='</ul>';
- if( apiRes.upload.warnings.sessionkey)
- _this.warnings_sessionkey = apiRes.upload.warnings.sessionkey;
+ if( apiRes.upload.sessionkey)
+ _this.warnings_sessionkey = apiRes.upload.sessionkey;
+
var bObj = {};
bObj[ gM('mwe-ignorewarning') ] = function() {
- js_log('ignorewarning req:')
- //re-inciate the upload proccess
- $j('#wpIgnoreWarning').attr('checked', true);
- $j( _this.editForm ).submit();
+ //check if we have a stashed key:
+ if( _this.warnings_sessionkey ){
+ //set to "loading"
+ $j( '#upProgressDialog' ).html( mv_get_loading_img() );
+ //setup loading:
+ var req = {
+ 'action' : 'upload',
+ 'sessionkey': _this.warnings_sessionkey,
+ 'ignorewarnings':1,
+ 'filename': $j('#wpDestFile').val(),
+ 'token' : _this.etoken
+ };
+ //run the upload from stash request
+ do_api_req({
+ 'data': req,
+ 'url' : _this.api_url
+ }, function( data ){
+ _this.processApiResult( data );
+ });
+ }else{
+ js_log('No session key re-sending upload')
+ //do a stashed upload
+ $j('#wpIgnoreWarning').attr('checked', true);
+ $j( _this.editForm ).submit();
+ }
};
bObj[ gM('mwe-return-to-form') ] = function(){
$j(this).dialog('close');