r75325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75324‎ | r75325 | r75326 >
Date:17:40, 24 October 2010
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
adding debug test suit for mediaWiki.util, visible on Special:MWUtilTest?debug=true
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.utiltest.js (added) (history)

Diff [purge]

Index: trunk/phase3/resources/Resources.php
@@ -328,6 +328,7 @@
329329 ) ),
330330 'mediawiki.util' => new ResourceLoaderFileModule( array(
331331 'scripts' => 'resources/mediawiki/mediawiki.util.js',
 332+ 'debugScripts' => 'resources/mediawiki/mediawiki.utiltest.js',
332333 ) ),
333334
334335 /* MediaWiki Legacy */
Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -26,7 +26,7 @@
2727 } else if (is_ff2) {
2828 this.tooltipAccessKeyPrefix = 'alt-shift-';
2929 }
30 -
 30+
3131 // Setup CheckboxShiftClick
3232 $.fn.enableCheckboxShiftClick = function () {
3333 var prevCheckbox = null;
@@ -42,17 +42,17 @@
4343 });
4444 return $box;
4545 };
46 -
 46+
4747 // Prototype enhancements
4848 if (typeof String.prototype.ucFirst === 'undefined') {
4949 String.prototype.ucFirst = function () {
5050 return this.substr(0, 1).toUpperCase() + this.substr(1, this.length);
5151 };
5252 }
53 -
 53+
5454 // Any initialisation after the DOM is ready
5555 $(function () {
56 - $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
 56+ $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
5757 });
5858
5959
@@ -96,7 +96,7 @@
9797
9898 /**
9999 * Check is a variable is empty. Support for strings, booleans, arrays and objects.
100 - * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
 100+ * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
101101 *
102102 * @param Mixed v the variable to check for empty ness
103103 */
@@ -281,6 +281,6 @@
282282
283283 };
284284
285 -})(jQuery, mediaWiki);
 285+ mediaWiki.util.init();
286286
287 -mediaWiki.util.init();
\ No newline at end of file
 287+})(jQuery, mediaWiki);
