[mw.util] bug fix and minor clean up
authorKrinkle <krinkle@users.mediawiki.org>
Thu, 23 Feb 2012 00:39:15 +0000 (00:39 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Thu, 23 Feb 2012 00:39:15 +0000 (00:39 +0000)
* Fixes bug 34603 (Patch by Rainer <Rainer@Rillke.eu>) and other instances of the same bug
-- Use 'util' instead of 'this' to allow re-usage of the method in a different context
* Use ternary operator instead of the default operator in mw.util.wikiGetlink to check it for type instead of thruthy-ness (so that falsy-values such as '' work, and thruthy non-string values such as objects fail).

resources/mediawiki/mediawiki.util.js

index 4350737..277b194 100644 (file)
@@ -2,7 +2,7 @@
  * Implements mediaWiki.util library
  */
 ( function ( $, mw ) {
-"use strict";
+       "use strict";
 
        // Local cache and alias
        var util = {
                 * @param str string String to be encoded
                 */
                wikiUrlencode: function ( str ) {
-                       return this.rawurlencode( str )
+                       return util.rawurlencode( str )
                                .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
                },
 
                /**
                 * Get the link to a page name (relative to wgServer)
                 *
-                * @param str string Page name to get the link for.
-                * @return string Location for a page with name of 'str' or boolean false on error.
+                * @param str String: Page name to get the link for.
+                * @return String: Location for a page with name of 'str' or boolean false on error.
                 */
                wikiGetlink: function ( str ) {
                        return mw.config.get( 'wgArticlePath' ).replace( '$1',
-                               this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) );
+                               util.wikiUrlencode( typeof str === 'string' ? str : mw.config.get( 'wgPageName' ) ) );
                },
 
                /**
                                        $link.attr( 'title', tooltip );
                                }
                                if ( accesskey && tooltip ) {
-                                       this.updateTooltipAccessKeys( $link );
+                                       util.updateTooltipAccessKeys( $link );
                                }
 
                                // Where to put our node ?