r66362 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66361‎ | r66362 | r66363 >
Date:17:26, 13 May 2010
Author:dale
Status:deferred
Tags:
Comment:
* added wgEnableTestJavascriptModules global for test modules
* added language PLURAL transform js vs mediawiki test
Modified paths:
  • /trunk/extensions/JS2Support/JS2Support.php (modified) (history)
  • /trunk/extensions/JS2Support/mwEmbed/loader.js (modified) (history)
  • /trunk/extensions/JS2Support/tests (added) (history)
  • /trunk/extensions/JS2Support/tests/loader.js (added) (history)
  • /trunk/extensions/JS2Support/tests/testLang.html (added) (history)
  • /trunk/extensions/JS2Support/tests/testLang.js (added) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/mwEmbed/loader.js
@@ -140,9 +140,7 @@
141141
142142 "mw.style.jqueryUiRedmond" : "libraries/jquery/jquery.ui/themes/redmond/jquery-ui-1.7.1.custom.css",
143143 "mw.style.jqueryUiSmoothness" : "libraries/jquery/jquery.ui/themes/smoothness/jquery-ui-1.7.1.custom.css",
144 - "mw.style.mwCommon" : "skins/common/common.css",
145 -
146 - "mw.testLang" : "tests/testLang.js",
 144+ "mw.style.mwCommon" : "skins/common/common.css",
