From 4a200aa70fef2b2688c20140ac846472abf6d8aa Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Mon, 27 Jul 2009 15:24:14 +0000 Subject: [PATCH] * (bug 19932) added do_close_session_update to avoid closing session on synchronous requests * some upload js cleanup / bug fixes --- includes/HttpFunctions.php | 15 ++++++++---- .../libAddMedia/mvBaseUploadInterface.js | 24 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index a87e6f6095..868bb029e2 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -173,7 +173,8 @@ class Http { $req = new HttpRequest( $sd['url'], array( 'target_file_path' => $sd['target_file_path'], 'upload_session_key'=> $upload_session_key, - 'timeout' => $wgAsyncHTTPTimeout + 'timeout' => $wgAsyncHTTPTimeout, + 'do_close_session_update' => true ) ); // run the actual request .. (this can take some time) wfDebug( __METHOD__ . 'do Request: ' . $sd['url'] . ' tf: ' . $sd['target_file_path'] ); @@ -285,6 +286,7 @@ class HttpRequest { $this->target_file_path = ( isset( $opt['target_file_path'] ) ) ? $opt['target_file_path'] : false; $this->upload_session_key = ( isset( $opt['upload_session_key'] ) ) ? $opt['upload_session_key'] : false; $this->headers_only = ( isset( $opt['headers_only'] ) ) ? $opt['headers_only'] : false; + $this->do_close_session_update = ( isset( $opt['do_close_session_update'] ) ) ? $opt['do_close_session_update'] : false; } /** @@ -345,7 +347,10 @@ class HttpRequest { // set the write back function (if we are writing to a file) if( $this->target_file_path ){ - $cwrite = new simpleFileWriter( $this->target_file_path, $this->upload_session_key ); + $cwrite = new simpleFileWriter( $this->target_file_path, + $this->upload_session_key, + $this->do_close_session_update + ); if( !$cwrite->status->isOK() ){ wfDebug( __METHOD__ . "ERROR in setting up simpleFileWriter\n" ); $status = $cwrite->status; @@ -499,10 +504,11 @@ class simpleFileWriter { var $session_id = null; var $session_update_interval = 0; // how often to update the session while downloading - function simpleFileWriter( $target_file_path, $upload_session_key ){ + function simpleFileWriter( $target_file_path, $upload_session_key, $do_close_session_update = false ){ $this->target_file_path = $target_file_path; $this->upload_session_key = $upload_session_key; $this->status = Status::newGood(); + $this->do_close_session_update = $do_close_session_update; // open the file: $this->fp = fopen( $this->target_file_path, 'w' ); if( $this->fp === false ){ @@ -534,7 +540,8 @@ class simpleFileWriter { } // if more than session_update_interval second have passed update_session_progress - if( $this->upload_session_key && ( ( time() - $this->prevTime ) > $this->session_update_interval ) ) { + if( $this->do_close_session_update && + $this->upload_session_key && ( ( time() - $this->prevTime ) > $this->session_update_interval ) ) { $this->prevTime = time(); $session_status = $this->update_session_progress(); if( !$session_status->isOK() ){ diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index 2b2384f908..9b0efc43db 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -194,7 +194,9 @@ mvBaseUploadInterface.prototype = { var httpUpConf ={ 'url' : $j('#wpUploadFileURL').val(), 'filename' : $j('#wpDestFile').val(), - 'comment' : $j('#wpUploadDescription').val() + 'comment' : $j('#wpUploadDescription').val(), + 'ignorewarnings' : ($j('#wpIgnoreWarning').is(':checked')) ?'true':'false' , + 'watch' : ($j('#wpWatchthis').is(':checked'))?'true':'false' } //check for editToken _this.etoken = $j("input[name='wpEditToken']").val(); @@ -222,11 +224,12 @@ mvBaseUploadInterface.prototype = { //else try and get a token: if(!_this.etoken && _this.api_url){ - js_log('Error:doHttpUpload: missing token'); - + js_log('Error:doHttpUpload: missing token'); }else{ req['token'] =_this.etoken; } + //reset the done with action flag: + _this.action_done = false; //do the api req do_api_req({ 'data': req, @@ -458,7 +461,7 @@ mvBaseUploadInterface.prototype = { bObj[ gM('ignorewarning') ] = function() { js_error('todo: ignore warnings action '); }; - _this.updateProgressWin( gM('uploadwarning'), '

' + gM('uploadwarning') + '

' +msg + '

',bObj); + _this.updateProgressWin( gM('uploadwarning'), '

' + gM('uploadwarning') + '

' +wmsg + '

',bObj); return false; } //should be "OK" @@ -487,16 +490,20 @@ mvBaseUploadInterface.prototype = { if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){ var url = apiRes.upload.imageinfo.descriptionurl; //check done action: - if(_this.done_upload_cb){ + if( _this.done_upload_cb && typeof _this.done_upload_cb == 'function'){ //close up shop: $j('#upProgressDialog').dialog('close'); //call the callback: _this.done_upload_cb( url ); }else{ var bObj = {}; + bObj[ gM('return-to-form')] = function(){ + $j(this).dialog('close'); + } bObj[ gM('go-to-resource') ] = function(){ window.location = url; - }; + }; + _this.action_done = true; _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', url), bObj); js_log('apiRes.upload.imageinfo::'+url); } @@ -592,10 +599,9 @@ mvBaseUploadInterface.prototype = { }, cancel_action:function(dlElm){ //confirm: - if( confirm( gM('mv-cancel-confim') )){ - alert("do dialog close:: cancel_action mvbase"); + if( confirm( gM('mv-cancel-confim') )){ //@@todo (cancel the encode / upload) - $j(dlElm).dialog('close'); + $j(this).dialog('close'); return false; }else{ return true; -- 2.20.1