Index: branches/js2-work/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js |
— | — | @@ -2025,8 +2025,10 @@ |
2026 | 2026 | }, |
2027 | 2027 | |
2028 | 2028 | /** |
2029 | | - * Sets up the proxy for the remote inserts |
2030 | | - */ |
| 2029 | + * Sets up the proxy for the remote inserts |
| 2030 | + * |
| 2031 | + * @param {Function} callbcak Function to call once proxy is setup. |
| 2032 | + */ |
2031 | 2033 | setupProxy: function( callback ) { |
2032 | 2034 | var _this = this; |
2033 | 2035 | |
— | — | @@ -2150,7 +2152,7 @@ |
2151 | 2153 | * get an edit Token |
2152 | 2154 | * depends on upload_api_target being initialized |
2153 | 2155 | * |
2154 | | - * @param {Function} callback Function to be called once the token is avaliable |
| 2156 | + * @param {Function} callback Function to be called once the token is available |
2155 | 2157 | */ |
2156 | 2158 | getEditToken: function( callback ) { |
2157 | 2159 | var _this = this; |
— | — | @@ -2252,7 +2254,7 @@ |
2253 | 2255 | * builds the wikitext represnetation and |
2254 | 2256 | * issues an api call to gennerate a preview |
2255 | 2257 | * |
2256 | | - * @param {Object} resource |
| 2258 | + * @param {Object} resource Resource to get preview text for. |
2257 | 2259 | */ |
2258 | 2260 | getPreviewText: function( resource ) { |
2259 | 2261 | var _this = this; |
— | — | @@ -2451,8 +2453,11 @@ |
2452 | 2454 | _this.setDisplayMode( 'list' ); |
2453 | 2455 | } ); |
2454 | 2456 | }, |
| 2457 | + |
2455 | 2458 | /** |
2456 | | - * Shows pagging for a given traget for a given currentProvider |
| 2459 | + * Shows pagging for a given target for a given currentProvider |
| 2460 | + * |
| 2461 | + * @param {String} target jQuery Selector for pagging Header output |
2457 | 2462 | */ |
2458 | 2463 | showPagingHeader: function( target ) { |
2459 | 2464 | var _this = this; |
— | — | @@ -2502,12 +2507,13 @@ |
2503 | 2508 | } ); |
2504 | 2509 | }, |
2505 | 2510 | |
2506 | | - /* |
2507 | | - * Select a given search provider |
| 2511 | + /** |
| 2512 | + * Select a given search provider |
| 2513 | + * @param {String} provider_id Provider id to select and display |
2508 | 2514 | */ |
2509 | | - selectTab: function( provider ) { |
2510 | | - js_log( 'select tab: ' + provider ); |
2511 | | - this.currentProvider = provider; |
| 2515 | + selectTab: function( provider_id ) { |
| 2516 | + js_log( 'select tab: ' + provider_id ); |
| 2517 | + this.currentProvider = provider_id; |
2512 | 2518 | if ( this.currentProvider == 'upload' ) { |
2513 | 2519 | this.showUploadTab(); |
2514 | 2520 | } else { |
— | — | @@ -2518,7 +2524,7 @@ |
2519 | 2525 | |
2520 | 2526 | /* |
2521 | 2527 | * Sets the dispaly mode |
2522 | | - * @param {String} either "box" or "list" |
| 2528 | + * @param {String} mode Either "box" or "list" |
2523 | 2529 | */ |
2524 | 2530 | setDisplayMode: function( mode ) { |
2525 | 2531 | js_log( 'setDisplayMode:' + mode ); |
Index: branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js |
— | — | @@ -2580,10 +2580,10 @@ |
2581 | 2581 | /** |
2582 | 2582 | * Getter for Stoped state |
2583 | 2583 | * @return {Boolean} |
2584 | | - * true if playing |
2585 | | - * false if not playing |
| 2584 | + * true if stopped |
| 2585 | + * false if playing |
2586 | 2586 | */ |
2587 | | - isStoped : function() { |
| 2587 | + isStoped: function() { |
2588 | 2588 | return this.thumbnail_disp; |
2589 | 2589 | }, |
2590 | 2590 | |
— | — | @@ -2592,7 +2592,7 @@ |
2593 | 2593 | * Monitor playback and update interface components. |
2594 | 2594 | * underling plugin objects are responsible for updating currentTime |
2595 | 2595 | */ |
2596 | | - monitor:function() { |
| 2596 | + monitor: function() { |
2597 | 2597 | var _this = this; |
2598 | 2598 | //js_log(' ct: ' + this.currentTime + ' dur: ' + ( parseInt( this.duration ) + 1 ) + ' is seek: ' + this.seeking ); |
2599 | 2599 | if ( this.currentTime && this.currentTime > 0 && this.duration ) { |
Index: branches/js2-work/phase3/js2/mwEmbed/tests/testApiProxy.html |
— | — | @@ -3,7 +3,7 @@ |
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"></script> |
| 7 | +<script type="text/javascript" src="../mwEmbed.js?debug=true"></script> |
8 | 8 | |
9 | 9 | <script type="text/javascript" > |
10 | 10 | //HARD coded local test: |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | 'client', |
19 | 19 | { |
20 | 20 | 'server_frame': remote_wiki_host + remote_script_path + '/index.php/MediaWiki:ApiProxy', |
21 | | - 'client_frame_path' : '/wiki_trunk/js2/mwEmbed/libMwApi/NestedCallbackIframe.html', |
| 21 | + 'client_frame_path' : mw.getMwEmbedPath() + 'libMwApi/NestedCallbackIframe.html', |
22 | 22 | }, |
23 | 23 | function(){ |
24 | 24 | //callback function here: |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | 'meta':'userinfo' |
44 | 44 | } |
45 | 45 | //we use normal do_api_req with keywork 'proxy' for the url |
46 | | - $mw.proxy.doRequest( rObj, |
| 46 | + mw.proxy.doRequest( rObj, |
47 | 47 | function( data ){ |
48 | 48 | //now we get the data back for that domain |
49 | 49 | if( !data.query || !data.query.userinfo ){ |
Index: branches/js2-work/phase3/js2/mwEmbed/libMwApi/NestedCallbackIframe.html |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | <script type="text/javascript"> |
8 | 8 | window.onload = function (){ |
9 | 9 | //call the nested callback in top most frame: |
10 | | - top.$mw.proxy.nested( window.location.href.split("#")[1] || false ); |
| 10 | + top.mw.proxy.nested( window.location.href.split("#")[1] || false ); |
11 | 11 | } |
12 | 12 | </script> |
13 | 13 | </head> |
Index: branches/js2-work/phase3/js2/mwEmbed/libMwApi/mw.proxy.js |
— | — | @@ -52,9 +52,11 @@ |
53 | 53 | $.proxy = { }; |
54 | 54 | |
55 | 55 | /** |
56 | | - * The client setup function: |
| 56 | + * The client setup function: |
| 57 | + * |
| 58 | + * @param {Object} proxyConfig Holds the server_frame & client_frame_path vars |
57 | 59 | */ |
58 | | - $.proxy.client = function( proxyConfig, conf ) { |
| 60 | + $.proxy.client = function( proxyConfig ) { |
59 | 61 | var _this = this; |
60 | 62 | // Do client setup: |
61 | 63 | if ( proxyConfig.server_frame ) |
— | — | @@ -63,8 +65,9 @@ |
64 | 66 | if ( proxyConfig.client_frame_path ) { |
65 | 67 | $.proxy.client_frame_path = proxyConfig.client_frame_path; |
66 | 68 | } else { |
67 | | - // Set to default mwEmbed iframe path: |
68 | | - $.proxy.client_frame_path = wgScriptPath + '/js2/mwEmbed/libMwApi/NestedCallbackIframe.html'; |
| 69 | + // Set to default via mediaWiki vars: |
| 70 | + |
| 71 | + $.proxy.client_frame_path = wgServer + wgScriptPath + '/js2/mwEmbed/libMwApi/NestedCallbackIframe.html'; |
69 | 72 | } |
70 | 73 | |
71 | 74 | if ( mw.parseUri( $.proxy.server_frame ).host == mw.parseUri( document.URL ).host ) { |
— | — | @@ -77,18 +80,22 @@ |
78 | 81 | var frameProxyOk = false; |
79 | 82 | |
80 | 83 | /** |
81 | | - * doFrameProxy |
| 84 | + * Does the frame proxy |
82 | 85 | * Writes an iframe with a hashed value of the requestQuery |
| 86 | + * |
| 87 | + * @param {Object} requestQuery The api request object |
83 | 88 | */ |
84 | 89 | $.proxy.doFrameProxy = function( requestQuery ) { |
| 90 | + |
85 | 91 | var hashPack = { |
86 | | - 'cd': mw.parseUri( document.URL ).host, |
87 | | - 'cfp': $.proxy.client_frame_path, |
88 | | - 'req': requestQuery |
| 92 | + // Client domain: |
| 93 | + 'clientFrame' : $.proxy.client_frame_path, |
| 94 | + 'request' : requestQuery |
89 | 95 | } |
90 | | - js_log( "Do frame proxy request on src: \n" + $.proxy.server_frame + "\n" + |
91 | | - JSON.stringify( requestQuery ) ); |
92 | | - // we can't update src's so we have to remove and add all the time :( |
| 96 | + |
| 97 | + js_log( "Do frame proxy request on src: \n" + $.proxy.server_frame + "\n" + JSON.stringify( requestQuery ) ); |
| 98 | + |
| 99 | + // We can't update src's so we have to remove and add all the time :( |
93 | 100 | // @@todo we should support frame msg system |
94 | 101 | $j( '#frame_proxy' ).remove(); |
95 | 102 | $j( 'body' ).append( '<iframe style="display:none" id="frame_proxy" name="frame_proxy" ' + |
— | — | @@ -109,6 +116,10 @@ |
110 | 117 | } |
111 | 118 | } |
112 | 119 | var lastApiReq = { }; |
| 120 | + |
| 121 | + /** |
| 122 | + * Dialog to send the user if a proxy to the remote server could not be created |
| 123 | + */ |
113 | 124 | $.proxy.proxyNotReadyDialog = function() { |
114 | 125 | var buttons = { }; |
115 | 126 | buttons[ gM( 'mwe-re-try' ) ] = function() { |
— | — | @@ -135,20 +146,28 @@ |
136 | 147 | buttons |
137 | 148 | ) |
138 | 149 | } |
139 | | - /* |
140 | | - * doRequest |
| 150 | + /** |
141 | 151 | * Takes a requestQuery, executes the query and then calls the callback |
| 152 | + * sets the local callback to be called once requestQuery completes |
| 153 | + * |
| 154 | + * @param {Object} requestQuery Api request object |
| 155 | + * @param {Function} callback Function called once the request is complete |
142 | 156 | */ |
143 | 157 | $.proxy.doRequest = function( requestQuery, callback ) { |
144 | | - js_log( "doRequest:: " + JSON.stringify( reqObj ) ); |
145 | | - lastApiReq = reqObj; |
| 158 | + js_log( "doRequest:: " + JSON.stringify( requestQuery ) ); |
| 159 | + lastApiReq = requestQuery; |
146 | 160 | // setup the callback: |
147 | 161 | $.proxy.callback = callback; |
148 | 162 | // do the proxy req: |
149 | 163 | $.proxy.doFrameProxy( requestQuery ); |
150 | 164 | } |
| 165 | + |
151 | 166 | /** |
152 | | - * The nested iframe action that passes its result back up to the top frame instance |
| 167 | + * The nested iframe action that passes its result back up to the top frame instance |
| 168 | + * |
| 169 | + * Entry point for hashResult from nested iframe |
| 170 | + * |
| 171 | + * @param {Object} hashResult Value to be sent to parent frame |
153 | 172 | */ |
154 | 173 | $.proxy.nested = function( hashResult ) { |
155 | 174 | // Close the loader if present: |
— | — | @@ -156,114 +175,140 @@ |
157 | 176 | js_log( '$.proxy.nested callback :: ' + unescape( hashResult ) ); |
158 | 177 | frameProxyOk = true; |
159 | 178 | |
160 | | - // Try to parse the hash result: |
| 179 | + // Try to parse the hash result |
161 | 180 | try { |
162 | | - var rObj = JSON.parse( unescape( hashResult ) ); |
| 181 | + var resultObject = JSON.parse( unescape( hashResult ) ); |
163 | 182 | } catch ( e ) { |
164 | 183 | js_log( "Error could not parse hashResult" ); |
165 | 184 | } |
166 | 185 | |
167 | 186 | // Special callback to frameProxyOk flag |
168 | 187 | // (only used to test the proxy connection) |
169 | | - if ( rObj.state == 'ok' ) |
| 188 | + if ( resultObject.state == 'ok' ) |
170 | 189 | return ; |
171 | 190 | |
172 | | - // Pass the callback: |
173 | | - $.proxy.callback( rObj ); |
| 191 | + // Pass the result object to the callback: |
| 192 | + $.proxy.callback( resultObject ); |
174 | 193 | } |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
175 | 199 | /** |
176 | | - * The server handles the actual proxy |
177 | | - * it adds child frames pointing to the parent "blank" frames |
178 | | - * |
179 | | - * This is (Domain B) in the above described setup |
180 | | - */ |
181 | | - $.proxy.server = function( proxyConfig, callback ) { |
182 | | - /* clear the body of any html */ |
183 | | - $j( 'body' ).html( 'proxy setup' ); |
| 200 | + * API iFrame Server:: |
| 201 | + * |
| 202 | + * Handles the server side proxy of requests |
| 203 | + * it adds child frames pointing to the parent "blank" frames |
| 204 | + */ |
| 205 | + |
| 206 | + /** |
| 207 | + * Api iFrame request: |
| 208 | + * @param {Object} requestObj Api request object |
| 209 | + */ |
| 210 | + function doApiRequest( clientRequest ) { |
| 211 | + |
| 212 | + // Make sure its a json format |
| 213 | + clientRequest.request[ 'format' ] = 'json'; |
| 214 | + |
| 215 | + // Process the API request. We don't use mw.apiReq since we need to "post" |
| 216 | + $j.post( wgScriptPath + '/api' + wgScriptExtension, |
| 217 | + clientRequest.request, |
| 218 | + function( data ) { |
| 219 | + // Put it result into nested frame hash string: |
| 220 | + outputResultsFrame( clientRequest.clientFrame, 'nested_push', JSON.parse( data ) ); |
| 221 | + } |
| 222 | + ); |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Outputs the result object to the client domain |
| 227 | + * |
| 228 | + * @param {String} nestName Name of iframe |
| 229 | + * @param {resultObj} the result to pass back to the client domain |
| 230 | + */ |
| 231 | + function outputResultsFrame( clientFrame, nestName, resultObj ) { |
| 232 | + $j( '#nested_push' ).remove(); |
| 233 | + // Setup the nested iframe proxy that points back to top domain: |
| 234 | + $j( 'body' ).append( |
| 235 | + $j('<iframe>').attr({ |
| 236 | + 'id' : nestName, |
| 237 | + 'name' : nestName, |
| 238 | + 'src' : clientFrame + '#' + escape( JSON.stringify( resultObj ) ) |
| 239 | + }) |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * Api server proxy entry point: |
| 245 | + * |
| 246 | + * @param {Object} proxyConfig The server side proxy configuration |
| 247 | + * @param {Function} callbcak Function to call once server is setup |
| 248 | + * |
| 249 | + */ |
| 250 | + $.proxy.server = function( proxyConfig, callback ) { |
| 251 | + /** |
| 252 | + * Clear the body of any html |
| 253 | + */ |
| 254 | + $j( 'body' ).html( 'Proxy Setup: ' ); |
184 | 255 | |
185 | | - // read the anchor action from the requesting url |
186 | | - var jmsg = unescape( mw.parseUri( document.URL ).anchor ); |
| 256 | + var clientRequest = false; |
| 257 | + |
| 258 | + // Read the anchor action from the requesting url |
| 259 | + var hashMsg = unescape( mw.parseUri( document.URL ).anchor ); |
187 | 260 | try { |
188 | | - var aObj = JSON.parse( jmsg ); |
| 261 | + var clientRequest = JSON.parse( hashMsg ); |
189 | 262 | } catch ( e ) { |
190 | 263 | js_log( "ProxyServer:: could not parse anchor" ); |
191 | 264 | } |
192 | | - if ( !aObj.cd ) { |
| 265 | + |
| 266 | + if ( !clientRequest || !clientRequest.clientFrame ) { |
193 | 267 | js_log( "Error: no client domain provided " ); |
| 268 | + $j( 'body' ).append( "no client frame provided" ); |
194 | 269 | return false; |
195 | | - } |
| 270 | + } |
196 | 271 | |
197 | | - js_log( "Setup server on: " + mw.parseUri( document.URL ).host + |
198 | | - ' client from: ' + aObj.cd + |
199 | | - ' to nested target: ' + aObj.cfp ); |
200 | | - |
201 | 272 | // Make sure we are logged in |
202 | 273 | // (its a normal mediaWiki page so all site vars should be defined) |
203 | 274 | if ( !wgUserName ) { |
204 | 275 | js_log( 'Error Not logged in' ); |
205 | 276 | return false; |
206 | 277 | } |
207 | | - |
208 | | - var domain = aObj.cd; |
209 | | - var nested_frame_src = 'http://' + aObj.cd + aObj.cfp; |
210 | | - // Check the master whitelist |
| 278 | + |
| 279 | + js_log( "Setup server on: " + mw.parseUri( document.URL ).host ); |
| 280 | + js_log('Client frame: ' + clientRequest.clientFrame ); |
| 281 | + |
| 282 | + var clientDomain = mw.parseUri( clientRequest.clientFrame ).host ; |
| 283 | + /** |
| 284 | + * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig |
| 285 | + */ |
| 286 | + // Check the master whitelist: |
211 | 287 | for ( var i in proxyConfig.master_whitelist ) { |
212 | | - if ( domain == proxyConfig.master_whitelist[ i ] ) { |
| 288 | + if ( clientDomain == proxyConfig.master_whitelist[ i ] ) { |
213 | 289 | // Do the request: |
214 | | - return doNestedProxy( aObj.req ); |
| 290 | + return doApiRequest( clientRequest ); |
215 | 291 | } |
216 | 292 | } |
217 | 293 | // Check master blacklist |
218 | 294 | for ( var i in proxyConfig.master_blacklist ) { |
219 | | - if ( domain == proxyConfig.master_blacklist ) { |
220 | | - js_log( 'domain: ' + domain + ' is blacklisted' ); |
| 295 | + if ( clientDomain == proxyConfig.master_blacklist ) { |
| 296 | + js_log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' ); |
221 | 297 | return false; |
222 | 298 | } |
223 | 299 | } |
| 300 | + // FIXME Add in user based approval :: |
| 301 | + |
| 302 | + // offer the user the ability to "approve" requested domain save to |
| 303 | + // their user/ apiProxyDomainList.js page |
| 304 | + |
224 | 305 | // FIXME grab the users whitelist for our current domain |
225 | 306 | /*var local_api = wgScriptPath + '/index' + wgScriptExtension + '?title=' + |
226 | 307 | 'User:' + wgUserName + '/apiProxyDomainList.js' + |
227 | 308 | '&action=raw&smaxage=0&gen=js'; |
228 | 309 | $j.get( local_api, function( data ){ |
229 | 310 | debugger; |
230 | | - });*/ |
231 | | - |
232 | | - // if still not found: |
233 | | - js_log( "domain " + domain + " not approved" ); |
234 | | - |
235 | | - // FIXME :: offer the user the ability to "approve" requested domain save to |
236 | | - // their user/ apiProxyDomainList.js page |
237 | | - |
238 | | - function doNestedProxy( reqObj ) { |
239 | | - js_log( "doNestedProxy to: " + nested_frame_src ); |
240 | | - |
241 | | - // Do a quick response to establish the proxy is working |
242 | | - // ( before we actually run the api-request ) |
243 | | - doNestedFrame ( 'nested_ok' , { 'state':'ok' } ); |
244 | | - |
245 | | - var outputhash = escape( JSON.stringify( reqObj ) ); |
246 | | - |
247 | | - // Add some api stuff: |
248 | | - reqObj[ 'format' ] = 'json'; |
249 | | - |
250 | | - // Process the api request |
251 | | - $j.post( wgScriptPath + '/api' + wgScriptExtension, |
252 | | - reqObj, |
253 | | - function( data ) { |
254 | | - // Put it into the nested frame hash string: |
255 | | - doNestedFrame( 'nested_push', JSON.parse( data ) ); |
256 | | - } |
257 | | - ); |
258 | | - } |
259 | | - // Add the doNestedFrame iframe: |
260 | | - function doNestedFrame( nestname, resultObj ) { |
261 | | - $j( '#nested_push' ).remove(); |
262 | | - // Setup the nested proxy that points back to top domain: |
263 | | - $j( 'body' ).append( '<iframe id="nested_push" name="nested_push" ' + |
264 | | - 'src="' + nested_frame_src + |
265 | | - '#' + escape( JSON.stringify( resultObj ) ) + |
266 | | - '"></iframe>' ); |
267 | | - } |
| 311 | + });*/ |
| 312 | + |
268 | 313 | } |
269 | 314 | |
270 | 315 | } )( window.mw ); |
Index: branches/js2-work/phase3/js2/mwEmbed/skins/ctrlBuilder.js |
— | — | @@ -1,7 +1,9 @@ |
2 | 2 | |
3 | | -// Set the global dismissNativeWarn flag: |
4 | | -_global['dismissNativeWarn'] = false; |
| 3 | +// Set the dismiss_playback_warning flag config |
| 4 | +// Set via config so a dismiss on one video embed applies to all video embeds. |
| 5 | +mw.setConfig( 'dismiss_playback_warning', false ); |
5 | 6 | |
| 7 | + |
6 | 8 | /** |
7 | 9 | * Msg text is inherited from embedPlayer |
8 | 10 | */ |
— | — | @@ -143,19 +145,19 @@ |
144 | 146 | $j( '#ffwarn_' + embedObj.id ).click( function() { |
145 | 147 | if ( $j( this ).is( ':checked' ) ) { |
146 | 148 | // set up a cookie for 7 days: |
147 | | - $j.cookie( 'dismissNativeWarn', true, { expires: 7 } ); |
| 149 | + $j.cookie( 'dismiss_playback_warning', true, { expires: 7 } ); |
148 | 150 | // set the current instance |
149 | | - _global['dismissNativeWarn'] = true; |
| 151 | + mw.setConfig( 'dismiss_playback_warning', true ); |
150 | 152 | $j( '#gnp_' + embedObj.id ).fadeOut( 'slow' ); |
151 | 153 | } else { |
152 | | - _global['adismissNativeWarn'] = false; |
153 | | - $j.cookie( 'dismissNativeWarn', false ); |
| 154 | + mw.setConfig( 'dismiss_playback_warning', false ); |
| 155 | + $j.cookie( 'dismiss_playback_warning', false ); |
154 | 156 | } |
155 | 157 | |
156 | 158 | } ); |
157 | 159 | } |
158 | | - if ( ( $j.cookie( 'dismissNativeWarn' ) !== true ) && |
159 | | - _global['dismissNativeWarn'] === false ) { |
| 160 | + if ( ( $j.cookie( 'dismiss_playback_warning' ) !== true ) && |
| 161 | + mw.getConfig( 'dismiss_playback_warning' ) === false ) { |
160 | 162 | $j( '#gnp_' + embedObj.id ).fadeIn( 'slow' ); |
161 | 163 | } |
162 | 164 | }, |
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Default global config values. Configuration values are set via mw.setConfig |
36 | | -* Configuration values should genneraly be set prior to dom-ready |
| 36 | +* Configuration values should generaly be set prior to dom-ready |
37 | 37 | */ |
38 | 38 | var mwDefaultConf = { |
39 | 39 | // Default skin name |
— | — | @@ -749,69 +749,9 @@ |
750 | 750 | * @key Name of the class |
751 | 751 | * @value Style sheet path |
752 | 752 | */ |
753 | | - stylePaths : { }, |
| 753 | + stylePaths : { }, |
754 | 754 | |
755 | | - |
756 | 755 | /** |
757 | | - * Load a set of scripts. |
758 | | - * Will issue many load requests or package the request for the script-loader |
759 | | - * |
760 | | - * @param {Object} loadSet Set of scripts to be loaded |
761 | | - * @param {Function} callback Function to call once all scripts are loaded. |
762 | | - */ |
763 | | - loadMany: function( loadSet, callback ){ |
764 | | - //Setup up the local "loadState" |
765 | | - var loadState = { }; |
766 | | - // Check if its a dependency set ( nested objects ) |
767 | | - if( typeof loadSet [ 0 ] == 'object' ){ |
768 | | - //Load sets of classes ( to preserver order for some browsers ) |
769 | | - this.loadDependencyChain( loadSet, callback ); |
770 | | - return ; |
771 | | - } |
772 | | - |
773 | | - // Set the initial load state for every item in the loadSet |
774 | | - for( var i in loadSet ){ |
775 | | - var loadName = loadSet[ i ]; |
776 | | - loadState[ loadName ] = 0; |
777 | | - } |
778 | | - |
779 | | - // Issue the load request check check loadState to see if we are "done" |
780 | | - for( var i in loadSet ){ |
781 | | - var loadName = loadSet[ i ]; |
782 | | - $.load( loadName, function ( loadName ){ |
783 | | - loadState[ loadName ] = 1; |
784 | | - |
785 | | - var loadDone = true; |
786 | | - for( var j in loadState ){ |
787 | | - if( loadState[ j ] === 0 ) |
788 | | - loadDone = false; |
789 | | - } |
790 | | - // Run the parent scope callback for "loadMany" |
791 | | - if( loadDone ) |
792 | | - callback(); |
793 | | - } ); |
794 | | - } |
795 | | - }, |
796 | | - |
797 | | - /** |
798 | | - * Load a sets of scripts satisfy dependency order for browsers that execute out of order |
799 | | - * |
800 | | - * @param {Object} loadChain A set of javascript arrays to be loaded. |
801 | | - * Sets are requested in array order. |
802 | | - */ |
803 | | - loadDependencyChain: function( loadChain, callback ){ |
804 | | - var _this = this; |
805 | | - // Load with dependency checks |
806 | | - this.load( loadChain.shift(), function() { |
807 | | - if ( loadChain.length != 0 ) { |
808 | | - _this.loadDependencyChain( loadChain, callback ); |
809 | | - } else { |
810 | | - callback(); |
811 | | - } |
812 | | - } ); |
813 | | - }, |
814 | | - |
815 | | - /** |
816 | 756 | * Core load function: |
817 | 757 | * |
818 | 758 | * @param {Mixed} loadRequest: |
— | — | @@ -873,7 +813,71 @@ |
874 | 814 | js_log( "Error could not handle load request" ); |
875 | 815 | }, |
876 | 816 | |
| 817 | + |
877 | 818 | /** |
| 819 | + * Load a set of scripts. |
| 820 | + * Will issue many load requests or package the request for the script-loader |
| 821 | + * |
| 822 | + * @param {Object} loadSet Set of scripts to be loaded |
| 823 | + * @param {Function} callback Function to call once all scripts are loaded. |
| 824 | + */ |
| 825 | + loadMany: function( loadSet, callback ){ |
| 826 | + |
| 827 | + //Setup up the local "loadState" |
| 828 | + var loadState = { }; |
| 829 | + |
| 830 | + // Check if its a dependency set ( nested objects ) |
| 831 | + if( typeof loadSet [ 0 ] == 'object' ){ |
| 832 | + //Load sets of classes ( to preserver order for some browsers ) |
| 833 | + this.loadDependencyChain( loadSet, callback ); |
| 834 | + return ; |
| 835 | + } |
| 836 | + |
| 837 | + // Set the initial load state for every item in the loadSet |
| 838 | + for( var i in loadSet ){ |
| 839 | + var loadName = loadSet[ i ]; |
| 840 | + loadState[ loadName ] = 0; |
| 841 | + } |
| 842 | + |
| 843 | + // Issue the load request check check loadState to see if we are "done" |
| 844 | + for( var i in loadSet ){ |
| 845 | + var loadName = loadSet[ i ]; |
| 846 | + $.load( loadName, function ( loadName ){ |
| 847 | + loadState[ loadName ] = 1; |
| 848 | + |
| 849 | + var loadDone = true; |
| 850 | + for( var j in loadState ){ |
| 851 | + if( loadState[ j ] === 0 ) |
| 852 | + loadDone = false; |
| 853 | + } |
| 854 | + |
| 855 | + // Run the parent scope callback for "loadMany" |
| 856 | + if( loadDone ) |
| 857 | + callback(); |
| 858 | + } ); |
| 859 | + } |
| 860 | + }, |
| 861 | + |
| 862 | + /** |
| 863 | + * Load a sets of scripts satisfy dependency order for browsers that execute out of order |
| 864 | + * |
| 865 | + * @param {Object} loadChain A set of javascript arrays to be loaded. |
| 866 | + * Sets are requested in array order. |
| 867 | + */ |
| 868 | + loadDependencyChain: function( loadChain, callback ){ |
| 869 | + var _this = this; |
| 870 | + // Load with dependency checks |
| 871 | + this.load( loadChain.shift(), function() { |
| 872 | + if ( loadChain.length != 0 ) { |
| 873 | + _this.loadDependencyChain( loadChain, callback ); |
| 874 | + } else { |
| 875 | + callback(); |
| 876 | + } |
| 877 | + } ); |
| 878 | + }, |
| 879 | + |
| 880 | + |
| 881 | + /** |
878 | 882 | * Loads javascript associated with a className |
879 | 883 | * |
880 | 884 | * @param {String} className Name of class to load |
— | — | @@ -884,7 +888,7 @@ |
885 | 889 | // Make sure the class is not already defined: |
886 | 890 | if ( $.isset( className ) ){ |
887 | 891 | js_log( 'Class ( ' + className + ' ) already defined ' ); |
888 | | - callback(); |
| 892 | + callback( className ); |
889 | 893 | return ; |
890 | 894 | } |
891 | 895 | |
— | — | @@ -1269,7 +1273,7 @@ |
1270 | 1274 | url += '?' + mw.getUrlParam(); |
1271 | 1275 | } |
1272 | 1276 | |
1273 | | - // Return if style sheet is already included: |
| 1277 | + // Check if style sheet is already included: |
1274 | 1278 | var foundSheet = false; |
1275 | 1279 | $j( 'link' ).each( function(){ |
1276 | 1280 | if( $j( this) .attr( 'href' ) == url ) |
— | — | @@ -2059,21 +2063,21 @@ |
2060 | 2064 | * |
2061 | 2065 | * @param mode is either 'server' or 'client' |
2062 | 2066 | */ |
2063 | | - $.apiProxy = function( mode, pConf, callback ) { |
| 2067 | + $.apiProxy = function( mode, proxyConfig, callback ) { |
2064 | 2068 | js_log( 'do apiProxy setup' ); |
2065 | 2069 | mw.load( [ |
2066 | 2070 | 'mw.proxy', |
2067 | 2071 | 'JSON' |
2068 | | - ], function() { |
| 2072 | + ], function() { |
2069 | 2073 | // do the proxy setup or |
2070 | 2074 | if ( mode == 'client' ) { |
2071 | 2075 | // just do the setup (no callbcak for client setup) |
2072 | | - mw.proxy.client( pConf ); |
| 2076 | + mw.proxy.client( proxyConfig ); |
2073 | 2077 | if ( callback ) |
2074 | 2078 | callback(); |
2075 | 2079 | } else if ( mode == 'server' ) { |
2076 | | - // do the request with the callback |
2077 | | - mw.proxy.server( pConf , callback ); |
| 2080 | + // Do the request with the callback |
| 2081 | + mw.proxy.server( proxyConfig , callback ); |
2078 | 2082 | } |
2079 | 2083 | } ); |
2080 | 2084 | } |
— | — | @@ -2440,6 +2444,7 @@ |
2441 | 2445 | } |
2442 | 2446 | return new_url; |
2443 | 2447 | } |
| 2448 | + |
2444 | 2449 | /** |
2445 | 2450 | * Given a float number of seconds, returns npt format response. |
2446 | 2451 | * |
— | — | @@ -2692,7 +2697,7 @@ |
2693 | 2698 | * Utility functions |
2694 | 2699 | */ |
2695 | 2700 | function js_log( string ) { |
2696 | | - // Add any prepend debug strings if necessary (used for cross browser) |
| 2701 | + // Add any prepend debug strings if necessary |
2697 | 2702 | if ( mw.getConfig( 'pre-append-log' ) ) |
2698 | 2703 | string = mw.getConfig( 'pre-append-log' ) + string; |
2699 | 2704 | |
Index: branches/js2-work/phase3/js2/apiProxyPage.js |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | * Since this is proxy server set a pre-append debug flag to know which debug msgs are coming from where |
10 | 10 | */ |
11 | 11 | |
12 | | -mw.getConfig( 'pre-append-log' ) = 'Proxy'; |
| 12 | +mw.setConfig( 'pre-append-log', 'Proxy:'); |
13 | 13 | |
14 | 14 | if ( !mwApiProxyConfig ) |
15 | 15 | var mwApiProxyConfig = { }; |
— | — | @@ -16,13 +16,15 @@ |
17 | 17 | // The default mwApiProxyConfig config |
18 | 18 | // (presently hard coded but should read from user and site config) |
19 | 19 | var mwApiProxyDefaultConfig = { |
20 | | - 'master_whitelist' : [ 'en.wikipedia.org', 'localhost', '127.1.1.100' ], |
21 | | - 'master_blacklist' : [] |
| 20 | + 'master_whitelist' : [ 'en.wikipedia.org', 'localhost', '127.1.1.100' ], |
| 21 | + 'master_blacklist' : [] |
22 | 22 | }; |
23 | 23 | |
24 | 24 | // User white_list should also be checked and configured at runtime. |
25 | 25 | mw.addOnloadHook( function() { |
26 | | - // build our configuration from the default and mwApiProxyConfig vars |
| 26 | + |
| 27 | + // Build our configuration from the default and mwApiProxyConfig vars |
27 | 28 | mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig ); |
28 | 29 | $j.apiProxy( 'server', mwApiProxyConfig ); |
| 30 | + |
29 | 31 | } ); |
Index: branches/js2-work/phase3/js2/remoteMwEmbed.js |
— | — | @@ -28,14 +28,14 @@ |
29 | 29 | // Add media wizard |
30 | 30 | if ( wgAction == 'edit' || wgAction == 'submit' ) { |
31 | 31 | var jsSetEdit = [ 'remoteSearchDriver', '$j.fn.textSelection', '$j.ui', '$j.ui.sortable' ] |
32 | | - mwr_load_mwEmbed( jsSetEdit, function() { |
| 32 | + loadMwEmbed( jsSetEdit, function() { |
33 | 33 | loadExternalJs( mwEmbedHostPath + '/editPage.js?' + mwGetReqArgs() ); |
34 | 34 | } ); |
35 | 35 | } |
36 | 36 | |
37 | 37 | // Timed text display: |
38 | 38 | if ( wgPageName.indexOf( "TimedText" ) === 0 ) { |
39 | | - mwr_load_mwEmbed( function() { |
| 39 | + loadMwEmbed( function() { |
40 | 40 | // Load with mw loader to get localized interface: |
41 | 41 | mw.load( ['mvTimeTextEdit'], function() { |
42 | 42 | // Could run init here (but mvTimeTextEdit already included onLoad actions) |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | if ( wgPageName == "Special:Upload" ) { |
49 | 49 | var jsSetUpload = [ 'mvBaseUploadInterface', 'mvFirefogg' , '$j.ui', |
50 | 50 | '$j.ui.progressbar', '$j.ui.dialog', '$j.ui.draggable' ]; |
51 | | - mwr_load_mwEmbed( jsSetUpload, function() { |
| 51 | + loadMwEmbed( jsSetUpload, function() { |
52 | 52 | loadExternalJs( mwEmbedHostPath + '/uploadPage.js?' + mwGetReqArgs() ); |
53 | 53 | } ); |
54 | 54 | } |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | // Special api proxy page |
57 | 57 | if ( wgPageName == 'MediaWiki:ApiProxy' ) { |
58 | 58 | var wgEnableIframeApiProxy = true; |
59 | | - mwr_load_mwEmbed( [ 'mw.proxy' ], function() { |
| 59 | + loadMwEmbed( [ 'mw.proxy' ], function() { |
60 | 60 | loadExternalJs( mwEmbedHostPath + '/apiProxyPage.js?' + mwGetReqArgs() ); |
61 | 61 | } ); |
62 | 62 | } |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | if ( navigator.userAgent && navigator.userAgent.indexOf("Firefox") != -1 ) |
80 | 80 | jsSetVideo.push( 'nativeEmbed' ); |
81 | 81 | |
82 | | - mwr_load_mwEmbed( jsSetVideo, function() { |
| 82 | + loadMwEmbed( jsSetVideo, function() { |
83 | 83 | mvJsLoader.embedPlayerCheck( function() { |
84 | 84 | // Do utility rewrite of OggHandler content: |
85 | 85 | rewrite_for_OggHandler( vidIdList ); |
— | — | @@ -197,14 +197,17 @@ |
198 | 198 | return rurl; |
199 | 199 | } |
200 | 200 | /** |
| 201 | +* Load the mwEmbed library: |
| 202 | +* |
201 | 203 | * @param {mixed} function or classSet to preload |
202 | 204 | * classSet saves round trips to the server by grabbing things we will likely need in the first request. |
203 | 205 | * ( this is essentially a shortcut to mv_jqueryBindings in mwEmbed.js ) |
204 | 206 | * @param {callback} function callback to be called once mwEmbed is ready |
205 | 207 | */ |
206 | | -function mwr_load_mwEmbed( classSet, callback ) { |
| 208 | +function loadMwEmbed( classSet, callback ) { |
207 | 209 | if( typeof classSet == 'function') |
208 | 210 | callback = classSet; |
| 211 | + |
209 | 212 | // Inject mwEmbed if needed |
210 | 213 | if ( typeof mw == 'undefined' ) { |
211 | 214 | if ( ( mwReqParam['uselang'] || mwReqParam['useloader'] ) && mwUseScriptLoader ) { |
— | — | @@ -218,7 +221,7 @@ |
219 | 222 | // Add requested classSet |
220 | 223 | for( var i=0; i < classSet.length; i++ ){ |
221 | 224 | var cName = classSet[i]; |
222 | | - if( !mwr_check_obj_path( cName ) ){ |
| 225 | + if( !mwCheckObjectPath( cName ) ){ |
223 | 226 | rurl += ',' + cName; |
224 | 227 | } |
225 | 228 | } |
— | — | @@ -232,20 +235,24 @@ |
233 | 236 | importScriptURI( mwEmbedHostPath + '/mwEmbed/mwEmbed.js?' + mwGetReqArgs() ); |
234 | 237 | } |
235 | 238 | } |
236 | | - mwr_check_for_mwEmbed( callback ); |
| 239 | + waitMwEmbedReady( callback ); |
237 | 240 | } |
238 | | - |
239 | | -function mwr_check_for_mwEmbed( callback ) { |
240 | | - if ( typeof mw == 'undefined' ) { |
| 241 | +/** |
| 242 | +* waits for mwEmbed to be ready |
| 243 | +*/ |
| 244 | +function waitMwEmbedReady( callback ) { |
| 245 | + if( ! mwCheckObjectPath( 'mw.version' ) ){ |
241 | 246 | setTimeout( function() { |
242 | | - mwr_check_for_mwEmbed( callback ); |
| 247 | + waitMwEmbedReady( callback ); |
243 | 248 | }, 25 ); |
244 | 249 | } else { |
245 | 250 | callback(); |
246 | 251 | } |
247 | 252 | } |
248 | | - |
249 | | -function mwr_check_obj_path ( libVar ) { |
| 253 | +/** |
| 254 | +* Checks an object path to see if its defined |
| 255 | +*/ |
| 256 | +function mwCheckObjectPath ( libVar ) { |
250 | 257 | if ( !libVar ) |
251 | 258 | return false; |
252 | 259 | var objPath = libVar.split( '.' ) |