\ No newline at end of file
Index: trunk/phase3/resources/mediawiki/mediawiki.utiltest.js
@@ -0,0 +1,137 @@
 2+/*
 3+ * mediaWiki Debug Test Suit on [[Special:MWUtilJSTest]] (only when ?debug=true)
 4+ */
 5+
 6+(function ($, mw) {
 7+
 8+ mediaWiki.test = {
 9+
 10+ /* Variables */
 11+ '$bodyContent' : null,
 12+ '$table' : null,
 13+ 'addedTests' : [],
 14+
 15+ /* Functions */
 16+
 17+ /**
 18+ * Adds a row to the test-table
 19+ *
 20+ * @param String code Code of the test to be executed
 21+ * @param String result Expected result in 'var (vartype)' form.
 22+ */
 23+ 'addTest' : function (code, result) {
 24+ this.addedTests.push([code, result]);
 25+ this.$table.append('<tr><td>' + mw.util.htmlEscape(code) + '</td><td>' + mw.util.htmlEscape(result) + '<td></td></td><td>?</td></tr>');
 26+ },
 27+
 28+ /* Initialisation */
 29+ 'initialised' : false,
 30+ 'init' : function () {
 31+ if (this.initialised === false) {
 32+ this.initialised = true;
 33+ $(function () {
 34+ if (wgTitle == 'MWUtilJSTest' && wgCanonicalNamespace == 'Special') {
 35+
 36+ // Build page
 37+ document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName;
 38+ $('#firstHeading').text('mediaWiki.util JavaScript Test');
 39+ mw.test.bodyContent = $('#bodyContent');
 40+ mw.test.bodyContent.html(
 41+ '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
 42+ '<hr />' +
 43+ '<table id="mw-mwutiltest-table" class="wikitable sortable"><tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr></table>'
 44+ );
 45+ mw.test.$table = $('table#mw-mwutiltest-table');
 46+
 47+ // Populate tests
 48+ mw.test.addTest('typeof String.prototype.trim',
 49+ 'function (string)');
 50+ mw.test.addTest('typeof String.prototype.trimLeft',
 51+ 'function (string)');
 52+ mw.test.addTest('typeof String.prototype.trimRight',
 53+ 'function (string)');
 54+ mw.test.addTest('typeof Array.prototype.compare',
 55+ 'function (string)');
 56+ mw.test.addTest('typeof Array.prototype.indexOf',
 57+ 'function (string)');
 58+ mw.test.addTest('4',
 59+ '4 (number)');
 60+ mw.test.addTest('typeof mediaWiki',
 61+ 'object (string)');
 62+ mw.test.addTest('typeof mw',
 63+ 'object (string)');
 64+ mw.test.addTest('typeof mw.util',
 65+ 'object (string)');
 66+ mw.test.addTest('typeof String.prototype.ucFirst',
 67+ 'function (string)');
 68+ mw.test.addTest('\'mediawiki\'.ucFirst()',
 69+ 'Mediawiki (string)');
 70+ mw.test.addTest('typeof $.fn.enableCheckboxShiftClick',
 71+ 'function (string)');
 72+ mw.test.addTest('typeof mw.util.rawurlencode',
 73+ 'function (string)');
 74+ mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')',
 75+ 'Test%3A%20A%26B%2FHere (string)');
 76+ mw.test.addTest('typeof mw.util.getWikilink',
 77+ 'function (string)');
 78+ mw.test.addTest('typeof mw.util.getParamValue',
 79+ 'function (string)');
 80+ mw.test.addTest('mw.util.getParamValue(\'debug\')',
 81+ 'true (string)');
 82+ mw.test.addTest('typeof mw.util.htmlEscape',
 83+ 'function (string)');
 84+ mw.test.addTest('mw.util.htmlEscape(\'<a href="http://mw.org/?a=b&c=d">link</a>\')',
 85+ '&lt;a href="http://mw.org/?a=b&amp;c=d"&gt;link&lt;/a&gt; (string)');
 86+ mw.test.addTest('typeof mw.util.htmlUnescape',
 87+ 'function (string)');
 88+ mw.test.addTest('mw.util.htmlUnescape(\'&lt;a href="http://mw.org/?a=b&amp;c=d"&gt;link&lt;/a&gt;\')',
 89+ '<a href="http://mw.org/?a=b&c=d">link</a> (string)');
 90+ mw.test.addTest('typeof mw.util.tooltipAccessKeyRegexp',
 91+ 'function (string)');
 92+ mw.test.addTest('typeof mw.util.updateTooltipAccessKeys',
 93+ 'function (string)');
 94+ mw.test.addTest('typeof mw.util.addPortletLink',
 95+ 'function (string)');
 96+ mw.test.addTest('typeof mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print")',
 97+ 'object (string)');
 98+ mw.test.addTest('mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print").outerHTML',
 99+ '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)');
 100+
 101+ // Run tests and compare results
 102+ var exec,
 103+ result,
 104+ resulttype,
 105+ numberoftests = 0,
 106+ numberoferrors = 0,
 107+ $testrows;
 108+ $testrows = mw.test.$table.find('tr');
 109+ $.each(mw.test.addedTests, (function (i) {
 110+ numberoftests++;
 111+
 112+ exec = mw.test.addedTests[i][0];
 113+ shouldreturn = mw.test.addedTests[i][1];
 114+ doesreturn = eval(exec);
 115+ doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
 116+ $thisrow = $testrows.eq(i + 1);
 117+ $thisrow.find('> td').eq(2).text(doesreturn);
 118+
 119+ if (shouldreturn === doesreturn) {
 120+ $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
 121+ } else {
 122+ $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR');
 123+ numberoferrors++;
 124+ }
 125+
 126+ })
 127+ );
 128+ mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberoferrors + ' error(s). </p>');
 129+
 130+ }
 131+ });
 132+ }
 133+ }
 134+ };
 135+
 136+ mediaWiki.test.init();
 137+
 138+})(jQuery, mediaWiki);
