From ab2745e92b1533bd7e3a188b9c789f04dff184d5 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Thu, 15 Oct 2009 00:14:05 +0000 Subject: [PATCH] * ( bug 21089 ) fixes js2 upload stash support. * Tested with chunk firefogg uploads, normal js2 uploads and http copy by url uploads --- includes/api/ApiUpload.php | 57 +++++++++--------- includes/upload/UploadFromChunks.php | 27 +++++---- .../libAddMedia/mvBaseUploadInterface.js | 58 ++++++++++--------- js2/mwEmbed/mv_embed.js | 2 +- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index b55ae18946..d37e54f371 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -57,11 +57,11 @@ class ApiUpload extends ApiBase { // 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 @@ -88,11 +88,10 @@ class ApiUpload extends ApiBase { /** * 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( @@ -100,22 +99,22 @@ class ApiUpload extends ApiBase { ); // 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 { /** @@ -135,14 +134,14 @@ class ApiUpload extends ApiBase { ); } 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; @@ -161,11 +160,11 @@ class ApiUpload extends ApiBase { } } } - + if( !isset( $this->mUpload ) ) $this->dieUsage( 'No upload module set', 'nomodule' ); - - + + // Finish up the exec command: $this->doExecUpload(); @@ -196,7 +195,7 @@ class ApiUpload extends ApiBase { 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 ) { @@ -210,8 +209,8 @@ class ApiUpload extends ApiBase { 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 ) ); @@ -227,12 +226,12 @@ class ApiUpload extends ApiBase { $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: @@ -242,14 +241,12 @@ class ApiUpload extends ApiBase { } 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 ) @@ -262,16 +259,18 @@ class ApiUpload extends ApiBase { 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; } } @@ -283,8 +282,8 @@ class ApiUpload extends ApiBase { 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(); diff --git a/includes/upload/UploadFromChunks.php b/includes/upload/UploadFromChunks.php index 1167243372..6a8478a0e0 100644 --- a/includes/upload/UploadFromChunks.php +++ b/includes/upload/UploadFromChunks.php @@ -57,13 +57,14 @@ class UploadFromChunks extends UploadBase { // 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 ){ @@ -72,20 +73,17 @@ class UploadFromChunks extends UploadBase { 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 @@ -185,7 +183,7 @@ class UploadFromChunks extends UploadBase { 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; @@ -194,7 +192,9 @@ class UploadFromChunks extends UploadBase { if( $watch == '' ) $watch = $this->mWatch; + $status = parent::performUpload( $summary, $comment, $watch, $user ); + if( !$status->isGood() ) { return $status; } @@ -209,7 +209,6 @@ class UploadFromChunks extends UploadBase { ) ); exit( 0 ); - } } diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index 8bd7e68bab..7c2bb540a1 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -336,26 +336,6 @@ mvBaseUploadInterface.prototype = { _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; @@ -452,10 +432,10 @@ mvBaseUploadInterface.prototype = { 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']; @@ -564,14 +544,36 @@ mvBaseUploadInterface.prototype = { wmsg+=''; } wmsg+=''; - 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'); diff --git a/js2/mwEmbed/mv_embed.js b/js2/mwEmbed/mv_embed.js index bf525d26b9..17f31e1cc5 100644 --- a/js2/mwEmbed/mv_embed.js +++ b/js2/mwEmbed/mv_embed.js @@ -1016,7 +1016,7 @@ var mvJsLoader = { js_log( 'embedVideoCheck:' ); // Make sure we have jQuery _this.jQueryCheck( function() { - //set class videonojs to hidden + //set class videonojs to loading $j('.videonojs').html( gM('mwe-loading_txt') ); //Set up the embed video player class request: (include the skin js as well) var depReq = [ -- 2.20.1