Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html |
— | — | @@ -3,8 +3,8 @@ |
4 | 4 | <head> |
5 | 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
6 | 6 | <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>--> |
9 | 9 | <script type="text/javascript" > |
10 | 10 | //HARD coded local test: |
11 | 11 | var remote_wiki_host = 'http://commons.wikimedia.org'; |
— | — | @@ -24,9 +24,9 @@ |
25 | 25 | mw.log('to a hello user'); |
26 | 26 | $j('#helloTarget').html( mw.loading_spinner() ); |
27 | 27 | //first get the user name: |
28 | | - getUserName(function( user_name ){ |
| 28 | + getUserName( function( user_name ){ |
29 | 29 | $j('#helloTarget').addClass('UserNameFound').hide().text( user_name ).fadeIn('slow'); |
30 | | - }); |
| 30 | + } ); |
31 | 31 | return false; |
32 | 32 | } |
33 | 33 | function getUserName( callback ){ |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | Target file name: <input id="file-name" type="text" size="15" /> |
161 | 161 | <div id="file-warning"></div> |
162 | 162 | <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"/> |
164 | 164 | </div> |
165 | 165 | <div style="background:#CEF;margin:20px;"> |
166 | 166 | <h3> Browse File Served From Remote: </h3> |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadHandler.js |
— | — | @@ -88,7 +88,6 @@ |
89 | 89 | mw.UploadHandler = function( options ) { |
90 | 90 | return this.init( options ); |
91 | 91 | } |
92 | | - |
93 | 92 | mw.UploadHandler.prototype = { |
94 | 93 | |
95 | 94 | // The form data to be submitted |
— | — | @@ -120,7 +119,6 @@ |
121 | 120 | // The following are really state of the upload, not the interface. |
122 | 121 | // we are currently only managing one, so this is okay... for now. |
123 | 122 | uploadBeginTime: null, |
124 | | - |
125 | 123 | |
126 | 124 | /** |
127 | 125 | * Object initialization |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.UploadInterface.js |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | */ |
21 | 21 | mw.UploadInterface = { }; |
22 | 22 | |
| 23 | + |
23 | 24 | /** |
24 | 25 | * Dialog Interface |
25 | 26 | */ |
— | — | @@ -31,7 +32,11 @@ |
32 | 33 | // we are currently only managing one, so this is okay... for now. |
33 | 34 | uploadBeginTime: null, |
34 | 35 | |
35 | | - setup: function( options ) { |
| 36 | + /** |
| 37 | + * Setup the dialog display |
| 38 | + * @param {Object} options |
| 39 | + */ |
| 40 | + setup: function( options ) { |
36 | 41 | var _this = this; |
37 | 42 | |
38 | 43 | // Start the "upload" time |
— | — | @@ -211,36 +216,44 @@ |
212 | 217 | }; |
213 | 218 | return cancelBtn; |
214 | 219 | } |
215 | | -} |
| 220 | +}; |
216 | 221 | |
| 222 | + |
217 | 223 | /** |
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 ) |
219 | 225 | */ |
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, |
225 | 231 | |
| 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 | + */ |
226 | 238 | init: function( callbackProxy ){ |
227 | 239 | this.callbackProxy = callbackProxy; |
228 | | - }, |
229 | | - |
| 240 | + }, |
230 | 241 | setup: function( options ){ |
231 | 242 | this.callbackProxy( 'setup', options ); |
232 | 243 | }, |
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 |
234 | 248 | 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() |
237 | 251 | mw.log('do update progress' ); |
238 | 252 | this.callbackProxy( 'updateProgress', fraction ); |
239 | 253 | } |
240 | 254 | }, |
| 255 | + |
241 | 256 | setPrompt: function( title_txt, msg, buttons ) { |
242 | 257 | // @@todo fix button isssue: |
243 | 258 | this.callbackProxy( 'setPrompt', title_txt, msg, buttons ); |
244 | 259 | } |
245 | 260 | }; |
246 | | - |
247 | | - |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | } )( jQuery ); |
116 | 116 | |
117 | 117 | |
118 | | -mw.Firefogg = function( options ) { |
| 118 | +mw.Firefogg = function( options ) { |
119 | 119 | return this.init( options ); |
120 | 120 | }; |
121 | 121 | mw.Firefogg.prototype = { // extends mw.BaseUploadHandler |
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js |
— | — | @@ -46,11 +46,7 @@ |
47 | 47 | |
48 | 48 | // ApiProxy scoped functions: |
49 | 49 | ( 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 | + |
55 | 51 | // Callback function for client requests |
56 | 52 | var proxyCallback = null; |
57 | 53 | |
— | — | @@ -67,7 +63,8 @@ |
68 | 64 | // ( note this time starts form when the page is "done" |
69 | 65 | // loading so it should only be the time need to load some |
70 | 66 | // cached js for the callback) |
71 | | - var proxyPageLoadTimeout = 10000; |
| 67 | + // 15 seconds |
| 68 | + var proxyPageLoadTimeout = 15000; |
72 | 69 | |
73 | 70 | /** |
74 | 71 | * Takes a requestQuery, executes the query and then calls the callback |
— | — | @@ -158,7 +155,8 @@ |
159 | 156 | mw.log( "Error: no api url to target" ); |
160 | 157 | return false; |
161 | 158 | } |
162 | | - //update the current apiUrl: |
| 159 | + |
| 160 | + // Update the current apiUrl: |
163 | 161 | currentApiUrl = options.api_url; |
164 | 162 | |
165 | 163 | if( ! options.width ) { |
— | — | @@ -204,7 +202,7 @@ |
205 | 203 | $j('<div />').loadingSpinner() |
206 | 204 | ); |
207 | 205 | |
208 | | - var uploadDialogInterface = mw.DialogInterface(); |
| 206 | + var uploadDialogInterface = new mw.DialogInterface(); |
209 | 207 | |
210 | 208 | // Setup the proxy scope callback to display the upload unhide the iframe upload form |
211 | 209 | proxyCallback = function( iframeData ) { |
— | — | @@ -229,11 +227,11 @@ |
230 | 228 | break |
231 | 229 | case 'uploadUI': |
232 | 230 | 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] ); |
235 | 233 | uploadDialogInterface[ iframeData['method'] ]( |
236 | 234 | args[0], args[1], args[2] |
237 | | - ); |
| 235 | + ); |
238 | 236 | } |
239 | 237 | break; |
240 | 238 | default: |
— | — | @@ -268,17 +266,17 @@ |
269 | 267 | 'action' : 'sendFrameMsg', |
270 | 268 | 'frameName' : options.frameName, |
271 | 269 | 'frameMsg' : options.frameMsg |
272 | | - }; |
| 270 | + }; |
273 | 271 | |
274 | 272 | // Send the iframe request: |
275 | 273 | appendIframe( { |
276 | | - 'persist' : true, |
| 274 | + 'persist' : true, |
277 | 275 | 'src' : getServerFrame( options.api_url ), |
278 | 276 | 'request' : iFrameRequest, |
279 | 277 | 'target' : options.target |
280 | | - }, function() { |
| 278 | + }, function( ) { |
281 | 279 | mw.log( "sendServerMsg iframe done loading" ); |
282 | | - } ) |
| 280 | + } ); |
283 | 281 | } |
284 | 282 | |
285 | 283 | /** |
— | — | @@ -287,14 +285,14 @@ |
288 | 286 | * @param {Object} frameMsg |
289 | 287 | */ |
290 | 288 | $.handleServerMsg = function( frameMsg ){ |
291 | | - mw.log( "handleServerMsg:: " + frameMsg ); |
| 289 | + mw.log( "handleServerMsg:: " + JSON.stringify( frameMsg ) ); |
292 | 290 | if( ! frameMsg.action ){ |
293 | 291 | mw.log(" missing frameMsg action " ); |
294 | 292 | return false; |
295 | 293 | } |
296 | 294 | switch( frameMsg.action ){ |
297 | 295 | case 'fileSubmit': |
298 | | - |
| 296 | + serverSubmitFile( frameMsg.formData ); |
299 | 297 | break; |
300 | 298 | } |
301 | 299 | } |
— | — | @@ -302,7 +300,7 @@ |
303 | 301 | /** |
304 | 302 | * Api server proxy entry point: |
305 | 303 | * validates the server frame request |
306 | | - * and proccess the request type |
| 304 | + * and process the request type |
307 | 305 | */ |
308 | 306 | $.server = function() { |
309 | 307 | // Validate the server request: |
— | — | @@ -383,7 +381,7 @@ |
384 | 382 | |
385 | 383 | setTimeout( function() { |
386 | 384 | 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") |
388 | 386 | mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" ); |
389 | 387 | proxyNotReadyDialog(); |
390 | 388 | } |
— | — | @@ -544,8 +542,9 @@ |
545 | 543 | clientRequest.request[ 'format' ] = 'json'; |
546 | 544 | |
547 | 545 | 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] ); |
550 | 549 | } |
551 | 550 | |
552 | 551 | // Process the API request. We don't use mw.getJSON since we need to "post" |
— | — | @@ -573,7 +572,7 @@ |
574 | 573 | mw.log("Error serverSendFrameMsg without frame msg or frameName" ); |
575 | 574 | return false; |
576 | 575 | } |
577 | | - // Send the messege to the target frame |
| 576 | + // Send the message to the target frame |
578 | 577 | top[ clientRequest.frameName ].mw.ApiProxy.handleServerMsg( clientRequest.frameMsg ); |
579 | 578 | } |
580 | 579 | |
— | — | @@ -589,22 +588,28 @@ |
590 | 589 | wgEnableFirefogg = true; |
591 | 590 | } |
592 | 591 | |
593 | | - // Load the mw.upload library with iframe interface (similar to uploadPage.js) |
| 592 | + // Setup the browse file html |
| 593 | + serverBrowseFileSetup(); |
594 | 594 | |
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. |
596 | 598 | if( wgEnableFirefogg ) { |
597 | 599 | mw.load( 'AddMedia.firefogg', function() { |
598 | | - var uploadConfig = serverBrowseFileSetup(); |
| 600 | + var uploadConfig = getUploadFileConfig( ); |
| 601 | + |
| 602 | + $j( '#wpUploadFile' ).firefogg( uploadConfig ); |
599 | 603 | |
600 | | - $j( '#wpUploadFile' ).firefogg( uploadConfig ); |
601 | 604 | // Update status |
602 | 605 | sendClientMsg( {'status':'ok'} ); |
603 | 606 | }); |
604 | 607 | } else { |
605 | 608 | mw.load( 'AddMedia.UploadHandler', function() { |
606 | | - var uploadConfig = serverBrowseFileSetup(); |
| 609 | + var uploadConfig = getUploadFileConfig(); |
607 | 610 | |
608 | 611 | $j( 'mw-upload-form' ).uploadHandler( uploadConfig ); |
| 612 | + |
| 613 | + // Update status |
609 | 614 | sendClientMsg( {'status':'ok'} ); |
610 | 615 | }); |
611 | 616 | } |
— | — | @@ -615,7 +620,7 @@ |
616 | 621 | * @return browse file config |
617 | 622 | */ |
618 | 623 | function serverBrowseFileSetup( ){ |
619 | | - // Get the proxy config |
| 624 | + // Get the proxy config |
620 | 625 | var proxyConfig = mw.getConfig( 'apiProxyConfig' ); |
621 | 626 | //check for fw ( file width ) |
622 | 627 | if( ! proxyConfig.fileWidth ) { |
— | — | @@ -644,19 +649,26 @@ |
645 | 650 | 'width' : proxyConfig.fileWidth |
646 | 651 | }) |
647 | 652 | ) |
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 ); |
651 | 663 | // Send the client the msg: |
652 | 664 | sendClientMsg( { |
653 | 665 | 'event' : 'uploadUI', |
654 | 666 | 'method' : method, |
655 | 667 | // Get all the arguments after the "method" |
656 | | - 'arguments' : arguments.split( 1 ) |
| 668 | + 'arguments' : args |
657 | 669 | } ); |
658 | | - }) |
| 670 | + } ); |
659 | 671 | |
660 | | - var uploadConfig = { |
| 672 | + var uploadConfig = { |
661 | 673 | // Set the interface type |
662 | 674 | 'ui' : uploadIframeUI, |
663 | 675 | |
— | — | @@ -669,14 +681,17 @@ |
670 | 682 | } |
671 | 683 | } |
672 | 684 | return uploadConfig; |
673 | | - |
674 | 685 | } |
675 | 686 | |
676 | | - function serverSubmitFile( options ){ |
| 687 | + /** |
| 688 | + * Server submit file |
| 689 | + * @param {Object} options Options for submiting file |
| 690 | + */ |
| 691 | + function serverSubmitFile( formData ){ |
677 | 692 | // Add the FileName and and the description to the form |
678 | 693 | var $form = $j('#mw-upload-form'); |
679 | 694 | // Add the filename and description if missing |
680 | | - if( ! $form.find('#filename').length ){ |
| 695 | + if( ! $form.find("[name='filename']").length ){ |
681 | 696 | $form.append( |
682 | 697 | $j( '<input />' ) |
683 | 698 | .attr( { |
— | — | @@ -685,7 +700,7 @@ |
686 | 701 | } ) |
687 | 702 | ); |
688 | 703 | } |
689 | | - if( ! $form.find('#description').length ){ |
| 704 | + if( ! $form.find("[name='description']").length ){ |
690 | 705 | $form.append( |
691 | 706 | $j( '<input />' ) |
692 | 707 | .attr( { |
— | — | @@ -696,13 +711,13 @@ |
697 | 712 | } |
698 | 713 | |
699 | 714 | // 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 ) |
702 | 717 | } |
703 | | - if( options.description ) { |
704 | | - $form.find( '#description' ).val( options.description ) |
| 718 | + if( formData.description ) { |
| 719 | + $form.find( "[name='description']" ).val( formData.description ) |
705 | 720 | } |
706 | | - |
| 721 | + |
707 | 722 | // Do submit the form |
708 | 723 | $form.submit(); |
709 | 724 | }; |
— | — | @@ -713,15 +728,15 @@ |
714 | 729 | */ |
715 | 730 | function sendClientMsg( msgObj ) { |
716 | 731 | |
717 | | - // Get a local refrence to the client request |
| 732 | + // Get a local reference to the client request |
718 | 733 | var clientFrame = getClientRequest()['clientFrame']; |
719 | 734 | |
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 |
721 | 736 | if( ! isAllowedClientFrame ( clientFrame ) ) { |
722 | 737 | mw.log( "cant send msg to " + clientFrame ); |
723 | 738 | return false; |
724 | 739 | } |
725 | | - var nestName = 'NestedFrame_' + $j('iframe').length; |
| 740 | + var nestName = 'NestedFrame_' + $j( 'iframe' ).length; |
726 | 741 | |
727 | 742 | // Append the iframe to body |
728 | 743 | appendIframe( { |
— | — | @@ -786,7 +801,7 @@ |
787 | 802 | if( ! options.persist ){ |
788 | 803 | // Schedule the removal of the iframe |
789 | 804 | setTimeout( function() { |
790 | | - $j('#' + options['name'] ).remove(); |
| 805 | + $j('#' + options[ 'name' ] ).remove(); |
791 | 806 | }, 10 ); |
792 | 807 | } |
793 | 808 | // Call the onload callback if set: |
— | — | @@ -795,6 +810,5 @@ |
796 | 811 | } |
797 | 812 | }; |
798 | 813 | } |
799 | | - |
800 | | - |
| 814 | + |
801 | 815 | } )( window.mw.ApiProxy ); |
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js |
— | — | @@ -121,7 +121,7 @@ |
122 | 122 | mw.load( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() ); |
123 | 123 | } ); |
124 | 124 | } |
125 | | - |
| 125 | + |
126 | 126 | // OggHandler rewrite for view pages: |
127 | 127 | var vidIdList = []; |
128 | 128 | var divs = document.getElementsByTagName( 'div' ); |