\ No newline at end of file
Property changes on: trunk/phase3/resources/mediawiki/mediawiki.utiltest.js
___________________________________________________________________
Added: svn:eol-style
1139 + native
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -3,11 +3,11 @@
44 */
55
66 // New fallback String trimming functionality, was introduced natively in JavaScript 1.8.1
7 -if (typeof String.prototype.trimx === 'undefined') {
 7+if (typeof String.prototype.trim === 'undefined') {
88 // Add removing trailing and leading whitespace functionality cross-browser
99 // See also: http://blog.stevenlevithan.com/archives/faster-trim-javascript
1010 String.prototype.trim = function () {
11 - return this.replace(/^\s+|\s+$/g, '');
 11+ return this.replace(/^\s+|\s+$/g, '');
1212 };
1313 }
1414 if (typeof String.prototype.trimLeft === 'undefined') {
@@ -15,7 +15,7 @@
1616 return this.replace(/^\s\s*/, "");
1717 };
1818 }
19 -
 19+
2020 if (typeof String.prototype.trimRight === 'undefined') {
2121 String.prototype.trimRight = function () {
2222 return this.replace(/\s\s*$/, "");
@@ -59,18 +59,18 @@
6060 */
6161 // Attach to window
6262 window.mediaWiki = new ( function( $ ) {
63 -
 63+
6464 /* Constants */
65 -
 65+
6666 // This will not change until we are 100% ready to turn off legacy globals
6767 var LEGACY_GLOBALS = true;
68 -
 68+
6969 /* Private Members */
70 -
 70+
7171 var that = this;
72 -
 72+
7373 /* Prototypes */
74 -
 74+
7575 this.prototypes = {
7676 /*
7777 * An object which allows single and multiple get/set/exists functionality on a list of key / value pairs
@@ -81,14 +81,14 @@
8282 * where value is the data to be parsed and options is additional data passed through to the parser
8383 */
8484 'map': function( global, parser, fallback ) {
85 -
 85+
8686 /* Private Members */
87 -
 87+
8888 var that = this;
8989 var values = global === true ? window : {};
90 -
 90+
9191 /* Public Methods */
92 -
 92+
9393 /**
9494 * Gets one or more values
9595 *
@@ -138,7 +138,7 @@
139139 return values;
140140 }
141141 };
142 -
 142+
143143 /**
144144 * Sets one or multiple configuration values using a key and a value or an object of keys and values
145145 *
@@ -154,7 +154,7 @@
155155 values[selection] = value;
156156 }
157157 };
158 -
 158+
159159 /**
160160 * Checks if one or multiple configuration fields exist
161161 */
@@ -172,31 +172,31 @@
173173 };
174174 }
175175 };
176 -
 176+
177177 /* Methods */
178 -
 178+
179179 /*
180180 * Dummy function which in debug mode can be replaced with a function that does something clever
181181 */
182182 this.log = function() { };
183 -
 183+
184184 /*
185185 * List of configuration values
186186 *
187187 * In legacy mode the values this object wraps will be in the global space
188188 */
189189 this.config = new this.prototypes.map( LEGACY_GLOBALS );
190 -
 190+
191191 /*
192192 * Information about the current user
193193 */
194194 this.user = new ( function() {
195 -
 195+
196196 /* Public Members */
197 -
 197+
198198 this.options = new that.prototypes.map();
199199 } )();
200 -
 200+
201201 /*
202202 * Basic parser, can be replaced with something more robust
203203 */
@@ -209,19 +209,19 @@
210210 }
211211 return text;
212212 };
213 -
 213+
214214 /*
215215 * Localization system
216216 */
217217 this.msg = new that.prototypes.map( false, this.parser, function( key ) { return '<' + key + '>'; } );
218 -
 218+
219219 /*
220220 * Client-side module loader which integrates with the MediaWiki ResourceLoader
221221 */
222222 this.loader = new ( function() {
223 -
 223+
224224 /* Private Members */
225 -
 225+
226226 var that = this;
227227 /*
228228 * Mapping of registered modules
@@ -253,9 +253,9 @@
254254 var suspended = true;
255255 // Flag inidicating that document ready has occured
256256 var ready = false;
257 -
 257+
258258 /* Private Methods */
259 -
 259+
260260 /**
261261 * Generates an ISO8601 "basic" string from a UNIX timestamp
262262 */
@@ -270,7 +270,7 @@
271271 pad( d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds() ), 'Z'
272272 ].join( '' );
273273 }
274 -
 274+
275275 /**
276276 * Recursively resolves dependencies and detects circular references
277277 */
@@ -298,7 +298,7 @@
299299 resolved[resolved.length] = module;
300300 unresolved.splice( unresolved.indexOf( module ), 1 );
301301 }
302 -
 302+
