r62631 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62630‎ | r62631 | r62632 >
Date:00:24, 17 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* some proxy code clean up
* refactored request handle to serverHandleRequest function
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
@@ -8,9 +8,10 @@
99 * and a central blacklisting of domains controlled by the site
1010 *
1111 * if the browser supports it we should pass msgs with postMessage API
12 -* http://ejohn.org/blog/cross-window-messaging/
 12+* http://ejohn.org/blog/cross-window-messaging/
1313 *
14 -* NOTE: it would be nice if this supported multiple proxy targets (ie to a bright widgets future)
 14+* NOTE: refactor efforts will include separating out "core" proxy functions and
 15+* having a separate class for "server" and "client" api usage
1516 *
1617 */
1718
@@ -24,8 +25,6 @@
2526 } );
2627
2728
28 -
29 -
3029 /**
3130 * apiProxy jQuery binding
3231 *
@@ -76,6 +75,7 @@
7776 * @param {Function} callback Function called once the request is complete
7877 */
7978 $.doRequest = function( apiUrl, requestQuery, callback ) {
 79+
8080 // Reset local vars:
8181 proxyCallback = false;
8282 frameProxyOk = false;
@@ -87,10 +87,16 @@
8888 }
8989
9090 mw.log( "doRequest:: " + JSON.stringify( requestQuery ) );
 91+
 92+ // Set local scope current request
 93+ // ( presently the api proxy only support sequential requests
 94+ // for multiple simultaneous requests we will need to do some minor refactoring )
9195 currentApiReq = requestQuery;
9296 currentApiUrl = apiUrl;
 97+
9398 // Setup the callback:
9499 proxyCallback = callback;
 100+
95101 // Do the proxy req:
96102 doFrameProxy( requestQuery );
97103 }
@@ -105,6 +111,7 @@
106112 $.nested = function( hashResult ) {
107113 // Close the loader if present:
108114 mw.closeLoaderDialog();
 115+
109116 mw.log( '$.proxy.nested callback :: ' + unescape( hashResult ) );
110117 frameProxyOk = true;
111118
@@ -193,7 +200,7 @@
194201
195202 // Setup the proxy callback to display the upload unhide the iframe upload form
196203 proxyCallback = function( iframeData ){
197 - //proccess fileBrowse callbacks::
 204+ // proccess fileBrowse callbacks::
198205
199206 // check for basic status "ok"
200207 if( iframeData['status'] == 'ok' ){
@@ -212,13 +219,9 @@
213220 break;
214221 default:
215222 mw.log(" Error unreconginzed event " + iframeData['event'] );
216 - }
217 -
218 - }
219 -
220 -
221 - }
222 -
 223+ }
 224+ }
 225+ }
223226 }
224227
225228 /**
@@ -238,15 +241,7 @@
239242 // Inform the client frame that we passed validation
240243 sendClientMsg( { 'state':'ok' } );
241244
242 - // Process request type
243 - if( clientRequest['browseFile'] ){
244 - mw.log( "DO BROWSE FILE" );
245 - serverBrowseFile( proxyConfig );
246 - return ;
247 - }
248 - // Else do a normal api request :
249 - return doApiRequest();
250 -
 245+ return serverHandleRequest();
251246 }
252247
253248 /**
@@ -325,7 +320,7 @@
326321
327322 setTimeout( function() {
328323 if ( !frameProxyOk ) {
329 - // we timmed out no api proxy (should make sure the user is "logged in")
 324+ // We timmed out no api proxy (should make sure the user is "logged in")
330325 mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" );
331326 proxyNotReadyDialog();
332327 }
@@ -335,7 +330,7 @@
336331
337332 /**
338333 * Validate an iframe request
339 - * checks the url hash for required paramaters
 334+ * checks the url hash for required parameters
340335 * checks master_blacklist
341336 * checks master_whitelist
342337 */
@@ -365,8 +360,7 @@
366361 * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig
367362 */
368363 return isAllowedClientFrame( clientRequest.clientFrame );
369 -
370 -
 364+
371365 // Not a valid request return false
372366 }
373367
@@ -430,7 +424,8 @@
431425 var pUri = mw.parseUri( getServerFrame() );
432426
433427 // FIXME we should have a Hosted page once we deploy mwEmbed on the servers.
434 - // A hosted page would be much faster since than a normal page view rewrite
 428+ // A hosted page would be much faster since it would not have to load all the
 429+ // normal page view assets prior to being rewrite for api proxy usage.
435430
436431 var login_url = pUri.protocol + '://' + pUri.host;
437432 login_url += pUri.path.replace( 'MediaWiki:ApiProxy', 'Special:UserLogin' );
@@ -454,18 +449,31 @@
455450 * Handles the server side proxy of requests
456451 * it adds child frames pointing to the parent "blank" frames
457452 */
458 -
 453+
 454+ /**
 455+ * serverHandleRequest handle a given request from the client
 456+ * maps the request to serverBrowseFile or serverApiRequest
 457+ */
 458+ function serverHandleRequest(){
 459+ var clientRequest = getClientRequest();
 460+ // Process request type
 461+ if( clientRequest['browseFile'] ){
 462+ serverBrowseFile();
 463+ return true;
 464+ }
 465+ // Else do a normal api request :
 466+ return serverApiRequest();
 467+ }
459468 /**
460469 * Api iFrame request:
461 - * @param {Object} requestObj Api request object
462470 */
463 - function doApiRequest( ) {
 471+ function serverApiRequest( ) {
464472 // Get the client request
465473 var clientRequest = getClientRequest();
466474 // Make sure its a json format
467475 clientRequest.request[ 'format' ] = 'json';
468476
469 - // Process the API request. We don't use mw.apiReq since we need to "post"
 477+ // Process the API request. We don't use mw.getJSON since we need to "post"
470478 $j.post( wgScriptPath + '/api' + wgScriptExtension,
471479 clientRequest.request,
472480 function( data ) {
@@ -480,7 +488,9 @@
481489 *
482490 * Sets the page content to browser file
483491 */
484 - function serverBrowseFile( proxyConfig ){
 492+ function serverBrowseFile( ){
 493+ // Get the proxy config
 494+ var proxyConfig = mw.getConfig( 'apiProxyConfig' );
485495 //check for fw ( file width )
486496 if( ! proxyConfig.fileWidth ){
487497 proxyConfig.fileWidth = 130;
@@ -576,7 +586,7 @@
577587
578588 // After the nested frame is done loading schedule its removal
579589 $j( '#' + nestName ).get( 0 ).onload = function() {
580 - // use a settimeout to give time for client frame to propogate update.
 590+ // Use a settimeout to give time for client frame to propagate update.
581591 setTimeout( function(){
582592 $j('#' + nestName ).remove();
583593 }, 10 );

Status & tagging log