* @param {number} [defaultNamespace=NS_MAIN]
* If given, will used as default namespace for the given title.
* @param {Object} [options] additional options
- * @param {string} [options.fileExtension='']
- * If the title is about to be created for the Media or File namespace,
- * ensures the resulting Title has the correct extension. Useful, for example
- * on systems that predict the type by content-sniffing, not by file extension.
- * If different from empty string, `forUploading` is assumed.
* @param {boolean} [options.forUploading=true]
* Makes sure that a file is uploadable under the title returned.
* There are pages in the file namespace under which file upload is impossible.
// merge options into defaults
options = $.extend( {
- fileExtension: '',
forUploading: true
}, options );
}
if ( namespace === NS_MEDIA
- || ( ( options.forUploading || options.fileExtension ) && ( namespace === NS_FILE ) )
+ || ( options.forUploading && ( namespace === NS_FILE ) )
) {
title = sanitize( title, [ 'generalRule', 'fileRule' ] );
// Get the last part, which is supposed to be the file extension
ext = parts.pop();
- if ( options.fileExtension ) {
- // Does the supplied file name carry the desired file extension?
- if ( Title.normalizeExtension( ext ) !== Title.normalizeExtension( options.fileExtension ) ) {
- // No, push back, whatever there was after the dot
- parts.push( ext );
- }
-
- // Always canonicalize to the desired file extension (e.g. 'jpeg' to 'jpg')
- ext = options.fileExtension;
- }
-
// Remove whitespace of the name part (that W/O extension)
title = $.trim( parts.join( '.' ) );
// Missing file extension
title = $.trim( parts.join( '.' ) );
- if ( options.fileExtension ) {
-
- // Cut, if too long and append the desired file extension
- title = trimFileNameToByteLength( title, options.fileExtension );
-
- } else {
-
- // Name has no file extension and a fallback wasn't provided either
- return null;
- }
+ // Name has no file extension and a fallback wasn't provided either
+ return null;
}
} else {
* @static
* @param {string} uncleanName The unclean file name including file extension but
* without namespace
- * @param {string} [fileExtension] the desired file extension
* @return {mw.Title|null} A valid Title object or null if the title is invalid
*/
- Title.newFromFileName = function ( uncleanName, fileExtension ) {
+ Title.newFromFileName = function ( uncleanName ) {
return Title.newFromUserInput( 'File:' + uncleanName, {
- fileExtension: fileExtension,
forUploading: true
} );
};