From e889e4fbec8d3867c0a894b362b92dc49f0b3ef6 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Mon, 13 Dec 2010 20:13:39 +0000 Subject: [PATCH] Make the Map-class publicly available --- .../mediawiki.util/mediawiki.util.test.js | 211 +++++++++--------- resources/mediawiki/mediawiki.js | 9 +- 2 files changed, 115 insertions(+), 105 deletions(-) diff --git a/resources/mediawiki.util/mediawiki.util.test.js b/resources/mediawiki.util/mediawiki.util.test.js index 7c4cc9dbd3..0a65c26119 100644 --- a/resources/mediawiki.util/mediawiki.util.test.js +++ b/resources/mediawiki.util/mediawiki.util.test.js @@ -21,105 +21,109 @@ * * @param code String Code of the test to be executed * @param result String Expected result in 'var (vartype)' form - * @param contain String Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY + * @param contain String Important part of the result, + * if result is different but does contain this it will not return ERROR but PARTIALLY */ 'addTest' : function( code, result, contain ) { if (!contain) { contain = result; } - this.addedTests.push([code, result, contain]); - this.$table.append('' + mw.html.escape(code).replace(/ /g, '  ') + '' + mw.html.escape(result).replace(/ /g, '  ') + '?'); + this.addedTests.push( [code, result, contain] ); + this.$table.append( '' + mw.html.escape(code).replace(/ /g, '  ' ) + + '' + mw.html.escape(result).replace(/ /g, '  ' ) + + '?' ); }, /* Initialisation */ 'initialised' : false, 'init' : function () { - if (this.initialised === false) { + if ( this.initialised === false ) { this.initialised = true; $(function () { - if (wgCanonicalSpecialPageName == 'Blankpage' && mw.util.getParamValue('action') === 'mwutiltest') { + if ( wgCanonicalSpecialPageName == 'Blankpage' + && mw.util.getParamValue( 'action' ) === 'mwutiltest' ) { // Build page document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName; - $('#firstHeading').text('mediaWiki.util JavaScript Test'); + $( '#firstHeading' ).text( 'mediaWiki.util JavaScript Test' ); mw.util.$content.html( - '

Below is a list of tests to confirm proper functionality of the mediaWiki.util functions

' + - '
' + - '' + - '' + - '
ExecShould returnDoes returnEqual ?
' + '

Below is a list of tests to confirm proper functionality of the mediaWiki.util functions

' + + '
' + + '' + + '' + + '
ExecShould returnDoes returnEqual ?
' ); - mw.test.$table = $('table#mw-mwutiltest-table'); + mw.test.$table = $( 'table#mw-mwutiltest-table' ); // Populate tests - mw.test.addTest('typeof $.trimLeft', - 'function (string)'); - mw.test.addTest('$.trimLeft(\' foo bar \')', - 'foo bar (string)'); - mw.test.addTest('typeof $.trimRight', - 'function (string)'); - mw.test.addTest('$.trimRight(\' foo bar \')', - ' foo bar (string)'); - mw.test.addTest('typeof $.isEmpty', - 'function (string)'); - mw.test.addTest('$.isEmpty(\'string\')', - 'false (boolean)'); - mw.test.addTest('$.isEmpty(\'0\')', - 'true (boolean)'); - mw.test.addTest('$.isEmpty([])', - 'true (boolean)'); - mw.test.addTest('typeof $.compareArray', - 'function (string)'); - mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )', - 'true (boolean)'); - mw.test.addTest('$.compareArray( [1], [2] )', - 'false (boolean)'); - mw.test.addTest('4', - '4 (number)'); - mw.test.addTest('typeof mediaWiki', - 'object (string)'); - mw.test.addTest('typeof mw', - 'object (string)'); - mw.test.addTest('typeof mw.util', - 'object (string)'); - mw.test.addTest('typeof mw.html', - 'object (string)'); - mw.test.addTest('typeof $.ucFirst', - 'function (string)'); - mw.test.addTest('$.ucFirst( \'mediawiki\' )', - 'Mediawiki (string)'); - mw.test.addTest('typeof $.escapeRE', - 'function (string)'); - mw.test.addTest('$.escapeRE( \'.st{e}$st\' )', - '\\.st\\{e\\}\\$st (string)'); - mw.test.addTest('typeof $.fn.checkboxShiftClick', - 'function (string)'); - mw.test.addTest('typeof mw.util.rawurlencode', - 'function (string)'); - mw.test.addTest('mw.util.rawurlencode( \'Test: A&B/Here\' )', - 'Test%3A%20A%26B%2FHere (string)'); - mw.test.addTest('typeof mw.util.wikiGetlink', - 'function (string)'); - mw.test.addTest('typeof mw.util.getParamValue', - 'function (string)'); - mw.test.addTest('mw.util.getParamValue( \'action\' )', - 'mwutiltest (string)'); - mw.test.addTest('mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )', - 'right (string)'); - mw.test.addTest('mw.util.tooltipAccessKeyRegexp.constructor.name', - 'RegExp (string)'); - mw.test.addTest('typeof mw.util.updateTooltipAccessKeys', - 'function (string)'); - mw.test.addTest('typeof mw.util.addPortletLink', - 'function (string)'); - mw.test.addTest('typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )', - 'object (string)'); - 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();', - 'MediaWiki.org (string)'); - mw.test.addTest('mw.html.element( \'hr\' )', - '
(string)'); - mw.test.addTest('mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )', - ' (string)'); + mw.test.addTest( 'typeof $.trimLeft', + 'function (string)' ); + mw.test.addTest( '$.trimLeft(\' foo bar \')', + 'foo bar (string)' ); + mw.test.addTest( 'typeof $.trimRight', + 'function (string)' ); + mw.test.addTest( '$.trimRight(\' foo bar \')', + ' foo bar (string)' ); + mw.test.addTest( 'typeof $.isEmpty', + 'function (string)' ); + mw.test.addTest( '$.isEmpty(\'string\')', + 'false (boolean)' ); + mw.test.addTest( '$.isEmpty(\'0\')', + 'true (boolean)' ); + mw.test.addTest( '$.isEmpty([])', + 'true (boolean)' ); + mw.test.addTest( 'typeof $.compareArray', + 'function (string)' ); + mw.test.addTest( '$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )', + 'true (boolean)' ); + mw.test.addTest( '$.compareArray( [1], [2] )', + 'false (boolean)' ); + mw.test.addTest( '4', + '4 (number)' ); + mw.test.addTest( 'typeof mediaWiki', + 'object (string)' ); + mw.test.addTest( 'typeof mw', + 'object (string)' ); + mw.test.addTest( 'typeof mw.util', + 'object (string)' ); + mw.test.addTest( 'typeof mw.html', + 'object (string)' ); + mw.test.addTest( 'typeof $.ucFirst', + 'function (string)' ); + mw.test.addTest( '$.ucFirst( \'mediawiki\' )', + 'Mediawiki (string)' ); + mw.test.addTest( 'typeof $.escapeRE', + 'function (string)' ); + mw.test.addTest( '$.escapeRE( \'.st{e}$st\' )', + '\\.st\\{e\\}\\$st (string)' ); + mw.test.addTest( 'typeof $.fn.checkboxShiftClick', + 'function (string)' ); + mw.test.addTest( 'typeof mw.util.rawurlencode', + 'function (string)' ); + mw.test.addTest( 'mw.util.rawurlencode( \'Test: A&B/Here\' )', + 'Test%3A%20A%26B%2FHere (string)' ); + mw.test.addTest( 'typeof mw.util.wikiGetlink', + 'function (string)' ); + mw.test.addTest( 'typeof mw.util.getParamValue', + 'function (string)' ); + mw.test.addTest( 'mw.util.getParamValue( \'action\' )', + 'mwutiltest (string)' ); + mw.test.addTest( 'mw.util.getParamValue( \'foo\', \'http://mw.org/?foo=wrong&foo=right#&foo=bad\' )', + 'right (string)' ); + mw.test.addTest( 'mw.util.tooltipAccessKeyRegexp.constructor.name', + 'RegExp (string)' ); + mw.test.addTest( 'typeof mw.util.updateTooltipAccessKeys', + 'function (string)' ); + mw.test.addTest( 'typeof mw.util.addPortletLink', + 'function (string)' ); + mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print" )', + 'object (string)' ); + 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();', + 'MediaWiki.org (string)' ); + mw.test.addTest( 'mw.html.element( \'hr\' )', + '
(string)' ); + mw.test.addTest( 'mw.html.element( \'img\', { \'src\': \'http://mw.org/?title=Main page&action=edit\' } )', + ' (string)' ); // Run tests and compare results var exec, @@ -130,34 +134,35 @@ numberofpartials = 0, numberoferrors = 0, $testrows; - $testrows = mw.test.$table.find('tr'); - $.each(mw.test.addedTests, (function ( i ) { - numberoftests++; + $testrows = mw.test.$table.find( 'tr' ); + $.each( mw.test.addedTests, function( i ) { + numberoftests++; - exec = mw.test.addedTests[i][0]; - shouldreturn = mw.test.addedTests[i][1]; - shouldcontain = mw.test.addedTests[i][2]; - doesreturn = eval(exec); - doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; - $thisrow = $testrows.eq(i + 1); - $thisrow.find('> td').eq(2).html( mw.html.escape(doesreturn).replace(/ /g, '  ') ); + exec = mw.test.addedTests[i][0]; + shouldreturn = mw.test.addedTests[i][1]; + shouldcontain = mw.test.addedTests[i][2]; + doesreturn = eval( exec ); + doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; + $thisrow = $testrows.eq( i + 1 ); + $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, '  ' ) ); - if (doesreturn.indexOf(shouldcontain) !== -1) { - if (doesreturn == shouldreturn){ - $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); - numberofpasseds++; - } else { - $thisrow.find('> td').eq(3).css('background', '#FFE').html('PARTIALLY'); - numberofpartials++; - } + if (doesreturn.indexOf(shouldcontain) !== -1) { + if (doesreturn == shouldreturn){ + $thisrow.find( '> td' ).eq(3).css( 'background', '#EFE' ).text( 'OK' ); + numberofpasseds++; } else { - $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR'); - numberoferrors++; + $thisrow.find( '> td' ).eq(3).css( 'background', '#FFE' ).html( 'PARTIALLY' ); + numberofpartials++; } + } else { + $thisrow.find( '> td' ).eq(3).css( 'background', '#FEE' ).text( 'ERROR' ); + numberoferrors++; + } - }) - ); - mw.test.$table.before('

Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s).

'); + } ); + mw.test.$table.before( '

Ran ' + numberoftests + ' tests. ' + + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + + numberofpartials + ' partially passed test(s).

' ); } }); diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 115304569d..7f20504fd0 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -291,12 +291,17 @@ window.mediaWiki = new ( function( $ ) { */ this.log = function() { }; + /* + * Make the Map-class publicly available + */ + this.Map = Map; + /* * List of configuration values * * In legacy mode the values this object wraps will be in the global space */ - this.config = new Map( LEGACY_GLOBALS ); + this.config = new this.Map( LEGACY_GLOBALS ); /* * Information about the current user @@ -306,7 +311,7 @@ window.mediaWiki = new ( function( $ ) { /* * Localization system */ - this.messages = new Map(); + this.messages = new this.Map(); /* Public Methods */ -- 2.20.1