From 6a90ab3d9788f1f0c9bb1f0e0e559f63d4b2fb83 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Thu, 8 Oct 2009 22:48:56 +0000 Subject: [PATCH] * js2 upload fixes (don't display preview on http uploads) --- .../libAddMedia/mvBaseUploadInterface.js | 62 +++-- js2/mwEmbed/libAddMedia/mvFirefogg.js | 7 +- js2/mwEmbed/libAddMedia/remoteSearchDriver.js | 230 +++++++++--------- js2/mwEmbed/mv_embed.js | 8 +- 4 files changed, 156 insertions(+), 151 deletions(-) diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index fe22e5a69b..8b37466396 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -52,6 +52,7 @@ mvBaseUploadInterface.prototype = { warnings_sessionkey:null, chunks_supported:false, form_post_override:false, + http_copy_upload : false, action_done:false, //the edit token: etoken:false, @@ -85,6 +86,10 @@ mvBaseUploadInterface.prototype = { //set up the submit action: $j( _this.editForm ).submit( function(){ js_log('setupForm.onSubmit:'); + + //set the upload mode: + _this.setWgUploadSelect(); + //run the original onsubmit (if not run yet set flag to avoid excessive chaining ) if( typeof( _this.org_onsubmit ) == 'function' ){ if( ! _this.org_onsubmit() ){ @@ -94,7 +99,7 @@ mvBaseUploadInterface.prototype = { } //check for post action override: if( _this.form_post_override ){ - js_log('form_post_override is true do form proccessing:'); + js_log('form_post_override is true do form proccesing:'); return true; } //get the input form data in flat json: @@ -117,7 +122,7 @@ mvBaseUploadInterface.prototype = { }catch(e){ js_log('::error in dispProgressOverlay or detectUploadMode'); } - + //don't submit the form we will do the post in ajax return false; }); @@ -192,26 +197,20 @@ mvBaseUploadInterface.prototype = { $j('#up-progressbar' ).progressbar( 'value', parseInt( 100 ) ); $j('#up-status-container').html( gM('mwe-upload-in-progress') ); }, + setWgUploadSelect: function(){ + if( $j('#wpSourceTypeFile').length == 0 || $j('#wpSourceTypeFile').get(0).checked ){ + this.http_copy_upload = false; + }else if( $j('#wpSourceTypeURL').get(0).checked ){ + this.http_copy_upload = true; + } + }, doUploadSwitch:function(){ var _this = this; js_log('mvUPload:doUploadSwitch():' + _this.upload_mode); //issue a normal post request - if( _this.upload_mode == 'post' ) { - //we don't support the upload api - //trick the browser into thinking the wpUpload button was pressed (there might be a cleaner way to do this) - $j(_this.editForm).append( - '' - ); - //do normal post - _this.form_post_override = true; - js_log('doUploadSwitch:: submit call'); - //do the submit : - _this.editForm.submit(); - }else if( - _this.upload_mode == 'api' && - ( $j('#wpSourceTypeFile').length == 0 || $j('#wpSourceTypeFile').get(0).checked ) - ){ - //@@TODO check for sendAsBinnary to support firefox 3.5 progress on upload + if( _this.upload_mode == 'api' && ! _this.http_copy_upload ){ + + //@@TODO check for sendAsBinnary to support firefox/html5 progress on upload //set the form target to iframe target: _this.iframeId = 'f_' + ($j('iframe').length + 1); @@ -242,11 +241,12 @@ mvBaseUploadInterface.prototype = { if( tmpAryData[i]['name'] ) js_log('name: ' + tmpAryData[i]['name'] + ' = ' + tmpAryData[i]['value']); }*/ - $j(_this.editForm).submit(); + $j( _this.editForm ).submit(); return false; - }else if( _this.upload_mode == 'api' && $j('#wpSourceTypeURL').get(0).checked){ + }else if( _this.upload_mode == 'api' ){ js_log('doHttpUpload (no form submit) '); + //if the api is supported.. && source type is http do upload with http status updates var httpUpConf ={ 'url' : $j('#wpUploadFileURL').val(), @@ -310,7 +310,7 @@ mvBaseUploadInterface.prototype = { //setup request: var req = { 'action' : 'upload', - 'asyncdownload' : true //do a s + 'asyncdownload' : true //do async download }; //set config from options: for(var i in opt){ @@ -407,8 +407,8 @@ mvBaseUploadInterface.prototype = { //special case update the file progress where we have data size: $j('#up-status-container').html( gM('mwe-upload-stats-fileprogres', [ - formatSize( data.upload['loaded'] ), - formatSize( data.upload['content_length'] ) + $mw.lang.formatSize( data.upload['loaded'] ), + $mw.lang.formatSize( data.upload['content_length'] ) ] ) ); @@ -418,7 +418,7 @@ mvBaseUploadInterface.prototype = { //for lack of content-length requests: $j('#up-status-container').html( gM('mwe-upload-stats-fileprogres', [ - formatSize( data.upload['loaded'] ), + $mw.lang.formatSize( data.upload['loaded'] ), gM('mwe-upload-unknown-size') ] ) @@ -437,7 +437,7 @@ mvBaseUploadInterface.prototype = { var bObj = {}; bObj[ gM('mwe-return-to-form') ] = function(){ _this.form_post_override = false; - $j(this).empty().dialog('close'); + $j(this).dialog('close'); }; //@@TODO should be refactored to more specialUpload page type error handling @@ -571,7 +571,7 @@ mvBaseUploadInterface.prototype = { $j( _this.editForm ).submit(); }; bObj[ gM('mwe-return-to-form') ] = function(){ - $j(this).empty().dialog('close'); + $j(this).dialog('close'); _this.form_post_override = false; } _this.updateProgressWin( gM('mwe-uploadwarning'), '

' + gM('mwe-uploadwarning') + '

' +wmsg + '

',bObj); @@ -606,14 +606,14 @@ mvBaseUploadInterface.prototype = { if( _this.done_upload_cb && typeof _this.done_upload_cb == 'function'){ js_log("call done_upload_cb"); //close up shop: - $j('#upProgressDialog').empty().dialog('close'); + $j('#upProgressDialog').dialog('close'); //call the callback: _this.done_upload_cb( apiRes.upload ); return false; }else{ var bObj = {}; bObj[ gM('mwe-return-to-form')] = function(){ - $j(this).empty().dialog('close'); + $j(this).dialog('close'); _this.form_post_override = false; } bObj[ gM('mwe-go-to-resource') ] = function(){ @@ -641,7 +641,7 @@ mvBaseUploadInterface.prototype = { //@@todo should fix jquery ui to not use object keys as user msg's var bObj = {}; bObj[ gM('mwe-ok-button') ] = function(){ - $j(this).empty().dialog('close'); + $j(this).dialog('close'); }; $j('#upProgressDialog').dialog('option','buttons', bObj); } @@ -718,10 +718,8 @@ mvBaseUploadInterface.prototype = { //confirm: if( confirm( gM('mwe-cancel-confim') )){ //@@todo (cancel the encode / upload) - $j(this).empty().dialog('close'); + $j(this).dialog('close'); } - //dont' follow the link; - return false; } }; diff --git a/js2/mwEmbed/libAddMedia/mvFirefogg.js b/js2/mwEmbed/libAddMedia/mvFirefogg.js index db44289235..c0875c9abe 100644 --- a/js2/mwEmbed/libAddMedia/mvFirefogg.js +++ b/js2/mwEmbed/libAddMedia/mvFirefogg.js @@ -313,15 +313,16 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface }, //do firefogg specific additions: dispProgressOverlay:function(){ - this.pe_dispProgressOverlay(); + this.pe_dispProgressOverlay(); + //if we are uploading video (not in passthrough mode show preview button) - if( ! this.encoder_settings['passthrough'] ){ + if( ! this.encoder_settings['passthrough'] && ! this.http_copy_upload ){ this.doPreviewControl(); } }, doPreviewControl:function(){ var _this = this; - //prepend preview collapable + //prepend preview (if fogg) $j('#upProgressDialog').append( '

'+ $j.btnHtml(gM('fogg-preview'), 'fogg_preview', 'triangle-1-e') + diff --git a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js index 6e8370f4a1..37bfe8d671 100644 --- a/js2/mwEmbed/libAddMedia/remoteSearchDriver.js +++ b/js2/mwEmbed/libAddMedia/remoteSearchDriver.js @@ -1256,133 +1256,138 @@ remoteSearchDriver.prototype = { //local repo jump directly to check Import Resource callback: cir_callback( rObj ); }else{ + js_log('check for: ' + rObj.target_resource_title); //check if the file is local (can be shared repo) _this.checkForFile(rObj.target_resource_title, function(imagePage){ if( imagePage ){ - cir_callback( rObj ); - } - }); - //update target_resource_title with resource repository prefix: - rObj.target_resource_title = cp.resource_prefix + rObj.target_resource_title; - reqObj['titles'] = _this.cFileNS + ':' + rObj.target_resource_title, - //check if the file exists: - _this.checkForFile( rObj.target_resource_title, function( imagePage ){ - if( imagePage ){ - //update to local src - rObj.local_src = imagePage['imageinfo'][0].url; - //@@todo maybe update poster too? - rObj.local_poster = imagePage['imageinfo'][0].thumburl; - - //resource is already present (or resource with same name is already present) - rObj.target_resource_title = found_title.replace(/File:|Image:/,''); cir_callback( rObj ); }else{ - js_log("resource not present: update:"+ _this.cFileNS + ':' + rObj.target_resource_title); + //update target_resource_title with resource repository prefix: + rObj.target_resource_title = cp.resource_prefix + rObj.target_resource_title; + reqObj['titles'] = _this.cFileNS + ':' + rObj.target_resource_title, + //check if the file exists: + _this.checkForFile( rObj.target_resource_title, function( imagePage ){ + if( imagePage ){ + //update to local src + rObj.local_src = imagePage['imageinfo'][0].url; + //@@todo maybe update poster too? + rObj.local_poster = imagePage['imageinfo'][0].thumburl; + + //resource is already present (or resource with same name is already present) + rObj.target_resource_title = found_title.replace(/File:|Image:/,''); + cir_callback( rObj ); + }else{ + _this.doImportInterface(rObj, callback); + } + }); + } + }); + } + }, + doImportInterface : function( rObj, callback){ + js_log("doImportInterface:: update:"+ _this.cFileNS + ':' + rObj.target_resource_title); + //update the rObj with import info + rObj.pSobj.updateDataForImport( rObj ); - //update the rObj with import info - rObj.pSobj.updateDataForImport( rObj ); + //setup the resource description from resource description: + var wt = '{{Information '+"\n"; - //setup the resource description from resource description: - var wt = '{{Information '+"\n"; + if( rObj.desc ){ + wt += '|Description= ' + rObj.desc + "\n"; + }else{ + wt += '|Description= ' + gM('mwe-missing_desc_see_source', rObj.link ) + "\n"; + } - if( rObj.desc ){ - wt += '|Description= ' + rObj.desc + "\n"; - }else{ - wt += '|Description= ' + gM('mwe-missing_desc_see_source', rObj.link ) + "\n"; - } + //output search specific info + wt+='|Source=' + rObj.pSobj.getImportResourceDescWiki( rObj ) + "\n"; - //output search specific info - wt+='|Source=' + rObj.pSobj.getImportResourceDescWiki( rObj ) + "\n"; + if( rObj.author ) + wt+='|Author=' + rObj.author +"\n"; - if( rObj.author ) - wt+='|Author=' + rObj.author +"\n"; + if( rObj.date ) + wt+='|Date=' + rObj.date +"\n"; - if( rObj.date ) - wt+='|Date=' + rObj.date +"\n"; + //add the Permision info: + wt+='|Permission=' + rObj.pSobj.getPermissionWikiTag( rObj ) +"\n"; - //add the Permision info: - wt+='|Permission=' + rObj.pSobj.getPermissionWikiTag( rObj ) +"\n"; + if( rObj.other_versions ) + wt+='|other_versions=' + rObj.other_versions + "\n"; - if( rObj.other_versions ) - wt+='|other_versions=' + rObj.other_versions + "\n"; + wt+='}}'; - wt+='}}'; + //get any extra categories or helpful links + wt+= rObj.pSobj.getExtraResourceDescWiki( rObj ); - //get any extra categories or helpful links - wt+= rObj.pSobj.getExtraResourceDescWiki( rObj ); + $j('#rsd_resource_import').remove();//remove any old resource imports - $j('#rsd_resource_import').remove();//remove any old resource imports + //@@ show user dialog to import the resource + $j( _this.target_container ).append('
' + + '

Resource: ' + rObj.title + ' needs to be imported

'+ + '
' + + rObj.pSobj.getEmbedHTML( rObj, {'id': _this.target_container + '_rsd_pv_vid', 'max_height':'200','only_poster':true} )+ //get embedHTML with small thumb: + '
'+ + ''+gM('mwe-resource_page_desc') +''+ + '
'+ + mv_get_loading_img('position:absolute;top:5px;left:5px') + + '
'+ + '
'+ + '
'+ + '' + gM('mwe-local_resource_title') + '
'+ + '
'+ + '' + gM('mwe-edit_resource_desc') + '' + + '
' + + '' + + '


' + - //@@ show user dialog to import the resource - $j( _this.target_container ).append('
' + - '

Resource: ' + rObj.title + ' needs to be imported

'+ - '
' + - rObj.pSobj.getEmbedHTML( rObj, {'id': _this.target_container + '_rsd_pv_vid', 'max_height':'200','only_poster':true} )+ //get embedHTML with small thumb: - '
'+ - ''+gM('mwe-resource_page_desc') +''+ - '
'+ - mv_get_loading_img('position:absolute;top:5px;left:5px') + - '
'+ - '
'+ - '
'+ - '' + gM('mwe-local_resource_title') + '
'+ - '
'+ - '' + gM('mwe-edit_resource_desc') + '' + - '
' + - '' + - '


' + - - $j.btnHtml(gM('mwe-do_import_resource'), 'rsd_import_doimport', 'check' ) + ' ' + - - $j.btnHtml(gM('mwe-update_preview'), 'rsd_import_apreview', 'refresh' ) + '
' + - - $j.btnHtml(gM('mwe-cancel_import'), 'rsd_import_acancel', 'close' ) + ' ' + - - '
'+ - //output the rendered and non-renderd version of description for easy swiching: - '
'); - //add hover: - //update video tag - rewrite_by_id(_this.target_container + '_rsd_pv_vid'); - //load the preview text: - _this.getParsedWikiText( wt, _this.cFileNS +':'+ rObj.target_resource_title, function( o ){ - $j('#rsd_import_desc').html(o); - }); - //add bindings: - $j( _this.target_container + ' .rsd_import_apreview').btnBind().click(function(){ - /*$j('#rsd_import_desc').show().html( - mv_get_loading_img() - );*/ - //load the preview text: - _this.getParsedWikiText( $j('#rsd_import_ta').val(), _this.cFileNS +':'+ rObj.target_resource_title, function( o ){ - js_log('got updated preivew: '); - $j('#rsd_import_desc').html(o); - }); - }); - $j(_this.target_container + ' .rsd_import_doimport').btnBind().click(function(){ - //check import mode: - if( _this.import_url_mode=='api'){ - _this.doImportAPI( rObj , cir_callback); - }else{ - js_log("Error: import mode is not form or API (can not copy asset)"); - } - }); - $j( _this.target_container + ' .rsd_import_acancel').btnBind().click(function(){ - $j('#rsd_resource_import').fadeOut("fast",function(){ - $j(this).remove(); - }); - }); - } + $j.btnHtml(gM('mwe-do_import_resource'), 'rsd_import_doimport', 'check' ) + ' ' + + + $j.btnHtml(gM('mwe-update_preview'), 'rsd_import_apreview', 'refresh' ) + '
' + + + $j.btnHtml(gM('mwe-cancel_import'), 'rsd_import_acancel', 'close' ) + ' ' + + + '
'+ + //output the rendered and non-renderd version of description for easy swiching: + '
'); + //add hover: + //update video tag + rewrite_by_id(_this.target_container + '_rsd_pv_vid'); + //load the preview text: + _this.getParsedWikiText( wt, _this.cFileNS +':'+ rObj.target_resource_title, function( o ){ + $j('#rsd_import_desc').html(o); + }); + //add bindings: + $j( _this.target_container + ' .rsd_import_apreview').btnBind().click(function(){ + /*$j('#rsd_import_desc').show().html( + mv_get_loading_img() + );*/ + //load the preview text: + _this.getParsedWikiText( $j('#rsd_import_ta').val(), _this.cFileNS +':'+ rObj.target_resource_title, function( o ){ + js_log('got updated preivew: '); + $j('#rsd_import_desc').html(o); }); - } - }, - checkForFile:function( fName, callback){ + }); + $j(_this.target_container + ' .rsd_import_doimport').btnBind().click(function(){ + //check import mode: + if( _this.import_url_mode=='api'){ + _this.doImportAPI( rObj , cir_callback); + }else{ + js_log("Error: import mode is not form or API (can not copy asset)"); + } + }); + $j( _this.target_container + ' .rsd_import_acancel').btnBind().click(function(){ + $j('#rsd_resource_import').fadeOut("fast",function(){ + $j(this).remove(); + }); + }); + }, + checkForFile:function( fName, callback){ + var _this = this; reqObj={ 'action':'query', 'titles': _this.cFileNS + ':' + fName, @@ -1395,13 +1400,12 @@ remoteSearchDriver.prototype = { 'data':reqObj, 'url':this.local_wiki_api_url },function(data){ - var found_title = false; + var found_title = false; for(var i in data.query.pages){ - js_log('found title: ' + i + ':' + data.query.pages[i]['title']); - found_title=data.query.pages[i]['title']; + js_log('found title: ' + i + ':' + data.query.pages[i]['title']); + found_title = data.query.pages[i]['title']; } - if( found_title ){ - js_log("checkForFile found title:" + found_title); + if( found_title ){ callback( data.query.pages[i] ); }else{ callback( false ); diff --git a/js2/mwEmbed/mv_embed.js b/js2/mwEmbed/mv_embed.js index 935b431416..da06905ada 100644 --- a/js2/mwEmbed/mv_embed.js +++ b/js2/mwEmbed/mv_embed.js @@ -645,7 +645,8 @@ function mvGetClassPath(k){ //js_log('got class path:' + k + ' : '+ mvClassPaths[k]); return mvAutoLoadClasses[k]; } else { - return js_error('could not find path for requested class ' + k ); + js_log('Error:: Could not find path for requested class ' + k ); + return false; } } if( typeof mvCssPaths == 'undefined' ) @@ -870,10 +871,11 @@ var mvJsLoader = { } if( this.checkLoading() ) { //@@todo we should check the