303303 /**
304304 * Gets a list of modules names that a module dependencies in their proper dependency order
305305 *
@@ -328,7 +328,7 @@
329329 }
330330 throw new Error( 'Invalid module argument: ' + module );
331331 };
332 -
 332+
333333 /**
334334 * Narrows a list of module names down to those matching a specific state. Possible states are 'undefined',
335335 * 'registered', 'loading', 'loaded', or 'ready'
@@ -363,7 +363,7 @@
364364 }
365365 return list;
366366 }
367 -
 367+
368368 /**
369369 * Executes a loaded module, making it ready to use
370370 *
@@ -418,7 +418,7 @@
419419 } catch ( e ) {
420420 mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message );
421421 mediaWiki.log( e );
422 - registry[module].state = 'error';
 422+ registry[module].state = 'error';
423423 // Run error callbacks of jobs affected by this condition
424424 for ( var j = 0; j < jobs.length; j++ ) {
425425 if ( jobs[j].dependencies.indexOf( module ) !== -1 ) {
@@ -431,7 +431,7 @@
432432 }
433433 }
434434 }
435 -
 435+
436436 /**
437437 * Adds a dependencies to the queue with optional callbacks to be run when the dependencies are ready or fail
438438 *
@@ -467,7 +467,7 @@
468468 // Work the queue
469469 that.work();
470470 }
471 -
 471+
472472 function sortQuery(o) {
473473 var sorted = {}, key, a = [];
474474 for ( key in o ) {
@@ -481,9 +481,9 @@
482482 }
483483 return sorted;
484484 }
485 -
 485+
486486 /* Public Methods */
487 -
 487+
488488 /**
489489 * Requests dependencies from server, loading and executing when things when ready.
490490 */
@@ -560,7 +560,7 @@
561561 }
562562 }
563563 };
564 -
 564+
565565 /**
566566 * Registers a module, letting the system know about it and it's dependencies. loader.js files contain calls
567567 * to this function.
@@ -599,7 +599,7 @@
600600 registry[module].dependencies = dependencies;
601601 }
602602 };
603 -
 603+
604604 /**
605605 * Implements a module, giving the system a course of action to take upon loading. Results of a request for
606606 * one or more modules contain calls to this function.
@@ -639,7 +639,7 @@
640640 request( module );
641641 }
642642 };
643 -
 643+
644644 /**
645645 * Executes a function as soon as one or more required modules are ready
646646 *
@@ -676,7 +676,7 @@
677677 request( dependencies, ready, error );
678678 }
679679 };
680 -
 680+
681681 /**
682682 * Loads an external script or one or more modules for future use
683683 *
@@ -727,7 +727,7 @@
728728 return true;
729729 }
730730 };
731 -
 731+
732732 /**
733733 * Flushes the request queue and begin executing load requests on demand
734734 */
@@ -735,7 +735,7 @@
736736 suspended = false;
737737 that.work();
738738 };
739 -
 739+
740740 /**
741741 * Changes the state of a module
742742 *
@@ -754,7 +754,7 @@
755755 }
756756 registry[module].state = state;
757757 };
758 -
 758+
759759 /**
760760 * Gets the version of a module
761761 *
@@ -766,16 +766,16 @@
767767 }
768768 return null;
769769 }
770 -
 770+
771771 /* Cache document ready status */
772 -
 772+
773773 $(document).ready( function() { ready = true; } );
774774 } )();
775 -
 775+
776776 /* Extension points */
777 -
 777+
778778 this.legacy = {};
779 -
 779+
780780 } )( jQuery );
781781
782782 /* Auto-register from pre-loaded startup scripts */

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   00:07, 13 January 2011

What's this MWUtilTest special page? I don't see it in core or extensions, nor is it showing up when I go to it on my local wiki.

#Comment by Trevor Parscal (WMF) (talk | contribs)   00:08, 13 January 2011

Nevermind, you answered my question in r75326.

Status & tagging log