r74961 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74960‎ | r74961 | r74962 >
Date:19:52, 18 October 2010
Author:dale
Status:deferred
Tags:
Comment:
* re factored withJS helper to global config for 'Mw.AppendWithJS '
* added regEx support to apiProxy domain list
** added all wikimedia projects domains to approved hosts ( so from any project users can edit or requests transcripts for subtitles on commons )
* some fixes to setConfig to better support arrays
Modified paths:
  • /branches/MwEmbedStandAlone/loader.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/ApiProxy/ApiProxyPage.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/ApiProxy/loader.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/ApiProxy/mw.ApiProxy.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/MiroSubs/loader.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerConfig.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/remotes/mw.MediaWikiRemoteSequencer.js (modified) (history)
  • /branches/MwEmbedStandAlone/mwEmbed.js (modified) (history)
  • /branches/MwEmbedStandAlone/remotes/mediaWiki.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/loader.js
@@ -97,7 +97,10 @@
9898 'commons_apiurl' : 'http://commons.wikimedia.org/w/api.php',
9999
100100 // Set the default loader group strategy
101 - 'loader.groupStrategy' : 'module'
 101+ 'loader.groupStrategy' : 'module',
 102+
 103+ // Default appendJS string ( not used outside of wikimedia gadget system )
 104+ 'Mw.AppendWithJS' : false
