mw.Title.newFromUserInput: Rename vars, improve docs for double signature
authorEd Sanders <esanders@wikimedia.org>
Wed, 12 Dec 2018 13:20:25 +0000 (13:20 +0000)
committerJforrester <jforrester@wikimedia.org>
Wed, 12 Dec 2018 17:38:03 +0000 (17:38 +0000)
Also add tests to cover this usage.

Change-Id: I61c7e7377ac7d75073dac025f5f7ff4e599756cb

resources/src/mediawiki.Title/Title.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js

index def9f68..ff7a40f 100644 (file)
         *
         * @static
         * @param {string} title
-        * @param {number} [defaultNamespace=NS_MAIN]
+        * @param {number|Object} [defaultNamespaceOrOptions=NS_MAIN]
         *  If given, will used as default namespace for the given title.
+        *  This method can also be called with two arguments, in which case
+        *  this becomes options (see below).
         * @param {Object} [options] additional options
         * @param {boolean} [options.forUploading=true]
         *  Makes sure that a file is uploadable under the title returned.
         *  Automatically assumed if the title is created in the Media namespace.
         * @return {mw.Title|null} A valid Title object or null if the input cannot be turned into a valid title
         */
-       Title.newFromUserInput = function ( title, defaultNamespace, options ) {
-               var namespace, m, id, ext, parts;
+       Title.newFromUserInput = function ( title, defaultNamespaceOrOptions, options ) {
+               var namespace, m, id, ext, parts,
+                       defaultNamespace;
 
                // defaultNamespace is optional; check whether options moves up
                if ( arguments.length < 3 && typeof defaultNamespace === 'object' ) {
-                       options = defaultNamespace;
-                       defaultNamespace = undefined;
+                       options = defaultNamespaceOrOptions;
+               } else {
+                       defaultNamespace = defaultNamespaceOrOptions;
                }
 
                // merge options into defaults
index 4a32157..84e1d4e 100644 (file)
 
                                assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
                                assert.strictEqual( title.toText(), thisCase.expected, prefix + 'Title as expected' );
+                               if ( thisCase.defaultNamespace === undefined ) {
+                                       title = mw.Title.newFromUserInput( thisCase.title, thisCase.options );
+                                       assert.strictEqual( title.toText(), thisCase.expected, prefix + 'Skipping namespace argument' );
+                               }
                        } else {
                                assert.strictEqual( title, null, thisCase.description + ', should not produce an mw.Title object' );
                        }