147145
148146 "$j.cookie" : "libraries/jquery/plugins/jquery.cookie.js",
149147 "$j.contextMenu" : "libraries/jquery/plugins/jquery.contextMenu.js",
Index: trunk/extensions/JS2Support/JS2Support.php
@@ -22,7 +22,8 @@
2323 */
2424 $wgExtensionFunctions[] = 'wfSetupJS2';
2525 function wfSetupJS2(){
26 - global $wgOut, $js2Dir, $wgAutoloadClasses, $wgScriptLoaderNamedPaths;
 26+ global $wgOut, $js2Dir, $wgAutoloadClasses, $wgScriptLoaderNamedPaths,
 27+ $wgExtensionJavascriptLoader, $wgEnableTestJavascriptModules;
2728
2829 // Remap output page as part of the extension setup
2930 $wgOut = new StubObject( 'wgOut', 'ScriptLoaderOutputPage' );
@@ -31,6 +32,12 @@
3233 // Include all the mediaWiki autoload classes:
3334 require( $js2Dir . 'JS2AutoLoader.php');
3435
 36+ // Add the core test module loaders (extensions can add their own test modules referencing this global )
 37+ if( $wgEnableTestJavascriptModules ) {
 38+ $wgExtensionJavascriptLoader[] = 'extensions/JS2Support/tests/loader.js';
 39+ }
 40+
 41+
3542 // Update all the javascript modules classNames and localization by reading respective loader.js files
3643 // @dependent on all extensions defining $wgExtensionJavascriptLoader paths in config file ( not in setup )
3744 // @NOTE parsing javascript could be delayed or avoided if we require more php extension configuration
@@ -85,7 +92,16 @@
8693 */
8794 $wgEnableScriptLoader = false;
8895
 96+
8997 /**
 98+ * wgEnableTestJavascriptModules if the test modules should be loaded and enabled
 99+ * In production environments its recommend to disabled wgEnableTestJavascriptModules
 100+ * since some tests can be very resource intensive.
 101+ */
 102+
 103+$wgEnableTestJavascriptModules = false;
 104+
 105+/**
90106 * $wgScriptModifiedCheck should run a file modified check on javascript files when
91107 * generating unique request ids for javascript include using the script-loader
92108 *
Index: trunk/extensions/JS2Support/tests/loader.js
@@ -0,0 +1,5 @@
 2+// Setup the test classes
 3+
 4+mw.addClassFilePaths( {
 5+ "mw.testLang" : "testLang.js"
 6+});
\ No newline at end of file
Property changes on: trunk/extensions/JS2Support/tests/loader.js
___________________________________________________________________
Name: svn:eol-style
17 + native
Index: trunk/extensions/JS2Support/tests/testLang.html
@@ -0,0 +1,193 @@
 2+<html>
 3+<head>
 4+<title>Test Plural Conversions (should match php) </title>
 5+<script type="text/javascript" src="../mwEmbed/mwEmbed.js"></script>
 6+<style>
 7+td{
 8+ border:solid thin black;
 9+}
 10+</style>
 11+<script type="text/javascript" >
 12+mw.ready( function(){
 13+ //for just setting one or two to test at a time for debug
 14+ //var langTestSet = [ 'tk', 'tt', 'sr-el', 'sr-ec', 'sr', 'shi', 'se', 'shi'];
 15+ //doLangTable ( langTestSet );
 16+
 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:
 41+ function doLangTable( langSet ){
 42+ $j('#table_out').loadingSpinner();
 43+ //build table output:
 44+ var msgTestSet = {
 45+ 'undelete_short' : [ 0, 1, 2, 5, 21, 101 ],
 46+ //category-subcat-count' has two params:
 47+ 'category-subcat-count' : [
 48+ [0,10],
 49+ [1,2],
 50+ [3,30]
 51+ ]
 52+ };
 53+
 54+ var passTest=0;
 55+ var failTest=0;
 56+ var testCount=0;
 57+
 58+ /**
 59+ * Proccess a language key test set
 60+ */
 61+ function doProcLangKey( langKey ){
 62+ mw.log(" doProcLangKey: " + langKey );
 63+ // Clear out the old digitTransformTable
 64+ mw.Language.digitTransformTable = null;
 65+ // Load the current language js file if it has a langKey
 66+ var transformLangKey = mw.getLangTransformKey ( langKey );
 67+ if( transformLangKey != 'en' ){
 68+ mw.log( langKey + " load msg transform" );
 69+ var langName = 'Language' + transformLangKey.substr(0,1).toUpperCase() + transformLangKey.substr( 1, transformLangKey.length );
 70+ $j.getScript( '../languages/classes/' + langName + '.js' , function(){
 71+ doLangTest();
 72+ });
 73+ } else {
 74+ mw.log( langKey + " no msg transform restore base" );
 75+ //If no transform, restore base plural
 76+ mw.Language.convertPlural = baseConvertPlural;
 77+ doLangTest();
 78+ }
 79+
 80+ function doLangTest(){
 81+ // Get the current language mw.testLang js
 82+ $j.getScript( '../mwScriptLoader.php?class=mw.testLang&debug=true&uselang='+langKey, function(){
 83+ var o='';
 84+ o+='<tr><td colspan="6" height="20" style="font-size:large"><b>Lang:' + langKey + '</b></td></tr>';
 85+ //now for each langage msg:
 86+ $j.each(msgTestSet, function(mKey, mTestSet){
 87+ //output table names:
 88+ o+='<tr>'+
 89+ '<td>$1[,$2]</td>'+
 90+ '<td width="14%">Msg key</td>'+
 91+ '<td width="34%">Msg text</td>'+
 92+ '<td width="24%">Msg Transform JS</td>'+
 93+ '<td width="24%">Msg Transform Mw</td>'+
 94+ '</tr>';
 95+
 96+ //for each number value
 97+ for(var i in mTestSet){
 98+ var numVal = mTestSet[i];
 99+ var numKey = (typeof numVal== 'object')? numVal.join( '_' ).replace('/ /', '_') : numVal;
 100+ var tkey = mKey + '_' + numKey + '_' + langKey;
 101+ o+='<tr>'+
 102+ '<td>' + numVal + '</td>' +
 103+ '<td>' + mKey + '</td>' +
 104+ '<td>' + mw.Language.msgNoTrans( mKey ) + '</td>' +
 105+ '<td id="' + tkey + '_js">' + gM( mKey, numVal ) + '</td>';
 106+ //show mw col:
 107+ if( mKey.substr(0, 5) == 'test_' ){
 108+ o+='<td> (test msg) </td>';
 109+ }else{
 110+ o+='<td id="' + tkey + '">loading...</td>';
 111+
 112+ //get transform from mw (& compare and highlight)
 113+ function doPopWmMsg(mKey, numVal, numKey){
 114+ //set the local tkey:
 115+ var tkey = mKey + '_' + numKey + '_' + langKey;
 116+ testCount++;
 117+ $j('#score_card').html('Running Tests <span id="perc_done">0</sapn>% done');
 118+ var msgparam = (typeof numVal== 'object')? numVal.join( '|' ) : numVal;
 119+ var request = {
 120+ 'action' : 'query',
 121+ 'meta' : 'allmessages',
 122+ 'ammessages' : mKey,
 123+ 'amlang' : langKey,
 124+ 'amargs' : msgparam,
 125+ 'amenableparser' : true
 126+ };
 127+ mw.getJSON('../../../api.php', request, function( data ) {
 128+ var t = '#'+ tkey;
 129+ var $target = $j( t ) ;
 130+ if( data.query && data.query.allmessages && data.query.allmessages[0]){
 131+ var msgText = data.query.allmessages && data.query.allmessages[0]['*'];
 132+ if( msgText == '' )
 133+ msgText = ' %missing% ';
 134+ $target.html( msgText );
 135+ var js_txt = $j.trim( $j(t + '_js').text().replace('\n', '') );
 136+ var php_txt = $j.trim( msgText );
 137+ // Just get the part in the <p> to compare with js version
 138+ if( js_txt != php_txt ){
 139+ $target.css('color', 'red');
 140+ failTest++;
 141+ }else{
 142+ $target.css('color', 'green');
 143+ passTest++;
 144+ }
 145+ var perc = ( failTest + passTest ) / testCount
 146+ if( perc != 1){
 147+ $j('#perc_done').html( Math.round(perc*1000)/1000 + '%');
 148+ }else{
 149+ var failHtlm = (failTest == 0)?failTest: '<span style="color:red">'+ failTest+'</span>';
 150+ $j('#score_card').html(
 151+ 'Passed: <span style="color:green">' + passTest + '</span> Failed:' + failHtlm );
 152+
 153+ //done with this lang... call outer function if we have lang keys left to proccess:
 154+ if( langSet.length !=0 )
 155+ doProcLangKey( langSet.pop() );
 156+ }
 157+ }else{
 158+ $target.html(' error ').css('color', 'red');
 159+ }
 160+ });
 161+ };
 162+ //pop off an anonymous function call
 163+ doPopWmMsg(mKey, numVal, numKey);
 164+ }
 165+ o+='</tr>';
 166+ }
 167+ //output a spacer:
 168+ o+='<tr><td colspan="6" height="20"> </td></tr>';
 169+ });
 170+ // remove the spiner
 171+ $j( '.loading_spinner').remove();
 172+ //put the output into the page:
 173+ $j('#table_out').append( o );
 174+ });
 175+ }
 176+ }//procc lang key:
 177+
 178+ doProcLangKey( langSet.pop() );
 179+ }
 180+});
 181+
 182+</script>
 183+</head>
 184+<body>
 185+<h3>Test Javascript plural msg transformations ( note this is a very resource intensive test )</h3>
 186+<a id="runAll" href="#">Run Test all<a> ( takes a while ) <br>
 187+<a id="runLang" href="#">Run Language Key</a>:<input size="5" id="testLangKey" name = "testLangKey" value="en"/>
 188+
 189+<div id="score_card" style="font-size:large"></div>
 190+<table id="table_out"></table>
 191+
 192+
 193+</body>
 194+</html>
Index: trunk/extensions/JS2Support/tests/testLang.js
@@ -0,0 +1,10 @@
 2+/* a simple language tester replacements
 3+ */
 4+
 5+mw.addMessages( {
 6+ "undelete_short" : "Undelete {{PLURAL:$1|one edit|$1 edits}}",
 7+ "category-subcat-count" : "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}",
 8+ "mwe-upload-multi" : "Upload {{PLURAL:$1|file|files}}"
 9+} );
 10+// define a class by the name of this file:
 11+mw.testLang = { };
\ No newline at end of file
Property changes on: trunk/extensions/JS2Support/tests/testLang.js
___________________________________________________________________
Name: svn:eol-style
112 + native

Status & tagging log