* some updates to the api_proxy examples and code
authorMichael Dale <dale@users.mediawiki.org>
Sun, 18 Oct 2009 21:03:24 +0000 (21:03 +0000)
committerMichael Dale <dale@users.mediawiki.org>
Sun, 18 Oct 2009 21:03:24 +0000 (21:03 +0000)
* display:none on iframe for ~background~ requests
* append to page example added to testApiProxy.html
* We could make some optimization by thinning out the MediaWiki:ApiProxy page by replacing it with a simple page without styles & extra js
* added a iframe status callback for quicker timeouts

js2/apiProxyPage.js
js2/editPage.js
js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
js2/mwEmbed/libAddMedia/remoteSearchDriver.js
js2/mwEmbed/libMwApi/mw.proxy.js
js2/mwEmbed/mv_embed.js
js2/mwEmbed/tests/testApiProxy.html
js2/remoteMwEmbed.js
js2/uploadPage.js

index 46ff0fe..0619e4a 100644 (file)
@@ -7,7 +7,6 @@
 /*
  * since this is proxy server set a pre-append debug flag to know which debug msgs are coming from where
  */
-
 if( !mwApiProxyConfig )
        var mwApiProxyConfig = {};
 
@@ -18,10 +17,8 @@ var mwApiProxyDefaultConfig = {
                'master_blacklist'      : []                                    
 };
 //user_white_list should also be checked and configured at runtime.
-
 js2AddOnloadHook( function() {                         
        //build our configuration from the default and mwApiProxyConfig vars
-       mwApiProxyConfig = $j.extend(true, mwApiProxyDefaultConfig,  mwApiProxyConfig);
-       
+       mwApiProxyConfig = $j.extend(true, mwApiProxyDefaultConfig,  mwApiProxyConfig); 
        $j.apiProxy( 'server', mwApiProxyConfig );      
 });
index 7775dc0..ca393d6 100644 (file)
@@ -20,13 +20,14 @@ var defaultAddMediaConfig = {
                'local_wiki_api_url': wgServer + wgScriptPath + '/api.php'
 };
 
-
 js2AddOnloadHook( function() {
        var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
        // kind of tricky, it would be nice to use run on ready "loader" call here
+       var didWikiEditorBind = false;
        if( typeof $j.wikiEditor != 'undefined' ) {
                        $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
                    function( e, section ) {
+                       didWikiEditorBind = true;
                        if ( typeof section.groups.insert.tools.file !== 'undefined' ) {
                            section.groups.insert.tools.file.action = {
                                'type': 'callback',
@@ -47,6 +48,10 @@ js2AddOnloadHook( function() {
                        $j( '#btn-add-media-wiz' ).addMediaWiz(
                                amwConf
                        );
+               }else{
+                       //make sure the wikieditor got binded: 
+                       if( !didWikiEditorBind )
+                               $j(".tool [rel='file']").addMediaWiz( amwConf );
                }
-       },100)
+       }, 120)
 });
index 3417e3d..f7a89d7 100644 (file)
@@ -252,15 +252,9 @@ mvBaseUploadInterface.prototype = {
                            'url'               : $j('#wpUploadFileURL').val(),
                            'filename'  : $j('#wpDestFile').val(),
                            'comment'   : $j('#wpUploadDescription').val(),
-                               'watch'         : ($j('#wpWatchthis').is(':checked'))?'true':'false'
-                       }
-                       //set up ignore warnings and watch arguments:
-                       if( $j('#wpIgnoreWarning').is(':checked') ){
-                               httpUpConf[ 'ignorewarnings'] =  'true';
-                       }
-                       if( $j('#wpWatchthis').is(':checked') ){
-                               httpUpConf[ 'watch'] =  'true';
-                       }
+                               'watch'         : ($j('#wpWatchthis').is(':checked'))?'true':'false',
+                               'ignorewarnings': ($j('#wpIgnoreWarning').is(':checked'))?'true':'false'
+                       }                       
                        //check for editToken
                        _this.etoken = $j("#wpEditToken").val();
                        _this.doHttpUpload( httpUpConf );
@@ -316,9 +310,7 @@ mvBaseUploadInterface.prototype = {
                        'asyncdownload' : true  //do async download
                };
                //set config from options:
-               for(var i in opt){
-                       req[i]= opt[i];
-               }
+               $j.extend(req, opt);
 
                //else try and get a token:
                if(!_this.etoken  && _this.api_url){
index 7e1f588..49a3fe9 100644 (file)
@@ -412,7 +412,7 @@ remoteSearchDriver.prototype = {
                        }
                }               
                //set the upload target name if unset
-               if( _this.upload_api_target == 'local' &&  ! _this.upload_api_name && wgSiteName)
+               if( _this.upload_api_target == 'local' &&  ! _this.upload_api_name && typeof wgSiteName != 'undefined')
                        _this.upload_api_name =  wgSiteName;
                
                
@@ -737,7 +737,7 @@ remoteSearchDriver.prototype = {
                }
        },
        //issue a api request & cache the result
-       //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none'
+       //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none'
        checkForCopyURLSupport:function ( callback ){
                var _this = this;
                js_log('checkForCopyURLSupport:: ');
@@ -961,7 +961,7 @@ remoteSearchDriver.prototype = {
                        'data':reqObj,
                        'url':this.local_wiki_api_url
                        }, function(data){
-                               //@@todo propogate the rObj
+                               //@@todo propagate the rObj
                                var rObj = {};
                        }
                );
@@ -1240,7 +1240,7 @@ remoteSearchDriver.prototype = {
                        })
 
        },
-       /*set-up the control actions for clipEdit with relevent callbacks */
+       /*set-up the control actions for clipEdit with relevant callbacks */
        getClipEditControlActions:function( cp ){
                var _this = this;
                var cConf= {};
@@ -1494,7 +1494,7 @@ remoteSearchDriver.prototype = {
                        js_log("do preview asset");                     
                        //load the preview text:
                        _this.getParsedWikiText( $j('#rsd_import_ta').val(), _this.cFileNS +':'+ rObj.target_resource_title, function( o ){
-                               js_log('got updated preivew: ');
+                               js_log('got updated preview: ');
                                $j('#rsd_import_desc').html(o);
                        });
                });
@@ -1540,7 +1540,7 @@ remoteSearchDriver.prototype = {
                                {
                                        'server_frame' : _this.upload_api_proxy_frame,                                  
                                },function(){
-                                       //now that the api is setup call actual import
+                                       //now that the api loaded call actual import
                                        debugger;
                                }                       
                        );      
