r78324 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78323‎ | r78324 | r78325 >
Date:20:13, 13 December 2010
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Make the Map-class publicly available
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -21,105 +21,109 @@
2222 *
2323 * @param code String Code of the test to be executed
2424 * @param result String Expected result in 'var (vartype)' form
25 - * @param contain String Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
 25+ * @param contain String Important part of the result,
 26+ * if result is different but does contain this it will not return ERROR but PARTIALLY
2627 */
2728 'addTest' : function( code, result, contain ) {
2829 if (!contain) {
2930 contain = result;
3031 }
31 - this.addedTests.push([code, result, contain]);
32 - this.$table.append('<tr><td>' + mw.html.escape(code).replace(/ /g, '&nbsp;&nbsp;') + '</td><td>' + mw.html.escape(result).replace(/ /g, '&nbsp;&nbsp;') + '</td><td></td><td>?</td></tr>');
 32+ this.addedTests.push( [code, result, contain] );
 33+ this.$table.append( '<tr><td>' + mw.html.escape(code).replace(/ /g, '&nbsp;&nbsp;' )
 34+ + '</td><td>' + mw.html.escape(result).replace(/ /g, '&nbsp;&nbsp;' )
 35+ + '</td><td></td><td>?</td></tr>' );
3336 },
3437
3538 /* Initialisation */
3639 'initialised' : false,
3740 'init' : function () {
38 - if (this.initialised === false) {
 41+ if ( this.initialised === false ) {
3942 this.initialised = true;
4043 $(function () {
41 - if (wgCanonicalSpecialPageName == 'Blankpage' && mw.util.getParamValue('action') === 'mwutiltest') {
 44+ if ( wgCanonicalSpecialPageName == 'Blankpage'
 45+ && mw.util.getParamValue( 'action' ) === 'mwutiltest' ) {
4246
4347 // Build page
4448 document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName;
45 - $('#firstHeading').text('mediaWiki.util JavaScript Test');
 49+ $( '#firstHeading' ).text( 'mediaWiki.util JavaScript Test' );
4650 mw.util.$content.html(
47 - '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
48 - '<hr />' +
49 - '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">' +
50 - '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>' +
51 - '</table>'
 51+ '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>'
 52+ + '<hr />'
 53+ + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">'
 54+ + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>'
 55+ + '</table>'
5256 );
53 - mw.test.$table = $('table#mw-mwutiltest-table');
 57+ mw.test.$table = $( 'table#mw-mwutiltest-table' );
5458
5559 // Populate tests
56 - mw.test.addTest('typeof $.trimLeft',
57 - 'function (string)');
58 - mw.test.addTest('$.trimLeft(\' foo bar \')',
59 - 'foo bar (string)');
60 - mw.test.addTest('typeof $.trimRight',
61 - 'function (string)');
62 - mw.test.addTest('$.trimRight(\' foo bar \')',
63 - ' foo bar (string)');
64 - mw.test.addTest('typeof $.isEmpty',
65 - 'function (string)');
66 - mw.test.addTest('$.isEmpty(\'string\')',
67 - 'false (boolean)');
68 - mw.test.addTest('$.isEmpty(\'0\')',
69 - 'true (boolean)');
70 - mw.test.addTest('$.isEmpty([])',
71 - 'true (boolean)');
72 - mw.test.addTest('typeof $.compareArray',
73 - 'function (string)');
74 - mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
75 - 'true (boolean)');
76 - mw.test.addTest('$.compareArray( [1], [2] )',
77 - 'false (boolean)');
78 - mw.test.addTest('4',
79 - '4 (number)');
80 - mw.test.addTest('typeof mediaWiki',
81 - 'object (string)');
82 - mw.test.addTest('typeof mw',
83 - 'object (string)');
84 - mw.test.addTest('typeof mw.util',
85 - 'object (string)');
86 - mw.test.addTest('typeof mw.html',
87 - 'object (string)');
88 - mw.test.addTest('typeof $.ucFirst',
89 - 'function (string)');
90 - mw.test.addTest('$.ucFirst( \'mediawiki\' )',
91 - 'Mediawiki (string)');
92 - mw.test.addTest('typeof $.escapeRE',
93 - 'function (string)');
94 - mw.test.addTest('$.escapeRE( \'.st{e}$st\' )',
95 - '\\.st\\{e\\}\\$st (string)');
96 - mw.test.addTest('typeof $.fn.checkboxShiftClick',
97 - 'function (string)');
98 - mw.test.addTest('typeof mw.util.rawurlencode',
99 - 'function (string)');
100 - mw.test.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )',
101 - 'Test%3A%20A%26B%2FHere (string)');
102 - mw.test.addTest('typeof mw.util.wikiGetlink',
103 - 'function (string)');
104 - mw.test.addTest('typeof mw.util.getParamValue',
105 - 'function (string)');
106 - mw.test.addTest('mw.util.getParamValue( \'action\' )',
107 - 'mwutiltest (string)');
108 - mw.test.addTest('mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
109 - 'right (string)');
110 - mw.test.addTest('mw.util.tooltipAccessKeyRegexp.constructor.name',
111 - 'RegExp (string)');
112 - mw.test.addTest('typeof mw.util.updateTooltipAccessKeys',
113 - 'function (string)');
114 - mw.test.addTest('typeof mw.util.addPortletLink',
115 - 'function (string)');
116 - mw.test.addTest('typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
117 - 'object (string)');
118 - mw.test.addTest('a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" ); $(a).text();',
119 - 'MediaWiki.org (string)');
120 - mw.test.addTest('mw.html.element( \'hr\' )',
121 - '<hr/> (string)');
122 - mw.test.addTest('mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
123 - '<img src="http://mw.org/?title=Main page&amp;action=edit"/> (string)');
 60+ mw.test.addTest( 'typeof $.trimLeft',
 61+ 'function (string)' );
 62+ mw.test.addTest( '$.trimLeft(\' foo bar \')',
 63+ 'foo bar (string)' );
 64+ mw.test.addTest( 'typeof $.trimRight',
 65+ 'function (string)' );
 66+ mw.test.addTest( '$.trimRight(\' foo bar \')',
 67+ ' foo bar (string)' );
 68+ mw.test.addTest( 'typeof $.isEmpty',
 69+ 'function (string)' );
 70+ mw.test.addTest( '$.isEmpty(\'string\')',
 71+ 'false (boolean)' );
 72+ mw.test.addTest( '$.isEmpty(\'0\')',
 73+ 'true (boolean)' );
 74+ mw.test.addTest( '$.isEmpty([])',
 75+ 'true (boolean)' );
 76+ mw.test.addTest( 'typeof $.compareArray',
 77+ 'function (string)' );
 78+ mw.test.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
 79+ 'true (boolean)' );
 80+ mw.test.addTest( '$.compareArray( [1], [2] )',
 81+ 'false (boolean)' );
 82+ mw.test.addTest( '4',
 83+ '4 (number)' );
 84+ mw.test.addTest( 'typeof mediaWiki',
 85+ 'object (string)' );
 86+ mw.test.addTest( 'typeof mw',
 87+ 'object (string)' );
 88+ mw.test.addTest( 'typeof mw.util',
 89+ 'object (string)' );
 90+ mw.test.addTest( 'typeof mw.html',
 91+ 'object (string)' );
 92+ mw.test.addTest( 'typeof $.ucFirst',
 93+ 'function (string)' );
 94+ mw.test.addTest( '$.ucFirst( \'mediawiki\' )',
 95+ 'Mediawiki (string)' );
 96+ mw.test.addTest( 'typeof $.escapeRE',
 97+ 'function (string)' );
 98+ mw.test.addTest( '$.escapeRE( \'.st{e}$st\' )',
 99+ '\\.st\\{e\\}\\$st (string)' );
 100+ mw.test.addTest( 'typeof $.fn.checkboxShiftClick',
 101+ 'function (string)' );
 102+ mw.test.addTest( 'typeof mw.util.rawurlencode',
 103+ 'function (string)' );
 104+ mw.test.addTest( 'mw.util.rawurlencode( \'Test: A&B/Here\' )',
 105+ 'Test%3A%20A%26B%2FHere (string)' );
 106+ mw.test.addTest( 'typeof mw.util.wikiGetlink',
 107+ 'function (string)' );
 108+ mw.test.addTest( 'typeof mw.util.getParamValue',
 109+ 'function (string)' );
 110+ mw.test.addTest( 'mw.util.getParamValue( \'action\' )',
 111+ 'mwutiltest (string)' );
 112+ mw.test.addTest( 'mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )',
 113+ 'right (string)' );
 114+ mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name',
 115+ 'RegExp (string)' );
 116+ mw.test.addTest( 'typeof mw.util.updateTooltipAccessKeys',
 117+ 'function (string)' );
 118+ mw.test.addTest( 'typeof mw.util.addPortletLink',
 119+ 'function (string)' );
 120+ mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )',
 121+ 'object (string)' );
 122+ mw.test.addTest( 'a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" ); $(a).text();',
 123+ 'MediaWiki.org (string)' );
 124+ mw.test.addTest( 'mw.html.element( \'hr\' )',
 125+ '<hr/> (string)' );
 126+ mw.test.addTest( 'mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )',
 127+ '<img src="http://mw.org/?title=Main page&amp;action=edit"/> (string)' );
