r63128 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63127‎ | r63128 | r63129 >
Date:18:47, 1 March 2010
Author:dale
Status:deferred
Tags:
Comment:
improved apiProxy upload
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadHandler.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadInterface.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html
@@ -3,8 +3,8 @@
44 <head>
55 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66 <title>Api Proxy Test</title>
7 -<script type="text/javascript" src="../mwEmbed.js?debug=true"></script>
8 -
 7+ <script type="text/javascript" src="../mwEmbed.js?debug=true"></script>
 8+ <!-- <script type="text/javascript" src="../jsScriptLoader.php?class=mwEmbed,mw.ApiProxy&debug=true"></script>-->
99 <script type="text/javascript" >
1010 //HARD coded local test:
1111 var remote_wiki_host = 'http://commons.wikimedia.org';
@@ -24,9 +24,9 @@
2525 mw.log('to a hello user');
2626 $j('#helloTarget').html( mw.loading_spinner() );
2727 //first get the user name:
28 - getUserName(function( user_name ){
 28+ getUserName( function( user_name ){
2929 $j('#helloTarget').addClass('UserNameFound').hide().text( user_name ).fadeIn('slow');
30 - });
 30+ } );
3131 return false;
3232 }
3333 function getUserName( callback ){
@@ -159,7 +159,7 @@
160160 Target file name: <input id="file-name" type="text" size="15" />
161161 <div id="file-warning"></div>
162162 <BR>
163 - Target desc: <input id="file-desc" type="text" size="20" />
 163+ Target desc: <input id="file-desc" type="text" size="20" value="test proxy desc"/>
164164 </div>
165165 <div style="background:#CEF;margin:20px;">
166166 <h3> Browse File Served From Remote: </h3>
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadHandler.js
@@ -88,7 +88,6 @@
8989 mw.UploadHandler = function( options ) {
9090 return this.init( options );
9191 }
92 -
9392 mw.UploadHandler.prototype = {
9493
9594 // The form data to be submitted
@@ -120,7 +119,6 @@
121120 // The following are really state of the upload, not the interface.
122121 // we are currently only managing one, so this is okay... for now.
123122 uploadBeginTime: null,
124 -
125123
126124 /**
127125 * Object initialization
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadInterface.js
@@ -19,6 +19,7 @@
2020 */
2121 mw.UploadInterface = { };
2222
 23+
2324 /**
2425 * Dialog Interface
2526 */
@@ -31,7 +32,11 @@
3233 // we are currently only managing one, so this is okay... for now.
3334 uploadBeginTime: null,
3435
35 - setup: function( options ) {
 36+ /**
 37+ * Setup the dialog display
 38+ * @param {Object} options
 39+ */
 40+ setup: function( options ) {
3641 var _this = this;
3742
3843 // Start the "upload" time
@@ -211,36 +216,44 @@
212217 };
213218 return cancelBtn;
214219 }
215 -}
 220+};
216221
 222+
