r65288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65287‎ | r65288 | r65289 >
Date:21:48, 19 April 2010
Author:dale
Status:deferred
Tags:
Comment:
* fixed relative css paths for script-loader usage in JS2Support extension
* updated testLang.html page ( not as much of a DOS as it requires user click )
* stubs for addMessageKeys support
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/languages/classes/LanguageFr.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/languages/mw.Language.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/testLang.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/testLang.html
@@ -11,46 +11,69 @@
1212
1313 mw.ready( function(){
1414 //for just setting one or two to test at a time for debug
15 - var langTestSet = [ 'es' ]; //pl
16 - //var langTestSet = mw.getConfig( 'languageCodeList' );
 15+ //var langTestSet = [ 'es' ]; //pl
1716
18 - //do mauall script loaders calls to test multiple languages:
 17+ // Setup bindings:
 18+ $j('#runLang').click(function(){
 19+ $j('#table_out,#score_card').empty();
 20+ if( !mw.Language.names[ $j('#testLangKey').val() ] ){
 21+ alert( escape( $j('#testLangKey').val() ) + ' does not appear to be a valid language key' );
 22+ } else {
 23+ doLangTable( new Array( $j('#testLangKey').val() ) )
 24+ }
 25+ });
 26+ $j('#runAll').click(function(){
 27+ $j('#table_out,#score_card').empty();
 28+ // Build the langTestSet from mw.Language.names
 29+ var langTestSet = []
 30+ for( var i in mw.Language.names ) {
 31+ langTestSet.push( i ) ;
 32+ }
 33+ doLangTable( langTestSet );
 34+ });
 35+
 36+ // Set-up base convert plural and gender (to restore for non-transofrm languages )
 37+ var baseConvertPlural = mw.Language.convertPlural;
 38+ var baseGender = mw.Language.gender.prototype;
 39+
 40+ // Do mauall script loaders calls to test multiple languages:
1941 function doLangTable( langSet ){
2042 //build table output:
2143 var msgTestSet = {
22 - 'undelete_short' : [ 0, 1, 2, 5, 21, 30 ],
 44+ 'undelete_short' : [ 0, 1, 2, 5, 21, 101 ],
2345 //category-subcat-count' has two params:
2446 'category-subcat-count' : [
2547 [0,10],
26 - [1,2],
 48+ [1,2],
2749 [3,30]
28 - ],
29 - 'contributions-title' : [0,1,2]
30 - };
31 - // Set-up base convert plural and gender (to restore if no language class is set)
32 - var baseConvertPlural = mw.Language.convertPlural;
33 - var baseGender = mw.Language.gender;
 50+ ]
 51+ };
3452
3553 var passTest=0;
3654 var failTest=0;
3755 var testCount=0;
3856
3957 /**
40 - * proccess a language key test set
 58+ * Proccess a language key test set
4159 */
4260 function doProcLangKey( langKey ){
4361 mw.log(" doProcLangKey: " + langKey );
4462 // Clear out the old digitTransformTable
4563 mw.Language.digitTransformTable = null;
46 - // Load the current language js file if it has a langKey
47 - if( mw.hasLangTransform (langKey ) ){
 64+ // Load the current language js file if it has a langKey
 65+ if( mw.hasLangTransform ( langKey ) ){
 66+ mw.log( langKey + " load msg transform" );
4867 var langName = 'Language' + langKey.substr(0,1).toUpperCase() + langKey.substr( 1,langKey.length );
4968 $j.getScript( '../languages/classes/' + langName + '.js' , function(){
5069 doLangTest();
5170 });
5271 } else {
 72+ mw.log( langKey + " no msg transform restore base" );
 73+ //If no transform, restore base plural
 74+ mw.Language.convertPlural = baseConvertPlural;
5375 doLangTest();
5476 }
 77+
5578 function doLangTest(){
5679 // Get the current language mw.testLang js
5780 $j.getScript( '../../../mwScriptLoader.php?class=mw.testLang&debug=true&uselang='+langKey, function(){
@@ -149,14 +172,15 @@
150173
151174 doProcLangKey( langSet.pop() );
152175 }
153 - //by default run the "debug" set:
154 - doLangTable( langTestSet );
155176 });
156177
157178 </script>
158179 </head>
159180 <body>
160 -<h3>Test Javascript plural msg transformations</h3>
 181+<h3>Test Javascript plural msg transformations ( note this is a very resource intensive test )</h3>
 182+<a id="runAll" href="#">Run Test all<a> ( takes a few minutes ) <br>
 183+<a id="runLang" href="#">Run Language Key</a>:<input size="5" id="testLangKey" name = "testLangKey" value="en"/>
 184+
161185 <div id="score_card" style="font-size:large"></div>
162186 <table id="table_out"></table>
163187
Index: branches/js2-work/phase3/js/mwEmbed/languages/mw.Language.js
@@ -28,23 +28,32 @@
2929 }
3030 }
3131
 32+ var messageKeyQueue = [];
3233 /**
3334 * mw.addMessagesKey function
3435 * Adds a msgKey to be pulled in remotely.
3536 *
3637 * NOTE the script-loader should replace this with localized addMessages calls
37 - * if addMessagesKey is called then we are running in raw file debug mode.
3838 *
 39+ * If addMessagesKey is called then we are running in raw file debug mode.
 40+ * it populates the messegeKeyQueue and loads the values in a separate request callback
 41+ *
3942 * @param {Array} msgSet The set of msgs to be loaded
4043 */
41 - mw.addMessageKeys = function( msgSet ) {
42 - /*for ( var i in msgSet ) {
43 - messageCache[ i ] = msgSet[i];
44 - }*/
45 - // FLAG loader to wait for remote msg keys
 44+ mw.addMessageKeys = function( msgSet ) {
 45+ messageKeyQueue.concat( msgSet );
4646 }
4747
 48+ /**
 49+ * NOTE: this is somewhat of a hack. But its only used in debug mode since
 50+ * normal msg loading happens via script-loader
 51+ */
 52+ mw.loadQueuedMessages = function( classSet, callback ){
 53+ // Load the queued msgs ( requires access to the mediaWiki entry point )
 54+
 55+ }
4856
 57+
4958 /**
5059 * Returns a transformed msg string
5160 *
@@ -531,8 +540,8 @@
532541 };
533542
534543 // Language classes ( has a file in /languages/classes/Language{code}.js )
535 - // ( for languages that overide default transforms )
536 - mw.Language.transformClass = ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
 544+ // ( for languages that override default transforms )
 545+ mw.Language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
537546 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi',
538547 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt',
539548 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma',
@@ -674,14 +683,14 @@
675684 return ( mw.Language.names[ langKey ] )? true : false;
676685 }
677686 /**
678 - * Checks if a language key has a transform class file
 687+ * Checks if a language key has a transform class file
679688 */
680689 mw.hasLangTransform = function( langKey ) {
681 - for( var i =0; i < mw.Language.transformClass; i++) {
 690+ for( var i =0; i < mw.Language.transformClass.length; i++ ) {
682691 if( langKey == mw.Language.transformClass[i] ){
683692 return true;
684693 }
685 - }
 694+ }
686695 return false;
687696 }
688697
Index: branches/js2-work/phase3/js/mwEmbed/languages/classes/LanguageFr.js
@@ -8,7 +8,6 @@
99 * Use singular form for zero (see bug 7309)
1010 */
1111 mw.Language.convertPlural = function( count, forms ) {
12 -
1312 forms = mw.Language.preConvertPlural( forms, 2 );
1413
1514 return (count <= 1) ? forms[0] : forms[1];
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1745,7 +1745,7 @@
17461746 }
17471747
17481748 // Get mwEmbed src:
1749 - var src = mw.getMwEmbedSrc();
 1749+ var src = mw.getMwEmbedSrc();
17501750 var mwpath = null;
17511751
17521752 // Check for direct include of the mwEmbed.js
@@ -2237,7 +2237,6 @@
22382238 langCode + '.js' );
22392239 }
22402240 }
2241 -
22422241 mw.setConfig('loaderContext', '' );
22432242 mw.load( loaderRequest, function() {
22442243 mw.log( 'Done moduleLoaderCheck request' );
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -396,14 +396,16 @@
397397
398398 // Check for the two jsScriptLoader entry points:
399399 if( strpos( $serverUri, 'mwScriptLoader.php') !== false ){
400 - $cssOptions[ 'prependRelativePath' ] =
401 - str_replace('mwScriptLoader.php', '', $serverUri)
402 - . dirname( $path ) . '/';
 400+ // Using the local mediaWiki entry point we should have our $wgScriptPath global
 401+ global $wgScriptPath;
 402+ $cssOptions[ 'prependRelativePath' ] = $wgScriptPath . '/' . dirname( $path ) . '/';
403403 } else if( strpos( $serverUri, 'jsScriptLoader.php') !== false ){
 404+ // We should use an absolute url to jsScriptLoader.php
404405 $cssOptions[ 'prependRelativePath' ] =
405406 str_replace('jsScriptLoader.php', '', $serverUri)
406407 . dirname( $path ) . '/';
407408 }
 409+
408410 // We always run minify to update css urls
409411 $cssString = Minify_CSS::minify( $cssString, $cssOptions);
410412

Status & tagging log