Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html |
— | — | @@ -17,7 +17,9 @@ |
18 | 18 | $j('#setupDone').show('slow'); |
19 | 19 | $j('#doHello').click( doHello ); |
20 | 20 | $j('#doAppend').click( doAppend ); |
| 21 | + $j('#doFileBrowse').click( doFileUpload ); |
21 | 22 | }); |
| 23 | + |
22 | 24 | function doHello(){ |
23 | 25 | mw.log('to a hello user'); |
24 | 26 | $j('#helloTarget').html( mw.loading_spinner() ); |
— | — | @@ -44,7 +46,7 @@ |
45 | 47 | ); |
46 | 48 | } |
47 | 49 | |
48 | | -//simple "hello from api proxy" append on talk page |
| 50 | +// Simple "hello from api proxy" append on talk page |
49 | 51 | function doAppend(){ |
50 | 52 | $j('#appendTarget').html( mw.loading_spinner() ); |
51 | 53 | //get user name |
— | — | @@ -74,6 +76,20 @@ |
75 | 77 | }); |
76 | 78 | }); |
77 | 79 | } |
| 80 | + |
| 81 | + |
| 82 | +function doFileUpload(){ |
| 83 | + $j('#browseTarget').html( mw.loading_spinner() ); |
| 84 | + mw.load( 'ApiProxy', function(){ |
| 85 | + mw.ApiProxy.browseFile( { |
| 86 | + 'target' : '#browseTarget', |
| 87 | + 'apiUrl' : remote_api_url |
| 88 | + },function(){ |
| 89 | + mw.log( 'brwose file cb' ); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | +} |
78 | 94 | </script> |
79 | 95 | |
80 | 96 | </head> |
— | — | @@ -83,8 +99,13 @@ |
84 | 100 | <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' + /js/remoteMwEmbed.js ) to your User skin .js page </span></div> |
85 | 101 | <div id="setupDone" style="display:none;"> |
86 | 102 | <br> <a href="#" id="doHello" >Hello User:</a> <span id="helloTarget"></span> |
| 103 | + |
87 | 104 | <br><br><br> <a href="#" id="doAppend">Append Msg to Talk page:</a> |
88 | 105 | <div id="appendTarget"></div> |
| 106 | + |
| 107 | + <br><br><br> <a href="#" id="doFileBrowse">Upload a file to remote:</a> |
| 108 | + <div id="browseTarget"></div> |
| 109 | + |
89 | 110 | </div> |
90 | 111 | |
91 | 112 | </body> |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js |
— | — | @@ -1062,6 +1062,7 @@ |
1063 | 1063 | mw.log( "could not parse uploadstatus / could not get responseText" ); |
1064 | 1064 | } |
1065 | 1065 | } |
| 1066 | + |
1066 | 1067 | |
1067 | 1068 | if ( _this.oldResponseText != response_text ) { |
1068 | 1069 | mw.log( 'new result text:' + response_text + ' state:' + _this.fogg.state ); |
— | — | @@ -1077,8 +1078,9 @@ |
1078 | 1079 | } catch( e ) { |
1079 | 1080 | var apiResult = null; |
1080 | 1081 | } |
1081 | | - } |
1082 | | - //Check for scuccess: |
| 1082 | + } |
| 1083 | + |
| 1084 | + //Check for success: |
1083 | 1085 | if( apiResult && _this.isApiSuccess( apiResult ) ){ |
1084 | 1086 | if( _this.processApiResult ( apiResult ) ){ |
1085 | 1087 | return true; |
— | — | @@ -1092,6 +1094,7 @@ |
1093 | 1095 | _this.fogg.cancel(); |
1094 | 1096 | return false; |
1095 | 1097 | } |
| 1098 | + |
1096 | 1099 | } |
1097 | 1100 | if ( _this.show_preview == true ) { |
1098 | 1101 | if ( _this.fogg.state == 'encoding' ) { |
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js |
— | — | @@ -843,6 +843,7 @@ |
844 | 844 | processApiResult: function( apiRes ) { |
845 | 845 | var _this = this; |
846 | 846 | mw.log( 'processApiResult::' ); |
| 847 | + |
847 | 848 | if ( !_this.isApiSuccess( apiRes ) ) { |
848 | 849 | // Error detected, show it to the user |
849 | 850 | _this.showApiError( apiRes ); |
— | — | @@ -856,7 +857,7 @@ |
857 | 858 | return; |
858 | 859 | } |
859 | 860 | |
860 | | - if ( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ) { |
| 861 | + if ( apiRes.upload && apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ) { |
861 | 862 | var url = apiRes.upload.imageinfo.descriptionurl; |
862 | 863 | |
863 | 864 | // Upload complete. |
Index: branches/js2-work/phase3/js/mwEmbed/modules/ApiProxy/mw.ApiProxy.js |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | // Local scope public vars |
52 | 52 | //( should probably tie these var defines to the scope of the doRequest call using something like "curry" function ) |
53 | 53 | |
54 | | - // Callback funcion for client requests |
| 54 | + // Callback function for client requests |
55 | 55 | var proxyCallback = null; |
56 | 56 | |
57 | 57 | // FrameProxy Flag: |
— | — | @@ -119,6 +119,25 @@ |
120 | 120 | proxyCallback( resultObject ); |
121 | 121 | } |
122 | 122 | |
| 123 | + /** |
| 124 | + * Generates a remote browse file iframe window |
| 125 | + * usefull for "uploading" cross domain |
| 126 | + * |
| 127 | + * @param {Function} callback Function to host the |
| 128 | + */ |
| 129 | + $.browseFile = function( options ){ |
| 130 | + if( ! options.target ){ |
| 131 | + mw.log( "Error: no target for file browse" ) ; |
| 132 | + return false; |
| 133 | + } |
| 134 | + if( ! options.apiUrl ){ |
| 135 | + mw.log( "Error: no api url to target" ); |
| 136 | + } |
| 137 | + $j( options.target ).html( |
| 138 | + |
| 139 | + ); |
| 140 | + } |
| 141 | + |
123 | 142 | /** |
124 | 143 | * Api server proxy entry point: |
125 | 144 | * |
— | — | @@ -127,64 +146,16 @@ |
128 | 147 | * |
129 | 148 | */ |
130 | 149 | $.server = function( proxyConfig, callback ) { |
131 | | - /** |
132 | | - * Clear the body of any html |
133 | | - */ |
134 | | - $j( 'body' ).html( 'Proxy Setup: ' ); |
135 | | - |
136 | | - var clientRequest = false; |
137 | | - |
138 | | - // Read the anchor action from the requesting url |
139 | | - var hashMsg = unescape( mw.parseUri( document.URL ).anchor ); |
140 | | - try { |
141 | | - var clientRequest = JSON.parse( hashMsg ); |
142 | | - } catch ( e ) { |
143 | | - mw.log( "ProxyServer:: could not parse anchor" ); |
144 | | - } |
145 | | - |
146 | | - if ( !clientRequest || !clientRequest.clientFrame ) { |
147 | | - mw.log( "Error: no client domain provided " ); |
148 | | - $j( 'body' ).append( "no client frame provided" ); |
149 | | - return false; |
150 | | - } |
151 | | - |
152 | | - // Make sure we are logged in |
153 | | - // (its a normal mediaWiki page so all site vars should be defined) |
154 | | - if ( typeof wgUserName != 'undefined' && !wgUserName ) { |
155 | | - mw.log( 'Error Not logged in' ); |
156 | | - return false; |
157 | | - } |
158 | | - |
159 | | - mw.log( "Setup server on: " + mw.parseUri( document.URL ).host ); |
160 | | - mw.log('Client frame: ' + clientRequest.clientFrame ); |
161 | | - |
162 | | - var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ; |
163 | | - |
164 | | - /** |
165 | | - * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig |
166 | | - */ |
167 | | - // Check master blacklist |
168 | | - for ( var i in proxyConfig.master_blacklist ) { |
169 | | - if ( clientDomain == proxyConfig.master_blacklist ) { |
170 | | - mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' ); |
171 | | - return false; |
172 | | - } |
173 | | - } |
174 | | - // Check the master whitelist: |
175 | | - for ( var i in proxyConfig.master_whitelist ) { |
176 | | - if ( clientDomain == proxyConfig.master_whitelist[ i ] ) { |
177 | | - // Do the request: |
178 | | - return doApiRequest( clientRequest ); |
179 | | - } |
180 | | - } |
181 | | - |
182 | | - // FIXME Add in user based approval :: |
183 | | - |
184 | | - // FIXME grab the users whitelist for our current domain |
185 | | - |
186 | | - // FIXME offer the user the ability to "approve" requested domain save to |
187 | | - // their user preference setup ) |
188 | | - |
| 150 | + //Validate the server request: |
| 151 | + if( validateIframeRequest( proxyConfig ) ){ |
| 152 | + // Process request type |
| 153 | + if( proxyConfig['browserFile'] ){ |
| 154 | + doBrowseFile(); |
| 155 | + return ; |
| 156 | + } |
| 157 | + // Else do a normal api request : |
| 158 | + return doApiRequest(); |
| 159 | + } |
189 | 160 | } |
190 | 161 | |
191 | 162 | /** |
— | — | @@ -225,6 +196,7 @@ |
226 | 197 | // We can't update src's so we have to remove and add all the time :( |
227 | 198 | // NOTE: we should support frame msg system |
228 | 199 | $j( '#frame_proxy' ).remove(); |
| 200 | + // NOTE we can't use jQuery buildout for iframes because IE throws away the "name" |
229 | 201 | $j( 'body' ).append( '<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' + |
230 | 202 | 'src="' + getServerFrame() + |
231 | 203 | '#' + escape( JSON.stringify( hashPack ) ) + |
— | — | @@ -232,10 +204,11 @@ |
233 | 205 | |
234 | 206 | // add an onLoad hook: |
235 | 207 | $j( '#frame_proxy' ).get( 0 ).onload = function() { |
236 | | - // Add a 15 second timeout for setting up the nested child callback (after page load) |
| 208 | + |
| 209 | + // Add a 10 second timeout for setting up the nested child callback (after page load) |
237 | 210 | |
238 | 211 | // NOTE: once we have a real entry point instead of ( mediaWiki:ApiProxy rewrite) |
239 | | - //this number can be reduced since it won't have to load all the style sheets and |
| 212 | + // this number can be reduced since it won't have to load all the style sheets and |
240 | 213 | // javascript for a normal page view |
241 | 214 | |
242 | 215 | setTimeout( function() { |
— | — | @@ -244,12 +217,84 @@ |
245 | 218 | mw.log( "Error:: api proxy timeout are we logged in? mwEmbed is on?" ); |
246 | 219 | proxyNotReadyDialog(); |
247 | 220 | } |
248 | | - }, 15000 ); |
| 221 | + }, 10000 ); |
249 | 222 | } |
250 | 223 | } |
251 | | - |
252 | 224 | |
253 | 225 | /** |
| 226 | + * Validate an iframe request |
| 227 | + * checks the url hash for required paramaters |
| 228 | + * checks master_blacklist |
| 229 | + * checks master_whitelist |
| 230 | + */ |
| 231 | + function validateIframeRequest( proxyConfig ){ |
| 232 | + var clientRequest = false; |
| 233 | + |
| 234 | + |
| 235 | + var clientRequest = getClientRequest(); |
| 236 | + |
| 237 | + if ( !clientRequest || !clientRequest.clientFrame ) { |
| 238 | + mw.log( "Error: no client domain provided " ); |
| 239 | + $j( 'body' ).append( "no client frame provided" ); |
| 240 | + return false; |
| 241 | + } |
| 242 | + |
| 243 | + // Make sure we are logged in |
| 244 | + // (its a normal mediaWiki page so all site vars should be defined) |
| 245 | + if ( typeof wgUserName != 'undefined' && !wgUserName ) { |
| 246 | + mw.log( 'Error Not logged in' ); |
| 247 | + return false; |
| 248 | + } |
| 249 | + |
| 250 | + mw.log( "Setup server on: " + mw.parseUri( document.URL ).host ); |
| 251 | + mw.log('Client frame: ' + clientRequest.clientFrame ); |
| 252 | + |
| 253 | + var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ; |
| 254 | + |
| 255 | + /** |
| 256 | + * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig |
| 257 | + */ |
| 258 | + // Check master blacklist |
| 259 | + for ( var i in proxyConfig.master_blacklist ) { |
| 260 | + if ( clientDomain == proxyConfig.master_blacklist ) { |
| 261 | + mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' ); |
| 262 | + return false; |
| 263 | + } |
| 264 | + } |
| 265 | + // Check the master whitelist: |
| 266 | + for ( var i in proxyConfig.master_whitelist ) { |
| 267 | + if ( clientDomain == proxyConfig.master_whitelist[ i ] ) { |
| 268 | + return true; |
| 269 | + } |
| 270 | + } |
| 271 | + |
| 272 | + // FIXME Add in user based approval :: |
| 273 | + |
| 274 | + // FIXME offer the user the ability to "approve" requested domain save to |
| 275 | + // their user preference setup ) |
| 276 | + |
| 277 | + // FIXME grab the users whitelist for our current domain |
| 278 | + |
| 279 | + // Not a valid request return false |
| 280 | + return false; |
| 281 | + } |
| 282 | + |
| 283 | + /** |
| 284 | + * Get the client request from the document hash |
| 285 | + * @return {Object} the object result of parsing the document anchor msg |
| 286 | + */ |
| 287 | + function getClientRequest(){ |
| 288 | + // Read the anchor data package from the requesting url |
| 289 | + var hashMsg = unescape( mw.parseUri( document.URL ).anchor ); |
| 290 | + try { |
| 291 | + return JSON.parse( hashMsg ); |
| 292 | + } catch ( e ) { |
| 293 | + mw.log( "ProxyServer:: could not parse anchor" ); |
| 294 | + return false; |
| 295 | + } |
| 296 | + } |
| 297 | + |
| 298 | + /** |
254 | 299 | * Dialog to send the user if a proxy to the remote server could not be created |
255 | 300 | */ |
256 | 301 | function proxyNotReadyDialog() { |
— | — | @@ -261,7 +306,7 @@ |
262 | 307 | buttons[ gM( 'mwe-cancel' ) ] = function() { |
263 | 308 | mw.closeLoaderDialog(); |
264 | 309 | } |
265 | | - var pUri = mw.parseUri( currentApiUrl ); |
| 310 | + var pUri = mw.parseUri( getServerFrame() ); |
266 | 311 | |
267 | 312 | // FIXME we should have a Hosted page once we deploy mwEmbed on the servers. |
268 | 313 | // A hosted page would be much faster since than a normal page view rewrite |
— | — | @@ -293,8 +338,9 @@ |
294 | 339 | * Api iFrame request: |
295 | 340 | * @param {Object} requestObj Api request object |
296 | 341 | */ |
297 | | - function doApiRequest( clientRequest ) { |
298 | | - |
| 342 | + function doApiRequest( ) { |
| 343 | + // Get the client request |
| 344 | + var clientRequest = getClientRequest(); |
299 | 345 | // Make sure its a json format |
300 | 346 | clientRequest.request[ 'format' ] = 'json'; |
301 | 347 | |
— | — | @@ -309,6 +355,15 @@ |
310 | 356 | } |
311 | 357 | |
312 | 358 | /** |
| 359 | + * setup the browse file proxy. |
| 360 | + * |
| 361 | + * Sets the page content to browser file |
| 362 | + */ |
| 363 | + function doBrowseFile(){ |
| 364 | + |
| 365 | + } |
| 366 | + |
| 367 | + /** |
313 | 368 | * Outputs the result object to the client domain |
314 | 369 | * |
315 | 370 | * @param {clientFrame} clientFrame Client frame name |
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js |
— | — | @@ -1,4 +1,4 @@ |
2 | | -/* |
| 2 | +/** |
3 | 3 | * This file exposes some of the functionality of mwEmbed to wikis |
4 | 4 | * that do not yet have mwEmbed enabled |
5 | 5 | */ |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | } |
96 | 96 | |
97 | 97 | |
98 | | - // Firefogg integration |
| 98 | + // Upload page integration |
99 | 99 | if ( wgPageName == "Special:Upload" ) { |
100 | 100 | loadMwEmbed([ |
101 | 101 | 'mw.BaseUploadInterface', |
— | — | @@ -117,6 +117,15 @@ |
118 | 118 | } ); |
119 | 119 | } |
120 | 120 | |
| 121 | + // Special api browse for file proxy page |
| 122 | + if ( wgPageName == 'MediaWiki:ApiProxyBrowserFile' ) { |
| 123 | + var wgEnableIframeApiProxy = true; |
| 124 | + loadMwEmbed( [ 'mw.proxy' ], function() { |
| 125 | + mwApiProxyConfig[ 'browserFile' ] = true; |
| 126 | + mw.load( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() ); |
| 127 | + } ); |
| 128 | + } |
| 129 | + |
121 | 130 | // OggHandler rewrite for view pages: |
122 | 131 | var vidIdList = []; |
123 | 132 | var divs = document.getElementsByTagName( 'div' ); |
— | — | @@ -401,12 +410,12 @@ |
402 | 411 | return false; |
403 | 412 | } |
404 | 413 | |
405 | | - for( var i = 0 ; i < scripts.length ; i ++){ |
| 414 | + for( var i = 0 ; i < scripts.length ; i++ ){ |
406 | 415 | if ( |
407 | 416 | scripts[i].src |
408 | 417 | && scripts[i].src.indexOf( 'MediaWiki:Gadget-mwEmbed.js' ) !== -1 |
409 | 418 | ){ |
410 | | - mw.log('gadget already installed: ' + scripts[i].src); |
| 419 | + mw.log( 'gadget already installed: ' + scripts[i].src ); |
411 | 420 | // Gadget found / enabled |
412 | 421 | return false; |
413 | 422 | } |
— | — | @@ -418,7 +427,7 @@ |
419 | 428 | 'text' : gM( 'mwe-enable-gadget' ), |
420 | 429 | 'icon_id': 'check' |
421 | 430 | }) |
422 | | - .css({ |
| 431 | + .css({ |
423 | 432 | 'font-size': '90%' |
424 | 433 | }) |
425 | 434 | .buttonHover() |
— | — | @@ -442,7 +451,7 @@ |
443 | 452 | ) |
444 | 453 | .remove(); |
445 | 454 | // Load gadgets form: |
446 | | - mwSubmitgadgetPref( 'mwEmbed' ); |
| 455 | + mwSubmitGadgetPref( 'mwEmbed' ); |
447 | 456 | |
448 | 457 | // return false to not follow link |
449 | 458 | return false; |
— | — | @@ -459,7 +468,7 @@ |
460 | 469 | ) |
461 | 470 | ); |
462 | 471 | } |
463 | | -function mwSubmitgadgetPref( gadget_id ){ |
| 472 | +function mwSubmitGadgetPref( gadget_id ){ |
464 | 473 | $j.get( wgArticlePath.replace('$1', 'Special:Preferences'), function( pageHTML ){ |
465 | 474 | // get the form |
466 | 475 | var form = mwGetFormFromPage ( pageHTML ); |
Index: branches/js2-work/phase3/js/apiProxyPage.js |
— | — | @@ -1,4 +1,4 @@ |
2 | | -/* |
| 2 | +/** |
3 | 3 | * mwProxy js2 page system. |
4 | 4 | * |
5 | 5 | * Invokes the apiProxy system |
— | — | @@ -19,11 +19,16 @@ |
20 | 20 | var mwApiProxyDefaultConfig = { |
21 | 21 | 'master_whitelist' : [ 'en.wikipedia.org', 'localhost', '127.1.1.100' ], |
22 | 22 | 'master_blacklist' : [] |
23 | | -}; |
| 23 | +}; |
24 | 24 | |
| 25 | + |
25 | 26 | // User white_list should also be checked and configured at runtime. |
26 | 27 | mw.ready( function() { |
27 | 28 | mw.load( 'ApiProxy', function(){ |
| 29 | + |
| 30 | + //Clear out the page content ( not needed for iframe proxy ) |
| 31 | + $j( 'body' ).html( '' ); |
| 32 | + |
28 | 33 | // Build our configuration from the default and mwApiProxyConfig vars |
29 | 34 | mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig ); |
30 | 35 | mw.ApiProxy.server( mwApiProxyConfig ); |
Index: branches/js2-work/phase3/js/uploadPage.js |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | // An API URL (we won't submit directly to action of the form) |
21 | 21 | 'api_url': wgServer + wgScriptPath + '/api.php', |
22 | 22 | // MediaWiki API supports chunk uploads: |
23 | | - 'enable_chunks' : false, |
| 23 | + 'enable_chunks' : true, |
24 | 24 | 'form_selector': mwUploadFormSelector, |
25 | 25 | 'new_source_cb': function( orgFilename, oggName ) { |
26 | 26 | $j( '#wpDestFile' ).val( oggName ); |