var
mwString = require( 'mediawiki.String' ),
+ toUpperMapping = require( './phpCharToUpper.json' ),
+
namespaceIds = mw.config.get( 'wgNamespaceIds' ),
/**
*
* @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 && $.type( defaultNamespace ) === 'object' ) {
- options = defaultNamespace;
- defaultNamespace = undefined;
+ if ( arguments.length < 3 && typeof defaultNamespace === 'object' ) {
+ options = defaultNamespaceOrOptions;
+ } else {
+ defaultNamespace = defaultNamespaceOrOptions;
}
// merge options into defaults
* @return {boolean} Namespace is a signature namespace
*/
Title.wantSignaturesNamespace = function ( namespaceId ) {
- return this.isTalkNamespace( namespaceId ) ||
+ return Title.isTalkNamespace( namespaceId ) ||
mw.config.get( 'wgExtraSignatureNamespaces' ).indexOf( namespaceId ) !== -1;
};
}
};
+ /**
+ * PHP's strtoupper differs from String.toUpperCase in a number of cases (T147646).
+ *
+ * @param {string} chr Unicode character
+ * @return {string} Unicode character, in upper case, according to the same rules as in PHP
+ */
+ Title.phpCharToUpper = function ( chr ) {
+ var mapped = toUpperMapping[ chr ];
+ return mapped || chr.toUpperCase();
+ };
+
/* Public members */
Title.prototype = {
) {
return this.title;
}
- // PHP's strtoupper differs from String.toUpperCase in a number of cases
- // Bug: T147646
return mw.Title.phpCharToUpper( this.title[ 0 ] ) + this.title.slice( 1 );
},