* updates for strict compliance mode chunk uploading
authorMichael Dale <dale@users.mediawiki.org>
Sat, 25 Jul 2009 03:25:01 +0000 (03:25 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Sat, 25 Jul 2009 03:25:01 +0000 (03:25 +0000)
* fixes for firefogg multiple forms on the special upload page.

includes/api/ApiFormatJson_json.php
includes/upload/UploadFromChunks.php
js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
js2/mwEmbed/libAddMedia/mvFirefogg.js
js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js
js2/mwEmbed/mv_embed.js
js2/uploadPage.js
skins/common/wikibits.js

index f86ec03..4ec76e6 100644 (file)
@@ -816,7 +816,8 @@ class Services_JSON
        function isError($data, $code = null)
        {
                if (class_exists('pear')) {
-                       return PEAR::isError($data, $code);
+                       //avoid some strict warnings on PEAR isError check (looks like http://pear.php.net/bugs/bug.php?id=9950 has been around for some time)
+                       return @PEAR::isError($data, $code);
                } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
                                is_subclass_of($data, 'services_json_error'))) {
                        return true;
index 5e67fe4..5d70716 100644 (file)
@@ -71,7 +71,7 @@ class UploadFromChunks extends UploadBase {
         * Verify whether the upload is sane.
         * Returns self::OK or else an array with error information
         */
-       function verifyUpload( $resultDetails ) {
+       function verifyUpload() {
                // no checks on chunk upload mode:
                if( $this->chunk_mode ==  UploadFromChunks::INIT )
                        return self::OK;
@@ -79,7 +79,7 @@ class UploadFromChunks extends UploadBase {
                // verify on init and last chunk request
                if(     $this->chunk_mode == UploadFromChunks::CHUNK ||
                        $this->chunk_mode == UploadFromChunks::DONE )
-                       return parent::verifyUpload( $resultDetails );
+                       return parent::verifyUpload();
        }
 
        // only run verifyFile on completed uploaded chunks
@@ -114,6 +114,7 @@ class UploadFromChunks extends UploadBase {
                        'mComment'                      => $comment,
                    'mSummary'                  => $summary,
                        'mWatch'                        => $watch,
+                       'mIgnorewarnings'       => true, //ignore warning on chunk uploads (for now)
                        'mFilteredName'         => $this->mFilteredName,
                        'mTempAppendPath'       => null, // the repo append path (not temporary local node mTempPath)
                        'mDesiredDestName'      => $this->mDesiredDestName,
@@ -230,7 +231,7 @@ class UploadFromChunks extends UploadBase {
                        if( is_file( $this->getRealPath( $this->mTempAppendPath ) ) ){
                                $status = $this->appendToUploadFile( $this->mTempAppendPath, $this->mTempPath );
                        } else {
-                               $status->fatal( 'filenotfound', $this->mTempAppendPath );
+                               $status = Status::newFatal( 'filenotfound', $this->mTempAppendPath );
                        }
                        return $status;
                }
index 01444ba..2b2384f 100644 (file)
@@ -45,9 +45,11 @@ var default_bui_options = {
        'parent_uploader':null,
        'edit_from':null,
        'done_upload_cb': null,
+       'target_edit_from':null,
        
        //upload_mode can be 'post', 'chunks' or autodetect. (autodetect issues an api call)
        'upload_mode':'autodetect'
+       
 }
 var mvBaseUploadInterface = function( iObj ){
        return this.init( iObj );
@@ -63,7 +65,7 @@ mvBaseUploadInterface.prototype = {
        etoken:false,
        init: function( iObj ){
                if(!iObj)
-                       iObj = {};
+                       iObj = {};              
                //inherit iObj properties:
                for(var i in default_bui_options){
                        if(iObj[i]){
@@ -74,22 +76,22 @@ mvBaseUploadInterface.prototype = {
                }               
        },
        setupForm:function(){   
-               var _this = this;
+               var _this = this;               
                //set up the local pointer to the edit form:
-               _this.editForm = _this.getEditForm();
-
-               if(_this.editForm){
+               _this.editForm = _this.getEditForm();           
+               
+               if( _this.editForm ){
                        //set up the org_onsubmit if not set: 
-                       if( typeof( _this.org_onsubmit ) == 'undefined' )
-                               _this.org_onsubmit = _this.editForm.onsubmit;
+                       if( typeof( _this.org_onsubmit ) == 'undefined' &&  _this.editForm.onsubmit )
+                               _this.org_onsubmit = _this.editForm.onsubmit;                                   
                        
                        //have to define the onsubmit function inline or its hard to pass the "_this" instance
-                       _this.editForm.onsubmit = function(){                                                                   
+                       $j( '#mw-upload-form' ).submit( function(){             
                                //run the original onsubmit (if not run yet set flag to avoid excessive chaining ) 
-                               if( typeof( _this.org_onsubmit ) == 'function' ){                                                                                 
+                               if( typeof( _this.org_onsubmit ) == 'function' ){                                                                 
                                        if( ! _this.org_onsubmit() ){
                                                //error in org submit return false;
-                                               return false;                                   
+                                               return false;
                                        }
                                }                               
                                //check for post action override:                                                                                                                       
@@ -119,7 +121,7 @@ mvBaseUploadInterface.prototype = {
                                 
                                //don't submit the form we will do the post in ajax
                                return false;   
-                       };                                                      
+                       });                                                                     
                }
                                        
        },      
@@ -524,9 +526,9 @@ mvBaseUploadInterface.prototype = {
        getProgressTitle:function(){
                return gM('upload-in-progress');
        },      
-       getEditForm:function(){
-               if(this.target_edit_from){
-                       return $j(this.target_edit_from).get(0);
+       getEditForm:function(){         
+               if( this.target_edit_from && $j( this.target_edit_from ).length != 0){                  
+                       return $j( this.target_edit_from ).get(0);
                }
                //just return the first form fond on the page. 
                return $j('form :first').get(0);
index 2c56d9b..b8b10c3 100644 (file)
@@ -196,19 +196,19 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                                        _this.selectFogg();
                                });                             
                    //also setup the text file display on Click to select file:  
-                   $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){                     
+                   $j( this.target_input_file_name ).unbind().attr('readonly', 'readonly').click(function(){                   
                        _this.selectFogg();
                    })          
                        
                }else{
                        //first check firefox version:           
-                       if(!($j.browser.mozilla && $j.browser.version >= '1.9.1')) {
-                               js_log('show use latest::' + _this.target_use_latest_fox);
-                               if(_this.target_use_latest_fox){
-                                       if(_this.form_rewrite)
-                                               $j(_this.target_use_latest_fox).prepend( gM('fogg-for_improved_uplods') );
+                       if(!( $j.browser.mozilla && $j.browser.version >= '1.9.1' )) {
+                               js_log( 'show use latest::' + _this.target_use_latest_fox );
+                               if( _this.target_use_latest_fox ){
+                                       if( _this.form_rewrite )
+                                               $j( _this.target_use_latest_fox ).prepend( gM('fogg-for_improved_uplods') );
                                                         
-                                       $j(_this.target_use_latest_fox).show();
+                                       $j( _this.target_use_latest_fox ).show();
                                }
                                return ;
                        }
@@ -224,7 +224,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                        }                                                                                       
                        //if rewriting form use upload msg text
                        var upMsg = (_this.form_rewrite) ? gM('fogg-for_improved_uplods') : '';                 
-                       $j(_this.target_please_install).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show();                        
+                       $j( _this.target_please_install ).html( upMsg + gM('fogg-please_install',os_link )).css('padding', '10px').show();                      
                }
                //setup the target save local file bindins: 
                $j( _this.target_btn_save_local_file ).unbind().click(function(){
@@ -243,7 +243,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
        //assume input target
        setupForm: function(){          
                js_log('firefogg::setupForm::');
-               //to parent form setup if we want http updates 
+               //to parent form setup if we want http updates          
                if( this.form_rewrite ){
                        //do parent form setup: 
                        this.pe_setupForm();            
@@ -279,7 +279,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                inTag+= '/><span id="' + $j(this.selector).attr('name') + '_fogg-control"></span>';
                                                                                
                js_log('set input: ' + inTag);
-               $j(this.selector).replaceWith(inTag);                   
+               $j( this.selector ).replaceWith( inTag );                       
                
                this.target_input_file_name = 'input[name=' + $j(this.selector).attr('name') + ']';
                //update the selector to the control target: 
@@ -292,6 +292,9 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                this.doControlBindings();
        },
        getEditForm:function(){
+               if( this.target_edit_from ){
+                       return this.pe_getEditForm();
+               }
                js_log('get form: action=' + $j(this.selector).parents().find("form").attr('action'));
                return $j(this.selector).parents().find("form").get(0);
        },   
@@ -413,12 +416,12 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
        },      
        doUploadSwitch:function(){                              
                var _this = this;
-               js_log("firefogg: doUploadSwitch:: " + this.fogg_enabled);
+               js_log( "firefogg: doUploadSwitch:: " + this.fogg_enabled );
                //make sure firefogg is enabled otherwise do parent UploadSwich:                
                if( !this.fogg_enabled || !this.firefogg_form_action )
                        return _this.pe_doUploadSwitch();
                
-               //check what mode to use firefogg in: 
+               //check what mode to use firefogg in:
                if( _this.upload_mode == 'post' ){
                        _this.doEncode();
                }else if( _this.upload_mode == 'api' && _this.chunks_supported){ //if api mode and chunks supported do chunkUpload
@@ -428,7 +431,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                }               
        },
        //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready
-       doChunkUpload : function(){
+       doChunkUpload : function(){             
                var _this = this;                       
                _this.action_done = false;                      
                
@@ -455,17 +458,18 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                        'comment'       : _this.formData['wpUploadDescription'],
                        'enablechunks': true
                };
+               
                //check for editToken:
-               if(!this.etoken)
+               if( !this.etoken )
                        this.etoken = _this.formData['wpEditToken'];
                        
-               if(this.etoken)
+               if( this.etoken )
                        aReq['token'] = this.etoken;
                
                if( _this.formData['wpWatchthis'] )
                        aReq['watch'] =  _this.formData['wpWatchthis'];
                
-               if(  _this.formData['wpIgnoreWarning'] )
+               if( _this.formData['wpIgnoreWarning'] )
                        aReq['ignorewarnings'] = _this.formData['wpIgnoreWarning'];
                
                js_log('do fogg upload/encode call: '+ _this.api_url + ' :: ' + JSON.stringify( aReq ) );                       
@@ -477,6 +481,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
        },
        //doEncode and monitor progress:
        doEncode : function(){  
+               js_log('firefogg:doEncode');
                var _this = this;
                _this.action_done = false;
                _this.dispProgressOverlay();                            
@@ -597,7 +602,7 @@ mvFirefogg.prototype = { //extends mvBaseUploadInterface
                                                   _this.updateProgressWin( gM('successfulupload'),  gM( 'mv_upload_done', _this.fogg.resultUrl),buttons);      
                                           }else{
                                                   //done state with error? ..not really possible given how firefogg works
-                                                  js_log(" upload done, in chunks mode, but no resultUrl!");
+                                                  js_log(" upload done, in chunks mode, but no resultUrl::" + response_text);                                             
                                           }                                                                                                                                                                                                               
                                   }                                                                                                    
                        }else{  
index 610fd41..6781e02 100644 (file)
@@ -92,7 +92,7 @@ baseRemoteSearch.prototype = {
                                                attr_name = attr_name.split('|');       
                                }
                                                                                                                                                                                                                
-                               $j.each(item.getElementsByTagName( tag_name ), function (inx, node){                                                    
+                               $j.each( item.getElementsByTagName( tag_name ), function ( inx, node ){                                                 
                                        var tag_val = '';                                                                                                
                                        if( node!=null && attr_name == null ){                                  
                                                if( node.childNodes[0] != null){                                                                        
@@ -101,11 +101,11 @@ baseRemoteSearch.prototype = {
                                                }
                                        }                               
                                        if( node!=null && attr_name != null){
-                                               if(typeof attr_name == 'string'){ 
+                                               if( typeof attr_name == 'string' ){ 
                                                        tag_val = $j.trim( $j( node ).attr( attr_name ) );
                                                }else{
                                                        var attr_vals = {};
-                                                       for(var j in attr_name){
+                                                       for( var j in attr_name ){
                                                                if( $j(node).attr( attr_name[j] ).length != 0)
                                                                        attr_vals[ attr_name[j] ] = $j.trim( $j(node).attr( attr_name[j]) ).replace(/(<([^>]+)>)/ig,"");
                                                        }
index 090ec02..4cec244 100644 (file)
@@ -20,7 +20,7 @@ if( MV_EMBED_VERSION ){
        MV_DO_INIT=false;       
 }
 //used to grab fresh copies of scripts. (should be changed on commit)  
-var MV_EMBED_VERSION = '1.0r17';
+var MV_EMBED_VERSION = '1.0r18';
 
 /*
  * Configuration variables (can be set from some precceding script) 
index ea53282..101885f 100644 (file)
@@ -5,6 +5,7 @@
 js2AddOnloadHook( function(){
        mwUploadHelper.init();          
 });
+var mwUploadFormTarget = '#mw-upload-form';
 //set up the upoload form bindings once all dom manipluation is done
 var mwUploadHelper = {
        firefogg_installed:false,
@@ -19,13 +20,14 @@ var mwUploadHelper = {
                        $j('#wpUploadFile').firefogg({ 
                                //an api url (we won't submit directly to action of the form)
                                'api_url' : wgServer + wgScriptPath + '/api.php',
-                               'form_rewrite': true,                           
+                               'form_rewrite': true,   
+                               'target_edit_from' : mwUploadFormTarget,                        
                                'new_source_cb' : function( orgFilename, oggName ){                                             
                                        if($j('#wpDestFile').val() == "")
                                                    $j('#wpDestFile').val( oggName );
                                                mwUploadHelper.doDestCheck();
                                },
-                               'detect_cb':function(fogg_installed){
+                               'detect_cb':function( fogg_installed ){
                                        if(fogg_installed){
                                                _this.firefogg_installed=true;
                                        }else{
@@ -39,7 +41,7 @@ var mwUploadHelper = {
                        if($j('#wpUploadFileURL').length != 0){
                                $j('#wpUploadFileURL').baseUploadInterface({ 
                                        'api_url'   : wgServer + wgScriptPath + '/api.php',
-                                       'target_edit_from' : '#mw-upload-form' 
+                                       'target_edit_from' : mwUploadFormTarget
                                });                             
                        }
                }
index 75a281a..f32b14a 100644 (file)
@@ -36,7 +36,7 @@ if (!window.onloadFuncts) {
        var onloadFuncts = [];
 }      
        
-//should use mwAddOnloadHook once js2 is enabled
+//code that is dependent on js2 functions should use js2AddOnloadHook
 function addOnloadHook(hookFunct) {    
        // Allows add-on scripts to add onload functions
        if(!doneOnloadHook) {
@@ -46,6 +46,7 @@ function addOnloadHook(hookFunct) {
        }
 }
 
+
 function hookEvent(hookName, hookFunct) {
        addHandler(window, hookName, hookFunct);
 }