124128
125129 // Run tests and compare results
126130 var exec,
@@ -130,34 +134,35 @@
131135 numberofpartials = 0,
132136 numberoferrors = 0,
133137 $testrows;
134 - $testrows = mw.test.$table.find('tr');
135 - $.each(mw.test.addedTests, (function ( i ) {
136 - numberoftests++;
 138+ $testrows = mw.test.$table.find( 'tr' );
 139+ $.each( mw.test.addedTests, function( i ) {
 140+ numberoftests++;
137141
138 - exec = mw.test.addedTests[i][0];
139 - shouldreturn = mw.test.addedTests[i][1];
140 - shouldcontain = mw.test.addedTests[i][2];
141 - doesreturn = eval(exec);
142 - doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
143 - $thisrow = $testrows.eq(i + 1);
144 - $thisrow.find('> td').eq(2).html( mw.html.escape(doesreturn).replace(/ /g, '&nbsp;&nbsp;') );
 142+ exec = mw.test.addedTests[i][0];
 143+ shouldreturn = mw.test.addedTests[i][1];
 144+ shouldcontain = mw.test.addedTests[i][2];
 145+ doesreturn = eval( exec );
 146+ doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
 147+ $thisrow = $testrows.eq( i + 1 );
 148+ $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, '&nbsp;&nbsp;' ) );
145149
146 - if (doesreturn.indexOf(shouldcontain) !== -1) {
147 - if (doesreturn == shouldreturn){
148 - $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
149 - numberofpasseds++;
150 - } else {
151 - $thisrow.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>');
152 - numberofpartials++;
153 - }
 150+ if (doesreturn.indexOf(shouldcontain) !== -1) {
 151+ if (doesreturn == shouldreturn){
 152+ $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' );
 153+ numberofpasseds++;
154154 } else {
155 - $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR');
156 - numberoferrors++;
 155+ $thisrow.find( '> td' ).eq(3).css( 'background', '#FFE' ).html( '<small>PARTIALLY</small>' );
 156+ numberofpartials++;
157157 }
 158+ } else {
 159+ $thisrow.find( '> td' ).eq(3).css( 'background', '#FEE' ).text( 'ERROR' );
 160+ numberoferrors++;
 161+ }
158162
159 - })
160 - );
161 - mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s). </p>');
 163+ } );
 164+ mw.test.$table.before( '<p><strong>Ran ' + numberoftests + ' tests. ' +
 165+ numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' +
 166+ numberofpartials + ' partially passed test(s). </p>' );
162167
163168 }
164169 });
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -292,11 +292,16 @@
293293 this.log = function() { };
294294
295295 /*
 296+ * Make the Map-class publicly available
 297+ */
 298+ this.Map = Map;
 299+
 300+ /*
296301 * List of configuration values
297302 *
298303 * In legacy mode the values this object wraps will be in the global space
299304 */
300 - this.config = new Map( LEGACY_GLOBALS );
 305+ this.config = new this.Map( LEGACY_GLOBALS );
301306
302307 /*
303308 * Information about the current user
@@ -306,7 +311,7 @@
307312 /*
308313 * Localization system
309314 */
310 - this.messages = new Map();
 315+ this.messages = new this.Map();
311316
312317 /* Public Methods */
313318

Comments

#Comment by Krinkle (talk | contribs)   20:15, 13 December 2010

I forgot that I had the whitespace fixes queued up for committing as well :

  • Make the Map-class publicly available
  • Whitespace cleanup of mediaWiki.util.test (wasn't done yet accordig to the conventions)

Status & tagging log