217223 /**
218 - * Iframe Interface ( sends updates to an iframe for remoteing upload progress events )
 224+ * Iframe Interface ( sends updates to an iframe for remote upload progress events )
219225 */
220 -mw.UploadIframeUI = function( callbackProxy ) {
221 - return this;
222 -}
223 -mw.UploadIframeUI.prototype = {
224 - 'lastProgressTime' : 0,
 226+mw.UploadIframeUI = function( callbackProxy ) {
 227+ return this.init( callbackProxy );
 228+};
 229+mw.UploadIframeUI.prototype = {
 230+ lastProgressTime : 0,
225231
 232+ /**
 233+ * init
 234+ * @param {Function} callbackProxy Function that reciveds
 235+ * all the method calls to be pass along as msgs to the
 236+ * other domain via iframe proxy or eventually html5 sendMsg
 237+ */
226238 init: function( callbackProxy ){
227239 this.callbackProxy = callbackProxy;
228 - },
229 -
 240+ },
230241 setup: function( options ){
231242 this.callbackProxy( 'setup', options );
232243 },
233 - // Don't call update progress more than every 3 seconds
 244+
 245+ // Don't call update progress more than once every 4 seconds
 246+ // Since it involves loading a cached iframe. Once we support html5
 247+ // cross domain "sendMsg" then we can pass all updates
234248 updateProgress: function( fraction ) {
235 - if( ( new Date() ).getTime() - _this.lastProgressTime > 3000 ){
236 - _this.lastProgressTime = ( new Date() ).getTime()
 249+ if( ( new Date() ).getTime() - this.lastProgressTime > 4000 ){
 250+ this.lastProgressTime = ( new Date() ).getTime()
237251 mw.log('do update progress' );
238252 this.callbackProxy( 'updateProgress', fraction );
239253 }
240254 },
 255+
241256 setPrompt: function( title_txt, msg, buttons ) {
242257 // @@todo fix button isssue:
243258 this.callbackProxy( 'setPrompt', title_txt, msg, buttons );
244259 }
245260 };
246 -
247 -
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js
@@ -114,7 +114,7 @@
115115 } )( jQuery );
116116
117117
118 -mw.Firefogg = function( options ) {
 118+mw.Firefogg = function( options ) {
119119 return this.init( options );
120120 };
121121 mw.Firefogg.prototype = { // extends mw.BaseUploadHandler
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js
@@ -46,11 +46,7 @@
4747
4848 // ApiProxy scoped functions:
4949 ( function( $ ) {
50 -
51 -
52 - // Local scope public vars
53 - //( should probably tie these var defines to the scope of the doRequest call using something like "curry" function )
54 -
 50+
5551 // Callback function for client requests
5652 var proxyCallback = null;
5753
@@ -67,7 +63,8 @@
6864 // ( note this time starts form when the page is "done"
6965 // loading so it should only be the time need to load some
7066 // cached js for the callback)
71 - var proxyPageLoadTimeout = 10000;
 67+ // 15 seconds
 68+ var proxyPageLoadTimeout = 15000;
7269
7370 /**
7471 * Takes a requestQuery, executes the query and then calls the callback
@@ -158,7 +155,8 @@
159156 mw.log( "Error: no api url to target" );
160157 return false;
161158 }
162 - //update the current apiUrl:
 159+
 160+ // Update the current apiUrl:
163161 currentApiUrl = options.api_url;
164162
165163 if( ! options.width ) {
@@ -204,7 +202,7 @@
205203 $j('<div />').loadingSpinner()
206204 );
207205
208 - var uploadDialogInterface = mw.DialogInterface();
 206+ var uploadDialogInterface = new mw.DialogInterface();
209207
210208 // Setup the proxy scope callback to display the upload unhide the iframe upload form
211209 proxyCallback = function( iframeData ) {
@@ -229,11 +227,11 @@
230228 break
231229 case 'uploadUI':
232230 if( uploadDialogInterface[ iframeData['method'] ] ){
233 - var args = iframeData['arguments'];
234 - debugger;
 231+ var args = iframeData['arguments'];
 232+ mw.log( "Do dialog interface: " + iframeData['method'] + ' args: ' + args[0] + ', ' + args[1] + ', ' + args[2] );
235233 uploadDialogInterface[ iframeData['method'] ](
236234 args[0], args[1], args[2]
237 - );
 235+ );
238236 }
239237 break;
240238 default:
@@ -268,17 +266,17 @@
269267 'action' : 'sendFrameMsg',
270268 'frameName' : options.frameName,
271269 'frameMsg' : options.frameMsg
272 - };
 270+ };
273271
274272 // Send the iframe request:
275273 appendIframe( {
276 - 'persist' : true,
 274+ 'persist' : true,
277275 'src' : getServerFrame( options.api_url ),
278276 'request' : iFrameRequest,
279277 'target' : options.target
280 - }, function() {
 278+ }, function( ) {
281279 mw.log( "sendServerMsg iframe done loading" );
282 - } )
 280+ } );
283281 }
284282
285283 /**
@@ -287,14 +285,14 @@
288286 * @param {Object} frameMsg
289287 */
290288 $.handleServerMsg = function( frameMsg ){
291 - mw.log( "handleServerMsg:: " + frameMsg );
 289+ mw.log( "handleServerMsg:: " + JSON.stringify( frameMsg ) );
292290 if( ! frameMsg.action ){
293291 mw.log(" missing frameMsg action " );
294292 return false;
295293 }
296294 switch( frameMsg.action ){
297295 case 'fileSubmit':
298 -
 296+ serverSubmitFile( frameMsg.formData );
299297 break;
300298 }
301299 }
@@ -302,7 +300,7 @@
303301 /**
304302 * Api server proxy entry point:
305303 * validates the server frame request
306 - * and proccess the request type
 304+ * and process the request type
307305 */
308306 $.server = function() {
309307 // Validate the server request:
@@ -383,7 +381,7 @@
384382
385383 setTimeout( function() {
386384 if ( !frameProxyOk ) {
387 - // We timmed out no api proxy (should make sure the user is "logged in")
 385+ // We timed out no api proxy (should make sure the user is "logged in")
388386 mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" );
389387 proxyNotReadyDialog();
390388 }
@@ -544,8 +542,9 @@
545543 clientRequest.request[ 'format' ] = 'json';
546544
547545 mw.log(" do post request to: " + wgScriptPath + '/api' + wgScriptExtension );
548 - for(var i in clientRequest.request ) {
549 - mw.log("req: " + i + " :: " + clientRequest.request[i] );
 546+
 547+ for( var i in clientRequest.request ) {
 548+ mw.log("req: " + i + " = " + clientRequest.request[i] );
550549 }
551550
552551 // Process the API request. We don't use mw.getJSON since we need to "post"
@@ -573,7 +572,7 @@
574573 mw.log("Error serverSendFrameMsg without frame msg or frameName" );
575574 return false;
576575 }
577 - // Send the messege to the target frame
 576+ // Send the message to the target frame
578577 top[ clientRequest.frameName ].mw.ApiProxy.handleServerMsg( clientRequest.frameMsg );
579578 }
580579
@@ -589,22 +588,28 @@
590589 wgEnableFirefogg = true;
591590 }
592591
593 - // Load the mw.upload library with iframe interface (similar to uploadPage.js)
 592+ // Setup the browse file html
 593+ serverBrowseFileSetup();
594594
595 - // Check if firefogg is enabled:
 595+ // Load the mw.upload library with iframe interface (similar to uploadPage.js)
 596+ // Check if firefogg is enabled:
 597+ // NOTE: the binding function should be made identical.
596598 if( wgEnableFirefogg ) {
597599 mw.load( 'AddMedia.firefogg', function() {
598 - var uploadConfig = serverBrowseFileSetup();
 600+ var uploadConfig = getUploadFileConfig( );
 601+
 602+ $j( '#wpUploadFile' ).firefogg( uploadConfig );
599603
600 - $j( '#wpUploadFile' ).firefogg( uploadConfig );
601604 // Update status
602605 sendClientMsg( {'status':'ok'} );
603606 });
604607 } else {
605608 mw.load( 'AddMedia.UploadHandler', function() {
606 - var uploadConfig = serverBrowseFileSetup();
 609+ var uploadConfig = getUploadFileConfig();
607610
608611 $j( 'mw-upload-form' ).uploadHandler( uploadConfig );
 612+
 613+ // Update status
609614 sendClientMsg( {'status':'ok'} );
610615 });
611616 }
@@ -615,7 +620,7 @@
616621 * @return browse file config
617622 */
618623 function serverBrowseFileSetup( ){
619 - // Get the proxy config
 624+ // Get the proxy config
620625 var proxyConfig = mw.getConfig( 'apiProxyConfig' );
621626 //check for fw ( file width )
622627 if( ! proxyConfig.fileWidth ) {
@@ -644,19 +649,26 @@
645650 'width' : proxyConfig.fileWidth
646651 })
647652 )
648 - );
649 -
650 - var uploadIframeUI = mw.UploadIframeUI( function( method ){
 653+ );
 654+ }
 655+
 656+ /**
 657+ * Browse file upload config gennerator
 658+ */
 659+ function getUploadFileConfig(){
 660+ var uploadIframeUI = new mw.UploadIframeUI( function( method ){
 661+ // Get all the arguments after the "method"
 662+ var args = $j.makeArray( arguments ).splice( 1 );
651663 // Send the client the msg:
652664 sendClientMsg( {
653665 'event' : 'uploadUI',
654666 'method' : method,
655667 // Get all the arguments after the "method"
656 - 'arguments' : arguments.split( 1 )
 668+ 'arguments' : args
657669 } );
658 - })
 670+ } );
659671
660 - var uploadConfig = {
 672+ var uploadConfig = {
661673 // Set the interface type
662674 'ui' : uploadIframeUI,
663675
@@ -669,14 +681,17 @@
670682 }
671683 }
672684 return uploadConfig;
673 -
674685 }
675686
676 - function serverSubmitFile( options ){
 687+ /**
 688+ * Server submit file
 689+ * @param {Object} options Options for submiting file
 690+ */
 691+ function serverSubmitFile( formData ){
677692 // Add the FileName and and the description to the form
678693 var $form = $j('#mw-upload-form');
679694 // Add the filename and description if missing
680 - if( ! $form.find('#filename').length ){
 695+ if( ! $form.find("[name='filename']").length ){
681696 $form.append(
682697 $j( '<input />' )
683698 .attr( {
@@ -685,7 +700,7 @@
686701 } )
687702 );
688703 }
689 - if( ! $form.find('#description').length ){
 704+ if( ! $form.find("[name='description']").length ){
690705 $form.append(
691706 $j( '<input />' )
692707 .attr( {
@@ -696,13 +711,13 @@
697712 }
698713
699714 // Update filename and description ( if set )
700 - if( options.filename ) {
701 - $form.find( "#filename" ).val( options.filename )
 715+ if( formData.filename ) {
 716+ $form.find( "[name='filename']" ).val( formData.filename )
702717 }
703 - if( options.description ) {
704 - $form.find( '#description' ).val( options.description )
 718+ if( formData.description ) {
 719+ $form.find( "[name='description']" ).val( formData.description )
705720 }
706 -
 721+
707722 // Do submit the form
708723 $form.submit();
709724 };
@@ -713,15 +728,15 @@
714729 */
715730 function sendClientMsg( msgObj ) {
716731
717 - // Get a local refrence to the client request
 732+ // Get a local reference to the client request
718733 var clientFrame = getClientRequest()['clientFrame'];
719734
720 - // Double check that the client is an approved domain before outputing the iframe
 735+ // Double check that the client is an approved domain before outputting the iframe
721736 if( ! isAllowedClientFrame ( clientFrame ) ) {
722737 mw.log( "cant send msg to " + clientFrame );
723738 return false;
724739 }
725 - var nestName = 'NestedFrame_' + $j('iframe').length;
 740+ var nestName = 'NestedFrame_' + $j( 'iframe' ).length;
726741
727742 // Append the iframe to body
728743 appendIframe( {
@@ -786,7 +801,7 @@
787802 if( ! options.persist ){
788803 // Schedule the removal of the iframe
789804 setTimeout( function() {
790 - $j('#' + options['name'] ).remove();
 805+ $j('#' + options[ 'name' ] ).remove();
791806 }, 10 );
792807 }
793808 // Call the onload callback if set:
@@ -795,6 +810,5 @@
796811 }
797812 };
798813 }
799 -
800 -
 814+
801815 } )( window.mw.ApiProxy );
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -121,7 +121,7 @@
122122 mw.load( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() );
123123 } );
124124 }
125 -
 125+
126126 // OggHandler rewrite for view pages:
127127 var vidIdList = [];
128128 var divs = document.getElementsByTagName( 'div' );

Status & tagging log