index 86f673e..a71ae49 100644 (file)
 */
 
 loadGM({
-       "mwe-setting-up-proxy": "Setting up proxy" 
+       "mwe-setting-up-proxy" : "Setting up proxy",
+       "mwe-re-try" : "Retry Api request", 
+       "mwe-re-trying": "Retrying api request",        
+       "mwe-cancel" : "Cancel",
+       "mwe-proxy-not-ready": "Proxy is not configured",
+       "mwe-please-login" : "Please <a target=\"_new\" href=\"$1\">loggin</a> and or enable mwEmbed and retry the request",
+       "mwe-remember-loging": "As a genneral sequirty reminder. Only login to web sites when your address bar displayes that sites address" 
 });
 
 (function( $ ) {
@@ -47,11 +53,9 @@ loadGM({
        $.proxy = {};
        
        /**
-        * The clientApiProxy handles a request to external server
-        * 
-        * This is (Domain A) in the above described setup
+        * The client setup function: 
         */
-       $.proxy.client = function( pConf, callback ){
+       $.proxy.client = function( pConf, conf ){
                var _this = this;
                //do setup: 
                if( pConf.server_frame )                
@@ -59,20 +63,15 @@ loadGM({
                
                if( pConf.client_frame_path )
                        $.proxy.client_frame_path = pConf.client_frame_path;
-               
-               //setup a dialog to manage proxy setup:
-               $j.addLoaderDialog( gM('mwe-setting-up-proxy') );
-                       
+                               
                if( parseUri( $.proxy.server_frame).host ==  parseUri( document.URL ).host ){
-                       js_log("Error: why are you trying to proxy yourself? " );
-                       return false;                           
-               }                                               
-               //add an iframe to domain B with request for proxy just do the setup
-               $.proxy.doFrameProxy( { 'init' : 'echo' } );
-                       
-               //if we have a setup callback 
-               $.proxy.callback =      callback;
+                       js_log("Error: why are you trying to proxy yourself? " );       
+                       return false;                                   
+               }               
+               return true;
        }
+       //set the frameProxy Flag: 
+       var frameProxyOk = false;
        /* setup a iframe request hash */
        $.proxy.doFrameProxy = function( reqObj ){              
                var hashPack = {
@@ -85,15 +84,47 @@ loadGM({
                //we can't update src's so we have to remove and add all the time :(
                //@@todo we should support frame msg system 
                $j('#frame_proxy').remove();
-               $j('body').append('<iframe id="frame_proxy" name="frame_proxy" ' +
+               $j('body').append('<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' +
                                'src="' + $.proxy.server_frame +
                                 '#' + escape( JSON.stringify( hashPack ) ) + 
                                 '"></iframe>' );
+                                
+               //add an onLoad hook: 
+               $j('#frame_proxy').get(0).onload = function(){
+                       //add a 5 second timeout for setting up the nested child callback (after page load) 
+                       setTimeout(function(){
+                               if( !frameProxyOk ){
+                                       //we timmed out no api proxy (should make sure the user is "logged in")
+                                       //for now let the implementation call proxyNotReadyDialog       
+                                       $.proxy.callback ( false );
+                               }                               
+                       }, 5000);
+               }
        }
-       
+       $.proxy.proxyNotReadyDialog = function(){
+               var btn = {};
+               btn[ gM('mwe-re-try') ] = function(){
+                       $j.addLoaderDialog( gM('mwe-re-trying') );
+                       $.proxy.doFrameProxy( lastApiReq );
+               }
+               btn[ gM('mwe-cancel') ] = function(){
+                       $j.closeLoaderDialog();
+               }
+               var pUri =  parseUri( $.proxy.server_frame);
+               //this is sort of a temporary hack if we change the MediaWiki:ApiProxy key
+               //we will have to deal with that here as well: 
+               var login_url = pUri.protocol +'://'+ pUri.host + 
+                               pUri.path.replace( 'MediaWiki:ApiProxy', 'Special:UserLogin');
+               $j.addDialog( gM('mwe-proxy-not-ready'), gM('mwe-please-login', login_url ) + 
+                                               '<p style="font-size:small">' + gM('mwe-remember-loging') + '</p>', 
+                       btn
+               )       
+       }
+       var lastApiReq = {};
        /* the do_api_request with callback: */
        $.proxy.doRequest = function( reqObj, callback){
                js_log("doRequest:: " + JSON.stringify( reqObj ) );             
+               lastApiReq = reqObj;
                //setup the callback:
                $.proxy.callback = callback;
                //do the proxy req:
@@ -103,16 +134,18 @@ loadGM({
         * The nested iframe action that passes its msg back up to the top instance      
         */
        $.proxy.nested = function( hashResult ){
-               js_log( 'got $.proxy.nested callback!! :: ' + hashResult );
+               //js_log( '$.proxy.nested callback :: ' + hashResult );
+               frameProxyOk = true;
                //try to parse the hash result: 
                try{
                        var rObj = JSON.parse( unescape( hashResult ) );
                }catch (e) {
                        js_log("Error could not parse hashResult");
                }               
-               //hide the loader if the initial state = ready msg is fired: 
-               if( rObj && rObj.state == 'ready')
-                       $j.closeLoaderDialog();
+               //special callback to frameProxyOk flag (not an api result, don't call callback)   
+               if( rObj.state == 'ok')                 
+                       return ;                        
+               
                //if all good pass it to the callback:
                $.proxy.callback( rObj ); 
        }
@@ -149,7 +182,7 @@ loadGM({
                        return false;
                }
                        
-               var domain =  parseUri( document.URL ).host;
+               var domain =  aObj.cd;
                var nested_frame_src = 'http://' + aObj.cd + aObj.cfp;
                //check the master whitelist
                for(var i in pConf.master_whitelist){
@@ -174,30 +207,31 @@ loadGM({
                });*/
                
                //if still not found: 
-               js_log("domain " + domain + " not approved");           
+               js_log("domain " + domain + " not approved");
+               
+               //offer the user the ability to "approve" requested domain save to their user page              
                
                function doNestedProxy( reqObj ){               
                        js_log("doNestedProxy to: " + nested_frame_src);
-                       var outputhash = escape( JSON.stringify( reqObj ) );
-                       //check if its just a "echo" request (no need to hit the api)                   
-                       if( reqObj.init && reqObj.init == 'echo'){
-                               doNestedFrame( {'state': 'ready', "echo": true } );
-                       }else{                  
-                               //add some api stuff: 
-                               reqObj['format'] = 'json';                                                                                              
-                               //process the api request
-                               $j.get(wgScriptPath + '/api' + wgScriptExtension,
-                                       reqObj,
-                                       function( data ){                                       
-                                               js_log("Proxy GOT Res: " +  data );
-                                               //put it into the nested frame hash string: 
-                                               doNestedFrame( JSON.parse( data ) );
-                                       }
-                               );                              
-                       }                                       
+                       //output iframe prior to running api request 
+                       //(so we can fail faster / cache the nested page / simotaniusly load things) 
+                       doNestedFrame ( 'nested_ok' , {'state':'ok'});
+                       
+                       var outputhash = escape( JSON.stringify( reqObj ) );    
+                       //add some api stuff: 
+                       reqObj['format'] = 'json';                                                                                              
+                       //process the api request
+                       $j.post(wgScriptPath + '/api' + wgScriptExtension,
+                               reqObj,
+                               function( data ){                                       
+                                       //js_log("Proxy GOT Res: " +  data );
+                                       //put it into the nested frame hash string: 
+                                       doNestedFrame( 'nested_push', JSON.parse( data ) );
+                               }
+                       );                                              
                }
                //add the doNestedFrame iframe: 
-               function doNestedFrame( resultObj ){                    
+               function doNestedFrame( nestname, resultObj ){                  
                        $j('#nested_push').remove();
                        //setup the nested proxy that points back to top domain:                        
                        $j('body').append( '<iframe id="nested_push" name="nested_push" ' +
index 57aaf06..b73d79d 100644 (file)
@@ -972,7 +972,7 @@ var mvJsLoader = {
         * checks for jQuery and adds the $j noConflict var
         */
        jQueryCheck: function( callback ) {
-               //js_log( 'jQueryCheck::' );
+               js_log( 'jQueryCheck::' );
                // Skip stuff if $j is already loaded:
                if( _global['$j'] && callback )
                        callback();
@@ -1060,9 +1060,10 @@ var mvJsLoader = {
        // Check the jQuery flag. This way, when remote embedding, we don't load jQuery
        // unless js2AddOnloadHook was used or there is video on the page.
        runQueuedFunctions: function() {
-               var _this = this;
-               this.doneReadyEvents = true;
+               js_log("runQueuedFunctions");
+               var _this = this;               
                this.jQueryCheck( function() {
+                       this.doneReadyEvents = true;
                        _this.runReadyEvents();
                });
        },
@@ -1131,6 +1132,7 @@ function setSwappableToLoading( e ) {
 }
 //js2AddOnloadHook: ensure jQuery and the DOM are ready
 function js2AddOnloadHook( func ) {
+       js_log("js2AddOnloadHook::" + mvJsLoader.doneReadyEvents);
        // If we have already run the DOM-ready function, just run the function directly:
        if( mvJsLoader.doneReadyEvents ) {
                // Make sure jQuery is there:
@@ -1158,30 +1160,19 @@ function rewrite_by_id( vid_id, ready_callback ) {
 /*********** INITIALIZATION CODE *************
  * set DOM-ready callback to init_mv_embed
  *********************************************/
-// for Mozilla browsers
+// for Mozilla / modern browsers
 if ( document.addEventListener ) {
-       document.addEventListener( "DOMContentLoaded", function(){ mwdomReady() }, false );
-} else {
-       // Use the onload method instead when DOMContentLoaded does not exist
-       window.onload = function() { mwdomReady() };
+       document.addEventListener( "DOMContentLoaded", mwdomReady, false );
 }
-/*
- * Should deprecate and use jquery.ui.dialog instead
- */
-function mv_write_modal( content, speed ) {
-       $j( '#modalbox,#mv_overlay' ).remove();
-       $j( 'body' ).append(
-               '<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;' +
-               'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">' +
-               content +
-               '</div>' +
-               '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;' +
-               'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;' +
-               'opacity: 0.6;"/>');
-       $j( '#modalbox,#mv_overlay' ).show( speed );
+var temp_f;
+if( window.onload ) {
+    temp_f = window.onload;
 }
-function mv_remove_modal( speed ) {
-       $j( '#modalbox,#mv_overlay' ).remove( speed );
+// Use the onload method as a backup (mwdomReady hanndles dobule init calls)
+window.onload = function () {
+    if( temp_f )
+        temp_f();
+       mwdomReady();    
 }
 
 /*
@@ -1202,13 +1193,21 @@ function mv_jqueryBindings() {
                 * @param mode is either 'server' or 'client'
                 */                             
                $.apiProxy = function( mode, pConf, callback ){
-                       js_log('do apiProxy setup');
-                       $.addLoaderDialog( gM('mwe-apiproxy-setup') );
+                       js_log('do apiProxy setup');                    
                        mvJsLoader.doLoad( [
                                '$mw.proxy',
                                'JSON'
                        ], function(){                          
-                               $mw.proxy[mode]( pConf, callback );
+                               //do the proxy setup or 
+                               if( mode == 'client'){
+                                       //just do the setup (no callbcak for client setup) 
+                                       $mw.proxy.client( pConf );
+                                       if( callback )
+                                               callback();
+                               }else if( mode=='server' ){
+                                       //do the request with the callback
+                                       $mw.proxy.server( pConf , callback );
+                               }
                        });     
                }
                //non selector based add-media-wizard direct invocation with loader
@@ -1312,7 +1311,8 @@ function mv_jqueryBindings() {
                /*
                 * The Firefogg jQuery function:
                 * @@note This Firefogg invocation could be made to work more like real jQuery plugins
-                */
+                */             
+               var queuedFirefoggConf = {};
                $.fn.firefogg = function( iObj, callback ) {
                        if( !iObj )
                                iObj = {};
@@ -1325,8 +1325,9 @@ function mv_jqueryBindings() {
                        var sElm = $j( this.selector ).get( 0 );
                        if( sElm['firefogg'] ) {
                                if( sElm['firefogg'] == 'loading' ) {
-                                       js_log( "Error: called firefogg operations on Firefogg selector that is " +
-                                               "not done loading" );
+                                       js_log( "Queued firefogg operations ( firefogg " +
+                                               "not done loading ) " );
+                                       $j.extend( queuedFirefoggConf, iObj );
                                        return false;
                                }
                                // Update properties
@@ -1377,6 +1378,11 @@ function mv_jqueryBindings() {
                                                myFogg.doRewrite( callback );
                                                var selectorElement = $j( iObj.selector ).get( 0 );
                                                selectorElement['firefogg'] = myFogg;
+                                               
+                                               js_log('pre:'+ selectorElement['firefogg']['firefogg_form_action'])
+                                               if(queuedFirefoggConf)
+                                                       $j.extend(selectorElement['firefogg'], queuedFirefoggConf);
+                                               js_log('post:'+ selectorElement['firefogg']['firefogg_form_action'])
                                        }
                        });
                }
@@ -1458,7 +1464,7 @@ function mv_jqueryBindings() {
                $.addDialog = function ( title, msg_txt, btn ){
                        $('#mwe_tmp_loader').remove();
                        //append the style free loader ontop: 
-                       $('body').append('<div id="mwe_tmp_loader" title="' + title + '" >' +
+                       $('body').append('<div id="mwe_tmp_loader" style="display:none" title="' + title + '" >' +
                                        msg_txt +
                        '</div>');
                        //turn the loader into a real dialog loader: 
@@ -1473,9 +1479,9 @@ function mv_jqueryBindings() {
                                $('#mwe_tmp_loader').dialog({
                                        bgiframe: true,
                                        draggable: false,
-                                       resizable: false,
-                                       height: 140,
+                                       resizable: false,                                       
                                        modal: true,
+                                       width:400,
                                        buttons: btn
                                });
                        });
@@ -1625,9 +1631,13 @@ function do_api_req( options, callback ) {
        if( !options.data['action'] )
                options.data['action'] = 'query';
 
-       // js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );
-       // Build request string
-       if( parseUri( document.URL ).host == parseUri( options.url ).host ) {
+       // js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );     
+       if( options.url == 'proxy' && $mw.proxy){
+               //assume the proxy is already "setup" since $mw.proxy is defined.
+               // @@todo we probably integrate that setup into the api call
+               $mw.proxy.doRequest( options.data,  callback);
+       
+       }else if( parseUri( document.URL ).host == parseUri( options.url ).host ) {
                // Local request: do API request directly
                $j.ajax({
                        type: "POST",
@@ -1943,4 +1953,4 @@ function js_log( string ) {
 function js_error( string ) {
        alert( string );
        return false;
-}
+}
\ No newline at end of file
index f9bf577..6919fea 100644 (file)
@@ -7,8 +7,8 @@
 
 <script type="text/javascript" >
 //HARD coded local test: 
-var remote_wiki_host = 'http://127.1.1.100';
-var remote_script_path = '/wiki_trunk';
+var remote_wiki_host = 'http://test.wikipedia.org';
+var remote_script_path = '/w';
 
 js2AddOnloadHook( function(){  
        $j('#hostName').text( remote_wiki_host );
@@ -22,43 +22,74 @@ js2AddOnloadHook( function(){
                function(){
                        //callback function here: 
                        $j('#setupDone').show('slow');
-                       $j('#doAppendCat').click( doCatAppend );                
+                       $j('#doHello').click( doHello );        
+                       $j('#doAppend').click(doAppend);        
                }
        );                              
 });
-function doCatAppend(){
-       js_log('append cat to User page');
-       //first get our user name:
+function doHello(){
+       js_log('to a hello user');
+       $j('#helloTarget').html( mv_get_loading_img() );
+       //first get the user name:
+       getUserName(function( user_name ){      
+               $j('#helloTarget').hide().text( user_name  ).fadeIn('slow');
+       });
+       return false;
+}
+function getUserName( callback ){
        var rObj = {
                'action':'query',
                'meta':'userinfo'
        }
        //we use normal do_api_req with keywork 'proxy' for the url 
        $mw.proxy.doRequest( rObj,
-               function(data){                                 
+               function( data ){
+                       //if we have no data proxy is not setup?                                        
+                       if(!data){
+                               $mw.proxy.proxyNotReadyDialog();
+                       }
                        //now we get the data back for that domain
                        if( !data.query || !data.query.userinfo ){
                                js_log("Error no query.userinfo ");
                                return false;
-                       }                       
-                       if( data.query.userinfo.id == 0 ){                                                      
-                               var btn = {};
-                               btn['try again'] = function(){
-                                       doCatAppend();
-                               }
-                               btn['cancel'] = function(){
-                                       $j(this).close();
-                               }
-                               $j.addDialog("Not logged in", 
-                                       "Are you logged in on" + remote_wiki_host + " ? Please loggin", 
-                                       btn
-                               )                               
-                       }else{
-                               $j('#helloTarget').hide().text( data.query.userinfo.name ).fadeIn('slow');
                        }
+                       callback( data.query.userinfo.name );                                                                   
                }
        );
-       return false;
+} 
+
+//simple "hello from api proxy" append on talk page
+function doAppend(){
+       $j('#appendTarget').html( mv_get_loading_img() );
+       //get user name
+       getUserName(function(userName){
+               var eTitle = 'User_talk:' + userName;
+               //get a edit token
+               get_mw_token(eTitle, 'proxy', function( token ){
+                       js_log("got token: " + token) ;
+                       var aReq = {
+                               'action':'edit',
+                               'title': eTitle,
+                               'summary': "Api proxy test edit",
+                               'appendtext': "\n\n==== Hello from Api proxy At: " + Date() + " ====",
+                               'token': token
+                       }
+                       do_api_req({
+                               'data': aReq,
+                               'url': 'proxy'
+                       },function(result){
+                               if(result.edit && result.edit.newrevid){                                
+                                       $j('#appendTarget').html( "success: " + JSON.stringify ( result) );
+                                       url = remote_wiki_host +  remote_script_path + '/index.php/';
+                                       url+= result.edit.title.replace(' ', '_');
+                                       $j('#appendTarget').append( '<br><a target="_new" href="' + url + '">visit page</a>' );
+                               }else{
+                                       $j('#appendTarget').html( "falied: " + JSON.stringify ( result) );
+                               }
+                       });
+                       
+               });
+       });
 }
 </script>
  
@@ -66,10 +97,11 @@ function doCatAppend(){
 <body>
 <h3> Simple API proxy testing system </h3>
 
-<div id="setupProxy">Setting up Proxy ... ( <span id="hostName"></span> )</div>
+<div id="setupProxy">Proxy for:  <span id="hostName"></span> <br><span style="font-size:small">( be sure to enable the mwEmbed gadget or add importScriptURI( 'path_to_local_mw_install' + /js2/remoteMwEmbed.js ) to your User skin .js page </span></div>
 <div id="setupDone" style="display:none;">
-<br> <a href="#" id="doAppendCat" >Hello User</a> <span id="helloTarget"><span>
-<br> Some other fun api stuff here...
+       <br> <a href="#" id="doHello" >Hello User:</a> <span id="helloTarget"></span>
+       <br><br><br> <a href="#" id="doAppend">Append Msg to Talk page:</a>
+       <div id="appendTarget"></div>
 </div>
 
 </body>
index 836b971..23fb0fa 100644 (file)
@@ -18,22 +18,23 @@ function doPageSpecificRewrite() {
        // Add media wizard
        if( wgAction == 'edit' || wgAction == 'submit' ) {
                load_mv_embed( function() {
-                       importScriptURI( mwEmbedHostPath + '/editPage.js' + reqAguments );
+                       loadExternalJs( mwEmbedHostPath + '/editPage.js' + reqAguments );
                } );
        }
 
        // Firefogg integration
        if( wgPageName == "Special:Upload" ){
                load_mv_embed( function() {
-                       importScriptURI( mwEmbedHostPath + '/uploadPage.js' + reqAguments );
+                       loadExternalJs( mwEmbedHostPath + '/uploadPage.js' + reqAguments );
                } );
        }
        
        // Special api proxy page
-       if( wgPageName == 'MediaWiki:ApiProxy' ){
+       if( wgPageName == 'MediaWiki:ApiProxy' ){               
                var wgEnableIframeApiProxy = true;
                load_mv_embed( function() {
-                       importScriptURI( mwEmbedHostPath + '/ApiProxyPage.js' + reqAguments );
+                       js_log("Wiki:ApiProxy::");
+                       loadExternalJs( mwEmbedHostPath + '/apiProxyPage.js' + reqAguments );
                });
        }
        
@@ -113,14 +114,14 @@ function rewrite_for_OggHandler( vidIdList ){
 function getRemoteEmbedPath() {
        for( var i = 0; i < document.getElementsByTagName( 'script' ).length; i++ ) {
                var s = document.getElementsByTagName( 'script' )[i];
-               if( s.src.indexOf( 'remoteMwEmbed.js' ) != -1 ) {
+               if( s.src.indexOf( '/remoteMwEmbed.js' ) != -1 ) {
                        var reqStr = '';
                        var scriptPath = '';
                        if( s.src.indexOf( '?' ) != -1) {
                                reqStr = s.src.substr( s.src.indexOf( '?' ) );
-                               scriptPath = s.src.substr( 0,  s.src.indexOf( '?' ) ).replace( 'remoteMwEmbed.js', '' );
+                               scriptPath = s.src.substr( 0,  s.src.indexOf( '?' ) ).replace( '/remoteMwEmbed.js', '' );
                        } else {
-                               scriptPath = s.src.replace( 'remoteMwEmbed.js', '' )
+                               scriptPath = s.src.replace( '/remoteMwEmbed.js', '' )
                        }
                        // Use the external_media_wizard path:
                        return [scriptPath, reqStr];
@@ -129,6 +130,8 @@ function getRemoteEmbedPath() {
 }
 
 function load_mv_embed( callback ) {
+       if(console.log)
+               console.log( 'load_mv_embed');
        // Inject mv_embed if needed
        if( typeof mvEmbed == 'undefined' ) {
                importScriptURI( mwEmbedHostPath + '/mwEmbed/mv_embed.js' + reqAguments );
index 41a391d..9299d56 100644 (file)
@@ -2,9 +2,12 @@
  * This script is run on [[Special:Upload]].
  * It controls the invocation of the mvUploader class based on local config.
  */
+
 js2AddOnloadHook( function() {
+       js_log("never ran js2hook");
        mwUploadHelper.init();
-} );
+});
+
 var mwUploadFormTarget = '#mw-upload-form';
 // Set up the upload form bindings once all DOM manipulation is done
 var mwUploadHelper = {
@@ -82,7 +85,7 @@ var mwUploadHelper = {
                $j( '#wpUploadFileURL' ).attr( 'disabled', set );
 
                // If Firefogg is enabled, toggle action according to wpSourceTypeFile selection
-               if( wgEnableFirefogg ) {
+               if( wgEnableFirefogg ) {                        
                        $j( '#wpUploadFile' ).firefogg({
                                'firefogg_form_action': $j( '#wpSourceTypeFile' ).attr( 'checked' )
                        } );
@@ -136,4 +139,4 @@ var mwUploadHelper = {
                        'warn_target': '#wpDestFile-warning'
                } );
        }
-}
+}
\ No newline at end of file