*
* @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
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' );
}