mw.Title/NamespaceInputWidget: Use wgNamespaceIds for namespace constants
authorEd Sanders <esanders@wikimedia.org>
Thu, 18 Feb 2016 11:32:11 +0000 (11:32 +0000)
committerEd Sanders <esanders@wikimedia.org>
Mon, 22 Feb 2016 10:37:01 +0000 (10:37 +0000)
Avoids duplication of numerical constants.

Fix instance of variable changing meaning (ns = ns.toLowerString()).

Change-Id: I0e21c51d0e1bdf8340d5d7c927cee7619171e14b

resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
resources/src/mediawiki/mediawiki.Title.js

index 4f1b874..c88395e 100644 (file)
        mw.widgets.NamespaceInputWidget.prototype.getNamespaceDropdownOptions = function ( config ) {
                var options,
                        exclude = config.exclude || [],
-                       NS_MAIN = 0;
+                       mainNamespace = mw.config.get( 'wgNamespaceIds' )[ '' ];
 
                options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
-                       if ( ns < NS_MAIN || exclude.indexOf( Number( ns ) ) !== -1 ) {
+                       if ( ns < mainNamespace || exclude.indexOf( Number( ns ) ) !== -1 ) {
                                return null; // skip
                        }
                        ns = String( ns );
-                       if ( ns === String( NS_MAIN ) ) {
+                       if ( ns === String( mainNamespace ) ) {
                                name = mw.message( 'blanknamespace' ).text();
                        }
                        return { data: ns, label: name };
index ffb3041..c438d05 100644 (file)
 
        var
 
+       namespaceIds = mw.config.get( 'wgNamespaceIds' ),
+
        /**
         * @private
         * @static
         * @property NS_MAIN
         */
-       NS_MAIN = 0,
+       NS_MAIN = namespaceIds[ '' ],
 
        /**
         * @private
         * @static
         * @property NS_TALK
         */
-       NS_TALK = 1,
+       NS_TALK = namespaceIds.talk,
 
        /**
         * @private
         * @static
         * @property NS_SPECIAL
         */
-       NS_SPECIAL = -1,
+       NS_SPECIAL = namespaceIds.special,
 
        /**
         * @private
         * @static
         * @property NS_MEDIA
         */
-       NS_MEDIA = -2,
+       NS_MEDIA = namespaceIds.media,
 
        /**
         * @private
         * @static
         * @property NS_FILE
         */
-       NS_FILE = 6,
+       NS_FILE = namespaceIds.file,
 
        /**
         * @private
                if ( typeof ns !== 'string' ) {
                        return false;
                }
-               ns = ns.toLowerCase();
-               id = mw.config.get( 'wgNamespaceIds' )[ ns ];
+               // TODO: Should just use local var namespaceIds here but it
+               // breaks test which modify the config
+               id = mw.config.get( 'wgNamespaceIds' )[ ns.toLowerCase() ];
                if ( id === undefined ) {
                        return false;
                }