102105
103106 } );
104107
Index: branches/MwEmbedStandAlone/mwEmbed.js
@@ -83,8 +83,13 @@
8484 }
8585 // Check if we should "merge" the config
8686 if( typeof value == 'object' && typeof mwConfig[ name ] == 'object' ) {
87 - for( var i in value ){
88 - mwConfig[ name ][ i ] = value[ i ];
 87+ if ( value.constructor.toString().indexOf("Array") == -1 ){
 88+ for( var i in value ){
 89+ mwConfig[ name ][ i ] = value[ i ];
 90+ }
 91+ } else {
 92+ // merge in the array
 93+ mwConfig[ name ] = mwConfig[ name ].concat( value );
8994 }
9095 } else {
9196 mwConfig[ name ] = value;
@@ -115,11 +120,16 @@
116121 }
117122 // Check if we should "merge" the config
118123 if( typeof value == 'object' && typeof mwConfig[ name ] == 'object' ) {
119 - for( var i in value ){
120 - if( typeof mwConfig[ name ][ i ] == 'undefined' ){
121 - mwConfig[ name ][ i ] = value[ i ];
 124+ if ( value.constructor.toString().indexOf("Array") == -1 ){
 125+ for( var i in value ){
 126+ if( typeof mwConfig[ name ][ i ] == 'undefined' ){
 127+ mwConfig[ name ][ i ] = value[ i ];
 128+ }
122129 }
123 - }
 130+ } else {
 131+ // merge in the array
 132+ mwConfig[ name ] = mwConfig[ name ].concat( value);
 133+ }
124134 }
125135 };
126136
@@ -1281,8 +1291,8 @@
12821292 */
12831293 mw.log = function( string ) {
12841294 // Add any prepend debug strings if necessary
1285 - if ( mw.getConfig( 'pre-append-log' ) ){
1286 - string = mw.getConfig( 'pre-append-log' ) + string;
 1295+ if ( mw.getConfig( 'Mw.LogPrepend' ) ){
 1296+ string = mw.getConfig( 'Mw.LogPrepend' ) + string;
12871297 }
12881298
12891299 if ( window.console ) {
Index: branches/MwEmbedStandAlone/modules/MiroSubs/loader.js
@@ -41,8 +41,7 @@
4242 $j( langMenu ).append(
4343 $j.getLineItem( gM( 'mwe-mirosubs-add-universal-subtitles'), 'mirosubs', function() {
4444 // Show loader
45 - mw.addLoaderDialog( gM('mwe-mirosubs-loading-universal-subtitles') );
46 -
 45+ mw.addLoaderDialog( gM('mwe-mirosubs-loading-universal-subtitles') );
4746 // Load miro subs:
4847 mw.load( 'MiroSubs', function(){
4948 // Open the mirosubs dialog:
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js
@@ -363,7 +363,7 @@
364364 .text( gM('mwe-sequencer-loading-player') ),
365365 $j('<div />')
366366 .addClass( "ui-layout-south mwseq-timeline" )
367 - .text( gM('mwe-sequencer-loading-timeline') )
 367+ .text( gM('mwe-sequencer-loading-timeline') )
368368 )
369369 )
370370 .children();
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerConfig.js
@@ -18,9 +18,6 @@
1919 // If a the sequencer should open new windows
2020 "Sequencer.SpawnNewWindows" : true,
2121
22 - // If a the sequencer should include withJS=MediaWiki:mwEmbed in created urls
23 - "Sequencer.WithJsMwEmbedUrlHelper" : true,
24 -
2522 // The size of the undo stack
2623 "Sequencer.NumberOfUndos" : 100,
2724
Index: branches/MwEmbedStandAlone/modules/Sequencer/remotes/mw.MediaWikiRemoteSequencer.js
@@ -37,13 +37,13 @@
3838 * @param {String} url The url to be wrapped
3939 */
4040 mw.getRemoteSequencerLink = function( url ){
41 - if( mw.getConfig( 'Sequencer.WithJsMwEmbedUrlHelper' ) ){
 41+ if( mw.getConfig( 'Mw.AppendWithJS' ) ){
4242 if( url.indexOf('?') == -1){
4343 url+='?';
4444 } else {
4545 url+='&';
4646 }
47 - url+='withJS=MediaWiki:MwEmbed.js';
 47+ url+= mw.getConfig( 'Mw.AppendWithJS' );
4848 }
4949 return url;
5050 };
@@ -310,7 +310,7 @@
311311 displayPlayerEmbed: function(){
312312 var _this = this;
313313 // load the embedPlayer module:
314 - mw.load( 'EmbedPlayer', function(){
 314+ mw.load('EmbedPlayer', function(){
315315 // Check if the sequence has been flattened and is up to date:
316316 var request = {
317317 'action': 'query',
Index: branches/MwEmbedStandAlone/modules/ApiProxy/loader.js
@@ -2,6 +2,19 @@
33
44 // Wrap in mw to not pollute global namespace
55 ( function( mw ) {
 6+
 7+ // Set the default allowable domains for api proxy
 8+ mw.setDefaultConfig({
 9+ // Black list domains
 10+ 'ApiProxy.DomainBlackList' : [],
 11+
 12+ // White list domains
 13+ 'ApiProxy.DomainWhiteList' : [
 14+ 'localhost',
 15+ '127.1.1.100'
 16+ ]
 17+ });
 18+
619 mw.addResourcePaths( {
720 "mw.ApiProxy" : "mw.ApiProxy.js"
821 } );
Index: branches/MwEmbedStandAlone/modules/ApiProxy/ApiProxyPage.js
@@ -8,37 +8,14 @@
99 * Since this is proxy server set a pre-append debug flag to know which debug msgs are coming from where
1010 */
1111
12 -mw.setConfig( 'pre-append-log', 'Proxy:');
13 -
14 -if ( !mwApiProxyConfig ){
15 - var mwApiProxyConfig = { };
16 -}
 12+mw.setConfig( 'Mw.LogPrepend', 'Proxy:');
1713
18 -// The default mwApiProxyConfig config
19 -// xxx todo whitelist all inter-wiki actions
20 -var mwApiProxyDefaultConfig = {
21 - 'master_whitelist' : [
22 - 'en.wikipedia.org',
23 - 'commons.wikimedia.org',
24 - 'usability.wikimedia.org',
25 - 'prototype.wikimedia.org',
26 - 'localhost',
27 - '127.1.1.100'
28 - ],
29 - 'master_blacklist' : []
30 -};
31 -
32 -// User white_list should also be checked and configured at runtime.
33 -mw.ready( function() {
34 - // Build our configuration from the default and mwApiProxyConfig vars
35 - mwApiProxyConfig = $j.extend( true, mwApiProxyDefaultConfig, mwApiProxyConfig );
36 - mw.setConfig( 'apiProxyConfig', mwApiProxyConfig);
37 -
38 - // Do a setTimeout to 0 to call after other zero delay async events
39 - // ( once everyone is doing buildout within mwsetup prior to .ready this won't be needed. )
 14+// The default allowable domain list is stored in the loader.js configuration.
 15+
 16+mw.ready( function() {
4017 mw.log( 'load ApiProxy' );
4118 mw.load( 'ApiProxy', function() {
42 - //Clear out the page content ( not needed for iframe proxy )
 19+ // Clear out the page content ( not needed for iframe proxy )
4320 $j( 'body' ).html( '' );
4421 mw.ApiProxy.server();
4522 } );
Index: branches/MwEmbedStandAlone/modules/ApiProxy/mw.ApiProxy.js
@@ -219,7 +219,7 @@
220220
221221 // Return the name of the browseFile frame
222222 return iFrameName;
223 - }
 223+ };
224224
225225 /**
226226 * Output a server msg to a server iFrame
@@ -259,7 +259,7 @@
260260 }, function( ) {
261261 mw.log( "sendServerMsg iframe done loading" );
262262 } );
263 - }
 263+ };
264264
265265 /**
266266 * The nested iframe action that passes its result back up to the top frame instance
@@ -304,7 +304,7 @@
305305 if( context.callback ){
306306 context.callback( resultObject );
307307 }
308 - }
 308+ };
309309
310310
311311 /**
@@ -326,7 +326,7 @@
327327 serverSendUploadHandlerAction( frameMsg.uiAction );
328328 break;
329329 }
330 - }
 330+ };
331331
332332 /**
333333 * Api server proxy entry point:
@@ -368,7 +368,7 @@
369369
370370 // Return the proxy context
371371 return proxyContext [ contextKey ];
372 - }
 372+ };
373373
374374 /**
375375 * Get a context from a contextKey
@@ -382,7 +382,7 @@
383383 return false;
384384 }
385385 return proxyContext [ contextKey ];;
386 - }
 386+ };
387387
388388 /**
389389 * Get the client frame path
@@ -400,7 +400,7 @@
401401 // Update the context to include the nestedCallbackFlag flag in the request
402402 return nestedServerFrame;
403403 }
404 - }
 404+ };
405405
406406 /**
407407 * Get the server Frame path per requested Api url
@@ -417,7 +417,7 @@
418418 * @param {URL} apiUrl The url of the api server
419419 */
420420 // Include gadget js ( in case the user has not enabled the gadget on that domain )
421 - var gadgetWithJS = '?withJS=MediaWiki:MwEmbed.js';
 421+
422422 //var gadgetWithJS = '';
423423
424424 function getServerFrame( context ) {
@@ -427,10 +427,15 @@
428428 }
429429 var parsedUrl = mw.parseUri( context.apiUrl );
430430
431 - var pageName = ( context.pageName ) ? context.pageName : 'ApiProxy'
 431+ var pageName = ( context.pageName ) ? context.pageName : 'ApiProxy';
432432
433 - return parsedUrl.protocol + '://' + parsedUrl.authority
434 - + '/w/index.php/MediaWiki:' + pageName + gadgetWithJS;
 433+ var pageUrl = parsedUrl.protocol + '://' + parsedUrl.authority
 434+ + '/w/index.php/MediaWiki:' + pageName;
 435+
 436+ if( mw.getConfig( 'Mw.AppendWithJS' ) ){
 437+ pageUrl+= '?' + mw.getConfig( 'Mw.AppendWithJS' );
 438+ }
 439+ return pageUrl;
435440 }
436441
437442 /**
@@ -483,9 +488,9 @@
484489 mw.log('Client frame: ' + clientRequest.clientFrame );
485490
486491 /**
487 - * HERE WE CHECK IF THE DOMAIN IS ALLOWED per the proxyConfig
488 - */
489 - return isAllowedClientFrame( clientRequest.clientFrame );
 492+ * CHECK IF THE DOMAIN IS ALLOWED per the ApiProxy config:
 493+ */
 494+ return isAllowedClientFrame( clientRequest.clientFrame );;
490495 }
491496
492497 /**
@@ -495,29 +500,54 @@
496501 function isAllowedClientFrame( clientFrame ) {
497502 var clientDomain = mw.parseUri( clientFrame ).host ;
498503 // Get the proxy config
499 - var proxyConfig = mw.getConfig( 'apiProxyConfig' );
500504
501505 // Check master blacklist
502 - for ( var i in proxyConfig.master_blacklist ) {
503 - if ( clientDomain == proxyConfig.master_blacklist ) {
504 - mw.log( 'domain: ' + clientDomain + ' is blacklisted ( no request )' );
505 - return false;
506 - }
507 - }
 506+ if( mw.getConfig('ApiProxy.DomainBlackList') && mw.getConfig('ApiProxy.DomainBlackList').length ){
 507+ var domainBlackList = mw.getConfig('ApiProxy.DomainBlackList');
 508+ for ( var i =0; i < domainBlackList.length; i++ ) {
 509+ var blackDomain = domainBlackList[i];
 510+ // Check if domain check is a RegEx:
 511+ if( typeof blackDomain == 'object' ){
 512+ if( clientDomain.match( blackDomain ) ){
 513+ return false;
 514+ }
 515+ } else {
 516+ // just do a direct domain check:
 517+ if( clientDomain == blackDomain ){
 518+ return false;
 519+ }
 520+ }
 521+ }
 522+ }
 523+
508524 // Check the master whitelist:
509 - for ( var i in proxyConfig.master_whitelist ) {
510 - if ( clientDomain == proxyConfig.master_whitelist[ i ] ) {
511 - return true;
 525+ if( mw.getConfig('ApiProxy.DomainWhiteList') && mw.getConfig('ApiProxy.DomainWhiteList').length ){
 526+ var domainWhiteList = mw.getConfig('ApiProxy.DomainWhiteList');
 527+ for ( var i =0; i < domainWhiteList.length; i++ ) {
 528+ whiteDomain = domainWhiteList[i];
 529+ // Check if domain check is a RegEx:
 530+ if( typeof whiteDomain == 'object' ){
 531+ if( clientDomain.match( whiteDomain ) ) {
 532+ return true;
 533+ }
 534+ } else {
 535+ if( clientDomain == whiteDomain ){
 536+ return true;
 537+ }
 538+ }
512539 }
513540 }
 541+
514542 // FIXME Add in user based approval ::
515543
516544 // FIXME offer the user the ability to "approve" requested domain save to
517545 // their user preference setup )
518546
519547 // FIXME grab and check domain against the users whitelist and permissions
 548+
 549+ // for now just return false if the domain is not in the approved list
520550 return false;
521 - }
 551+ };
522552
523553 /**
524554 * Get the client request from the document hash
@@ -532,7 +562,7 @@
533563 mw.log( "ProxyServer:: could not parse anchor" );
534564 return false;
535565 }
536 - }
 566+ };
537567
538568 /**
539569 * Dialog to send the user if a proxy to the remote server could not be created
@@ -587,7 +617,7 @@
588618 'content' : $dialogMsg,
589619 'buttons' : buttons
590620 })
591 - }
 621+ };
592622
593623 /**
594624 * API iFrame Server::
@@ -619,7 +649,7 @@
620650 }
621651 mw.log( "Error could not handle client request" );
622652 return false;
623 - }
 653+ };
624654
625655 /**
626656 * Api iFrame request:
Index: branches/MwEmbedStandAlone/remotes/mediaWiki.js
@@ -4,7 +4,7 @@
55 */
66 var urlparts = getRemoteEmbedPath();
77 var mwEmbedHostPath = urlparts[0];
8 -var mwRemoteVersion = 'r165';
 8+var mwRemoteVersion = 'r167';
99 var mwUseScriptLoader = true;
1010
1111 // Log the mwRemote version makes it easy to debug cache issues
@@ -72,17 +72,31 @@
7373 /*******************************
7474 * Wikimedia specific config
7575 ********************************/
 76+// The player should attribute kaltura
 77+mw.setConfig( 'EmbedPlayer.KalturaAttribution', true );
 78+
 79+//The sequencer clips should include attribution 'edit sequence' link on pause
7680 mw.setConfig( 'Sequencer.KalturaPlayerEditOverlay', true );
77 -mw.setConfig( 'Sequencer.WithJsMwEmbedUrlHelper', true );
78 -mw.setConfig( 'EmbedPlayer.KalturaAttribution', true );
 81+
 82+// If the swarm p2p transport stream should be used for clients that have it installed
7983 mw.setConfig( 'SwarmTransport.Enable', true );
 84+
 85+// Sequencer should only load asset from upload.wikimedia.org:
8086 mw.setConfig( 'SmilPlayer.AssetDomainWhiteList', ['upload.wikimedia.org'] );
8187
 88+// Gadgets should append withJS to requests where we need to re-invoke the gadget on a different page
 89+// NOTE this is REQUIRED for apiProxy to work across projects where the user has not universally enabled the gadget
 90+mw.setConfig( 'Mw.AppendWithJS', 'withJS=MediaWiki:MwEmbed.js');
8291
 92+// Allow all wikimedia regEx domains matches to support api-proxy requests
 93+// NOTE remember to put $ at the end of the domain or it would match en.wikipedia.org.evil.com
 94+mw.setConfig( 'ApiProxy.DomainWhiteList',
 95+ [ /wikimedia\.org$/ , /wikipedia\.org$/ , /wiktionary.org$/ , /wikinews.org$/ , /wikibooks.org$/ , /wikisource.org$/ , /wikiversity.org$/ , /wikiquote.org$/ ]
 96+);
8397
8498
8599 // Use wikibits onLoad hook: ( since we don't have js2 / mw object loaded )
86 -if( window.jQuery ){
 100+if( window.jQuery ){
87101 jQuery( document ).ready( doPageSpecificRewrite );
88102 } else {
89103 addOnloadHook( function() {

Status & tagging log