r55555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55554‎ | r55555 | r55556 >
Date:17:15, 24 August 2009
Author:dantman
Status:reverted (Comments)
Tags:
Comment:
- Use array literals instead of new Array(); (note that `new Array;` without () is actually supposed to break in IE6 iirc)
- Use RegExp literals instead of new RegExp(...); when unnecessary.
- Fix bad use of object iteration on an array bug20376
Modified paths:
  • /trunk/phase3/skins/common/mwsuggest.js (modified) (history)
  • /trunk/phase3/skins/common/protect.js (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/mwsuggest.js
@@ -24,8 +24,8 @@
2525 // delay between keypress and suggestion (in ms)
2626 var os_search_timeout = 250;
2727 // these pairs of inputs/forms will be autoloaded at startup
28 -var os_autoload_inputs = new Array('searchInput', 'searchInput2', 'powerSearchText', 'searchText');
29 -var os_autoload_forms = new Array('searchform', 'searchform2', 'powersearch', 'search' );
 28+var os_autoload_inputs = ['searchInput', 'searchInput2', 'powerSearchText', 'searchText'];
 29+var os_autoload_forms = ['searchform', 'searchform2', 'powersearch', 'search'];
3030 // if we stopped the service
3131 var os_is_stopped = false;
3232 // max lines to show in suggest table
@@ -364,7 +364,7 @@
365365 var c = document.getElementById(r.container);
366366 var width = c.offsetWidth - os_operaWidthFix(c.offsetWidth);
367367 var html = "<table class=\"os-suggest-results\" id=\""+r.resultTable+"\" style=\"width: "+width+"px;\">";
368 - r.results = new Array();
 368+ r.results = [];
369369 r.resultCount = results.length;
370370 for(i=0;i<results.length;i++){
371371 var title = os_decodeValue(results[i]);
Index: trunk/phase3/skins/common/wikibits.js
@@ -181,23 +181,14 @@
182182 var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
183183
184184 function escapeQuotes(text) {
185 - var re = new RegExp("'","g");
186 - text = text.replace(re,"\\'");
187 - re = new RegExp("\\n","g");
188 - text = text.replace(re,"\\n");
189 - return escapeQuotesHTML(text);
 185+ return escapeQuotesHTML(text.replace(/'/g,"\\'").replace(/\n/g,"\\n"));
190186 }
191187
192188 function escapeQuotesHTML(text) {
193 - var re = new RegExp('&',"g");
194 - text = text.replace(re,"&amp;");
195 - re = new RegExp('"',"g");
196 - text = text.replace(re,"&quot;");
197 - re = new RegExp('<',"g");
198 - text = text.replace(re,"&lt;");
199 - re = new RegExp('>',"g");
200 - text = text.replace(re,"&gt;");
201 - return text;
 189+ return text.replace(/&/g,"&amp;")
 190+ .replace(/"/g,"&quot;")
 191+ .replace(/</gre,"&lt;")
 192+ .replace(/>/g,"&gt;");
202193 }
203194
204195
@@ -308,7 +299,7 @@
309300 link.setAttribute( "title", tooltip );
310301 }
311302 if ( accesskey && tooltip ) {
312 - updateTooltipAccessKeys( new Array( link ) );
 303+ updateTooltipAccessKeys( [link] );
313304 }
314305
315306 if ( nextnode && nextnode.parentNode == node )
@@ -354,7 +345,7 @@
355346 // A lot of user scripts (and some of the code below) break if
356347 // ta isn't defined, so we make sure it is. Explictly using
357348 // window.ta avoids a "ta is not defined" error.
358 - if (!window.ta) window.ta = new Array;
 349+ if (!window.ta) window.ta = [];
359350
360351 // Make a local, possibly restricted, copy to avoid clobbering
361352 // the original.
@@ -367,7 +358,7 @@
368359
369360 // Now deal with evil deprecated ta
370361 var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false;
371 - for (var id in ta) {
 362+ for (var id = 0; id < ta.length; id++) {
372363 var n = document.getElementById(id);
373364 if (n) {
374365 var a = null;
@@ -498,7 +489,7 @@
499490 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
500491 */
501492 function getElementsByClassName(oElm, strTagName, oClassNames){
502 - var arrReturnElements = new Array();
 493+ var arrReturnElements = [];
503494 if ( typeof( oElm.getElementsByClassName ) == "function" ) {
504495 /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
505496 var arrNativeReturn = oElm.getElementsByClassName( oClassNames );
@@ -511,7 +502,7 @@
512503 return arrReturnElements;
513504 }
514505 var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
515 - var arrRegExpClassNames = new Array();
 506+ var arrRegExpClassNames = [];
516507 if(typeof oClassNames == "object"){
517508 for(var i=0; i<oClassNames.length; i++){
518509 arrRegExpClassNames[arrRegExpClassNames.length] =
@@ -680,8 +671,8 @@
681672
682673 var reverse = (span.getAttribute("sortdir") == 'down');
683674
684 - var newRows = new Array();
685 - var staticRows = new Array();
 675+ var newRows = new [];
 676+ var staticRows = new [];
686677 for (var j = rowStart; j < table.rows.length; j++) {
687678 var row = table.rows[j];
688679 if((" "+row.className+" ").indexOf(" unsortable ") < 0) {
@@ -689,8 +680,8 @@
690681 var oldIndex = (reverse ? -j : j);
691682 var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") );
692683
693 - newRows[newRows.length] = new Array(row, preprocessed, oldIndex);
694 - } else staticRows[staticRows.length] = new Array(row, false, j-rowStart);
 684+ newRows[newRows.length] = new [row, preprocessed, oldIndex];
 685+ } else staticRows[staticRows.length] = [row, false, j-rowStart];
695686 }
696687
697688 newRows.sort(sortfn);
Index: trunk/phase3/skins/common/protect.js
@@ -250,7 +250,7 @@
251251 */
252252 'getLevelSelectors': function() {
253253 var all = document.getElementsByTagName("select");
254 - var ours = new Array();
 254+ var ours = [];
255255 for (var i = 0; i < all.length; i++) {
256256 var element = all[i];
257257 if (element.id.match(/^mwProtect-level-/)) {
@@ -279,7 +279,7 @@
280280 */
281281 'getExpiryInputs': function() {
282282 var all = document.getElementsByTagName("input");
283 - var ours = new Array();
 283+ var ours = [];
284284 for (var i = 0; i < all.length; i++) {
285285 var element = all[i];
286286 if (element.name.match(/^mwProtect-expiry-/)) {
@@ -307,7 +307,7 @@
308308 */
309309 'getExpirySelectors': function() {
310310 var all = document.getElementsByTagName("select");
311 - var ours = new Array();
 311+ var ours = [];
312312 for (var i = 0; i < all.length; i++) {
313313 var element = all[i];
314314 if (element.id.match(/^mwProtectExpirySelection-/)) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r55569* Revert r55555-55557 for now, breaks tabs in special preferences, don't know...nikerabbit13:56, 25 August 2009

Comments

#Comment by Nikerabbit (talk | contribs)   13:11, 25 August 2009

Breaks tabs at Special:Preferences (even after 55557).

Status & tagging log