r109717 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109716‎ | r109717 | r109718 >
Date:02:37, 22 January 2012
Author:krinkle
Status:ok
Tags:
Comment:
[mediawiki.util] minor code cleanup
* Remove distance between variable assignment and usage in mw.util.ini
* Change awkwardly indention from extended var statement into separate flush-left assignments and a simple var statement.
* whitespace etc. (ignore whitespace with -x-uw or on ViewVC diff)
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -11,11 +11,8 @@
1212 * Initialisation
1313 * (don't call before document ready)
1414 */
15 - init: function() {
16 - var profile = $.client.profile(),
17 - $tocTitle = $( '#toctitle' ),
18 - $tocToggleLink = $( '#togglelink' ),
19 - hideTocCookie;
 15+ init: function () {
 16+ var profile, $tocTitle, $tocToggleLink, hideTocCookie;
2017
2118 /* Set up $.messageBox */
2219 $.messageBoxNew( {
@@ -24,6 +21,7 @@
2522 } );
2623
2724 /* Set tooltipAccessKeyPrefix */
 25+ profile = $.client.profile();
2826
2927 // Opera on any platform
3028 if ( profile.name === 'opera' ) {
@@ -76,12 +74,14 @@
7775 }
7876
7977 // Table of contents toggle
 78+ $tocTitle = $( '#toctitle' );
 79+ $tocToggleLink = $( '#togglelink' );
8080 // Only add it if there is a TOC and there is no toggle added already
8181 if ( $( '#toc' ).length && $tocTitle.length && !$tocToggleLink.length ) {
8282 hideTocCookie = $.cookie( 'mw_hidetoc' );
8383 $tocToggleLink = $( '<a href="#" class="internal" id="togglelink"></a>' )
8484 .text( mw.msg( 'hidetoc' ) )
85 - .click( function( e ) {
 85+ .click( function ( e ) {
8686 e.preventDefault();
8787 util.toggleToc( $(this) );
8888 } );
@@ -106,7 +106,7 @@
107107 *
108108 * @param str string String to be encoded
109109 */
110 - rawurlencode: function( str ) {
 110+ rawurlencode: function ( str ) {
111111 str = String( str );
112112 return encodeURIComponent( str )
113113 .replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
@@ -120,7 +120,7 @@
121121 *
122122 * @param str string String to be encoded
123123 */
124 - wikiUrlencode: function( str ) {
 124+ wikiUrlencode: function ( str ) {
125125 return this.rawurlencode( str )
126126 .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
127127 },
@@ -131,7 +131,7 @@
132132 * @param str string Page name to get the link for.
133133 * @return string Location for a page with name of 'str' or boolean false on error.
134134 */
135 - wikiGetlink: function( str ) {
 135+ wikiGetlink: function ( str ) {
136136 return mw.config.get( 'wgArticlePath' ).replace( '$1',
137137 this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
138138 },
@@ -143,7 +143,7 @@
144144 * @param str string Name of script (eg. 'api'), defaults to 'index'
145145 * @return string Address to script (eg. '/w/api.php' )
146146 */
147 - wikiScript: function( str ) {
 147+ wikiScript: function ( str ) {
148148 return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) +
149149 mw.config.get( 'wgScriptExtension' );
150150 },
@@ -154,7 +154,7 @@
155155 * @param text string CSS to be appended
156156 * @return CSSStyleSheet
157157 */
158 - addCSS: function( text ) {
 158+ addCSS: function ( text ) {
159159 var s = document.createElement( 'style' );
160160 s.type = 'text/css';
161161 s.rel = 'stylesheet';
@@ -164,7 +164,7 @@
165165 s.styleSheet.cssText = text; // IE
166166 } else {
167167 // Safari sometimes borks on null
168 - s.appendChild( document.createTextNode( text + '' ) );
 168+ s.appendChild( document.createTextNode( String( text ) ) );
169169 }
170170 return s.sheet || s;
171171 },
@@ -178,7 +178,7 @@
179179 * @return mixed Boolean visibility of the toc (true if it's visible)
180180 * or Null if there was no table of contents.
181181 */
182 - toggleToc: function( $toggleLink, callback ) {
 182+ toggleToc: function ( $toggleLink, callback ) {
183183 var $tocList = $( '#toc ul:first' );
184184
185185 // This function shouldn't be called if there's no TOC,
@@ -216,7 +216,7 @@
217217 * @param url string URL to search through (optional)
218218 * @return mixed Parameter value or null.
219219 */
220 - getParamValue: function( param, url ) {
 220+ getParamValue: function ( param, url ) {
221221 url = url || document.location.href;
222222 // Get last match, stop at hash
223223 var re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ),
@@ -251,7 +251,7 @@
252252 * @param $nodes {Array|jQuery} [optional] A jQuery object, or array
253253 * of elements to update.
254254 */
255 - updateTooltipAccessKeys: function( $nodes ) {
 255+ updateTooltipAccessKeys: function ( $nodes ) {
256256 if ( !$nodes ) {
257257 // Rather than going into a loop of all anchor tags, limit to few elements that
258258 // contain the relevant anchor tags.
@@ -261,7 +261,7 @@
262262 $nodes = $( $nodes );
263263 }
264264
265 - $nodes.attr( 'title', function( i, val ) {
 265+ $nodes.attr( 'title', function ( i, val ) {
266266 if ( val && util.tooltipAccessKeyRegexp.exec( val ) ) {
267267 return val.replace( util.tooltipAccessKeyRegexp,
268268 '[' + util.tooltipAccessKeyPrefix + '$5]' );
@@ -312,7 +312,7 @@
313313 * @return mixed The DOM Node of the added item (a ListItem or Anchor element,
314314 * depending on the skin) or null if no element was added to the document.
315315 */
316 - addPortletLink: function( portlet, href, text, id, tooltip, accesskey, nextnode ) {
 316+ addPortletLink: function ( portlet, href, text, id, tooltip, accesskey, nextnode ) {
317317 var $item, $link, $portlet, $ul;
318318
319319 // Check if there's atleast 3 arguments to prevent a TypeError
@@ -328,14 +328,14 @@
329329 // Some skins don't have any portlets
330330 // just add it to the bottom of their 'sidebar' element as a fallback
331331 switch ( mw.config.get( 'skin' ) ) {
332 - case 'standard' :
333 - case 'cologneblue' :
 332+ case 'standard':
 333+ case 'cologneblue':
334334 $( '#quickbar' ).append( $link.after( '<br/>' ) );
335335 return $link[0];
336 - case 'nostalgia' :
 336+ case 'nostalgia':
337337 $( '#searchform' ).before( $link ).before( ' &#124; ' );
338338 return $link[0];
339 - default : // Skins like chick, modern, monobook, myskin, simple, vector...
 339+ default: // Skins like chick, modern, monobook, myskin, simple, vector...
340340
341341 // Select the specified portlet
342342 $portlet = $( '#' + portlet );
@@ -418,7 +418,7 @@
419419 * to allow CSS/JS to hide different boxes. null = no class used.
420420 * @return {Boolean} True on success, false on failure.
421421 */
422 - jsMessage: function( message, className ) {
 422+ jsMessage: function ( message, className ) {
423423 if ( !arguments.length || message === '' || message === null ) {
424424 $( '#mw-js-message' ).empty().hide();
425425 return true; // Emptying and hiding message is intended behaviour, return true
@@ -464,8 +464,10 @@
465465 * @return mixed Null if mailtxt was an empty string, otherwise true/false
466466 * is determined by validation.
467467 */
468 - validateEmail: function( mailtxt ) {
469 - if( mailtxt === '' ) {
 468+ validateEmail: function ( mailtxt ) {
 469+ var rfc5322_atext, rfc1034_ldh_str, HTML5_email_regexp;
 470+
 471+ if ( mailtxt === '' ) {
470472 return null;
471473 }
472474
@@ -481,7 +483,7 @@
482484 */
483485
484486 /**
485 - * First, define the RFC 5322 'atext' which is pretty easy :
 487+ * First, define the RFC 5322 'atext' which is pretty easy:
486488 * atext = ALPHA / DIGIT / ; Printable US-ASCII
487489 "!" / "#" / ; characters not including
488490 "$" / "%" / ; specials. Used for atoms.
@@ -494,7 +496,7 @@
495497 "|" / "}" /
496498 "~"
497499 */
498 - var rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~",
 500+ rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~";
499501
500502 /**
501503 * Next define the RFC 1034 'ldh-str'
@@ -505,29 +507,29 @@
506508 * <let-dig-hyp> ::= <let-dig> | "-"
507509 * <let-dig> ::= <letter> | <digit>
508510 */
509 - rfc1034_ldh_str = "a-z0-9\\-",
 511+ rfc1034_ldh_str = "a-z0-9\\-";
510512
511 - HTML5_email_regexp = new RegExp(
512 - // start of string
513 - '^'
514 - +
515 - // User part which is liberal :p
516 - '[' + rfc5322_atext + '\\.]+'
517 - +
518 - // 'at'
519 - '@'
520 - +
521 - // Domain first part
522 - '[' + rfc1034_ldh_str + ']+'
523 - +
524 - // Optional second part and following are separated by a dot
525 - '(?:\\.[' + rfc1034_ldh_str + ']+)*'
526 - +
527 - // End of string
528 - '$',
529 - // RegExp is case insensitive
530 - 'i'
531 - );
 513+ HTML5_email_regexp = new RegExp(
 514+ // start of string
 515+ '^'
 516+ +
 517+ // User part which is liberal :p
 518+ '[' + rfc5322_atext + '\\.]+'
 519+ +
 520+ // 'at'
 521+ '@'
 522+ +
 523+ // Domain first part
 524+ '[' + rfc1034_ldh_str + ']+'
 525+ +
 526+ // Optional second part and following are separated by a dot
 527+ '(?:\\.[' + rfc1034_ldh_str + ']+)*'
 528+ +
 529+ // End of string
 530+ '$',
 531+ // RegExp is case insensitive
 532+ 'i'
 533+ );
532534 return (null !== mailtxt.match( HTML5_email_regexp ) );
533535 },
534536
@@ -538,7 +540,7 @@
539541 * @param allowBlock boolean
540542 * @return boolean
541543 */
542 - isIPv4Address: function( address, allowBlock ) {
 544+ isIPv4Address: function ( address, allowBlock ) {
543545 if ( typeof address !== 'string' ) {
544546 return false;
545547 }
@@ -557,7 +559,7 @@
558560 * @param allowBlock boolean
559561 * @return boolean
560562 */
561 - isIPv6Address: function( address, allowBlock ) {
 563+ isIPv6Address: function ( address, allowBlock ) {
562564 if ( typeof address !== 'string' ) {
563565 return false;
564566 }

Status & tagging log