* js2 upload fixes (don't display preview on http uploads)
authorMichael Dale <dale@users.mediawiki.org>
Thu, 8 Oct 2009 22:48:56 +0000 (22:48 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Thu, 8 Oct 2009 22:48:56 +0000 (22:48 +0000)
js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
js2/mwEmbed/libAddMedia/mvFirefogg.js
js2/mwEmbed/libAddMedia/remoteSearchDriver.js
js2/mwEmbed/mv_embed.js

index fe22e5a..8b37466 100644 (file)
@@ -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(
-                               '<input type="hidden" name="wpUpload" value="' + $j('input[name=\'wpUpload\']').val() + '"/>'
-                       );
-                       //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'),  '<h3>' + gM('mwe-uploadwarning') + '</h3>' +wmsg + '<p>',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;
        }
 };
 
index db44289..c0875c9 100644 (file)
@@ -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(         
                        '<div style="clear:both;height:3em"/>'+                                                 
                        $j.btnHtml(gM('fogg-preview'), 'fogg_preview', 'triangle-1-e') + 
index 6e8370f..37bfe8d 100644 (file)
@@ -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('<div id="rsd_resource_import" '+
+               'class="ui-state-highlight ui-widget-content ui-state-error" ' +
+               'style="position:absolute;top:50px;left:50px;right:50px;bottom:50px;z-index:5">' +
+                       '<h3 style="color:red">Resource: <span style="color:black">' + rObj.title + '</span> needs to be imported</h3>'+
+                               '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:0px;overflow:auto;top:30px;">' +
+                                       rObj.pSobj.getEmbedHTML( rObj, {'id': _this.target_container + '_rsd_pv_vid', 'max_height':'200','only_poster':true} )+ //get embedHTML with small thumb:
+                                       '<br style="clear both">'+
+                                       '<strong>'+gM('mwe-resource_page_desc') +'</strong>'+
+                                       '<div id="rsd_import_desc" syle="display:inline;">'+
+                                               mv_get_loading_img('position:absolute;top:5px;left:5px') +
+                                       '</div>'+
+                               '</div>'+
+                               '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
+                                       'bottom:0px;top:30px;right:0px;overflow:auto;">'+
+                                       '<strong>' + gM('mwe-local_resource_title') + '</strong><br>'+
+                                       '<input type="text" size="30" value="' + rObj.target_resource_title + '" readonly="true"><br>'+
+                                       '<strong>' + gM('mwe-edit_resource_desc') + '</strong>' +
+                                       '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' +
+                                               wt +
+                                       '</textarea><br>' +
+                                       '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7"/>' +
+                                       '<label for="wpWatchthis">'+gM('mwe-watch_this_page')+'</label><br><br><br>' +
 
-                                       //@@ show user dialog to import the resource
-                                       $j( _this.target_container ).append('<div id="rsd_resource_import" '+
-                                       'class="ui-state-highlight ui-widget-content ui-state-error" ' +
-                                       'style="position:absolute;top:50px;left:50px;right:50px;bottom:50px;z-index:5">' +
-                                               '<h3 style="color:red">Resource: <span style="color:black">' + rObj.title + '</span> needs to be imported</h3>'+
-                                                       '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:0px;overflow:auto;top:30px;">' +
-                                                               rObj.pSobj.getEmbedHTML( rObj, {'id': _this.target_container + '_rsd_pv_vid', 'max_height':'200','only_poster':true} )+ //get embedHTML with small thumb:
-                                                               '<br style="clear both">'+
-                                                               '<strong>'+gM('mwe-resource_page_desc') +'</strong>'+
-                                                               '<div id="rsd_import_desc" syle="display:inline;">'+
-                                                                       mv_get_loading_img('position:absolute;top:5px;left:5px') +
-                                                               '</div>'+
-                                                       '</div>'+
-                                                       '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
-                                                               'bottom:0px;top:30px;right:0px;overflow:auto;">'+
-                                                               '<strong>' + gM('mwe-local_resource_title') + '</strong><br>'+
-                                                               '<input type="text" size="30" value="' + rObj.target_resource_title + '" readonly="true"><br>'+
-                                                               '<strong>' + gM('mwe-edit_resource_desc') + '</strong>' +
-                                                               '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' +
-                                                                       wt +
-                                                               '</textarea><br>' +
-                                                               '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7"/>' +
-                                                               '<label for="wpWatchthis">'+gM('mwe-watch_this_page')+'</label><br><br><br>' +
-
-                                                               $j.btnHtml(gM('mwe-do_import_resource'), 'rsd_import_doimport', 'check' ) + ' ' +
-
-                                                               $j.btnHtml(gM('mwe-update_preview'), 'rsd_import_apreview', 'refresh' ) + '<div style="clear:both;height:20px;"/>' +
-
-                                                               $j.btnHtml(gM('mwe-cancel_import'), 'rsd_import_acancel', 'close' ) + ' ' +
-
-                                                       '</div>'+
-                                                       //output the rendered and non-renderd version of description for easy swiching:
-                                       '</div>');
-                                       //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' ) + '<div style="clear:both;height:20px;"/>' +
+
+                                       $j.btnHtml(gM('mwe-cancel_import'), 'rsd_import_acancel', 'close' ) + ' ' +
+
+                               '</div>'+
+                               //output the rendered and non-renderd version of description for easy swiching:
+               '</div>');
+               //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 );
index 935b431..da06905 100644 (file)
@@ -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 <script> Element .onLoad property to 
-                       //make sure its just not a very slow connection
+                       //make sure its just not a very slow connection or we can run the callback 
+                       //(even though the class is not loaded) 
                         
                        if( this.load_time++ > 4000 ){ // Time out after ~80 seconds
-                               js_error( gM('mwe-error_load_lib', [mvGetClassPath(this.missing_path),  this.missing_path]) );
+                               js_log( gM('mwe-error_load_lib', [mvGetClassPath(this.missing_path),  this.missing_path]) );
                                this.load_error = true;
                        } else {
                                setTimeout( 'mvJsLoader.doLoad()', 20 );