* @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.
// 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
} );
};
cases = [
{
title: 'DCS0001557854455.JPG',
- options: {
- fileExtension: 'PNG'
- },
expected: 'DCS0001557854455.JPG',
description: 'Title in normal namespace without anything invalid but with "file extension"'
},
},
{
title: 'File:Foo.JPEG',
- options: {
- fileExtension: 'jpg'
- },
- expected: 'File:Foo.jpg',
+ expected: 'File:Foo.JPEG',
description: 'Page in File-namespace with non-canonical extension'
},
{
title: 'File:Foo.JPEG ',
- options: {
- fileExtension: 'jpg'
- },
- expected: 'File:Foo.jpg',
+ expected: 'File:Foo.JPEG',
description: 'Page in File-namespace with trailing whitespace'
}
];
}
} );
- QUnit.test( 'newFromFileName', 66, function ( assert ) {
+ QUnit.test( 'newFromFileName', 54, function ( assert ) {
var title, i, thisCase, prefix,
cases = [
{
fileName: 'DCS0001557854455.JPG',
typeOfName: 'Standard camera output',
nameText: 'DCS0001557854455',
- prefixedText: 'File:DCS0001557854455.jpg',
- extensionDesired: 'jpg'
+ prefixedText: 'File:DCS0001557854455.JPG'
},
{
fileName: 'File:Sample.png',
fileName: 'Treppe 2222 Test upload.jpg',
typeOfName: 'File name with spaces in it and lower case file extension',
nameText: 'Treppe 2222 Test upload',
- prefixedText: 'File:Treppe 2222 Test upload.JPG',
- extensionDesired: 'JPG'
+ prefixedText: 'File:Treppe 2222 Test upload.jpg'
},
{
fileName: 'I contain a \ttab.jpg',
nameText: 'Dot. dot',
prefixedText: 'File:Dot. dot. dot'
},
- {
- fileName: 'dot. dot ._dot',
- typeOfName: 'File name with different file extension desired',
- nameText: 'Dot. dot . dot',
- prefixedText: 'File:Dot. dot . dot.png',
- extensionDesired: 'png'
- },
- {
- fileName: 'fileWOExt',
- typeOfName: 'File W/O extension with extension desired',
- nameText: 'FileWOExt',
- prefixedText: 'File:FileWOExt.png',
- extensionDesired: 'png'
- },
{
fileName: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢𠻗𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂𠻹𠻺𠼭𠼮𠽌𠾴𠾼𠿪𡁜𡁯𡁵𡁶𡁻𡃁𡃉𡇙𢃇𢞵𢫕𢭃𢯊𢱑𢱕𢳂.png',
typeOfName: 'File name longer than 240 bytes',
for ( i = 0; i < cases.length; i++ ) {
thisCase = cases[ i ];
- title = mw.Title.newFromFileName( thisCase.fileName, thisCase.extensionDesired );
+ title = mw.Title.newFromFileName( thisCase.fileName );
if ( thisCase.nameText !== undefined ) {
prefix = '[' + thisCase.typeOfName + '] ';
assert.notStrictEqual( title, null, prefix + 'Parses successfully' );
assert.equal( title.getNameText(), thisCase.nameText, prefix + 'Filename matches original' );
assert.equal( title.getPrefixedText(), thisCase.prefixedText, prefix + 'File page title matches original' );
- if ( thisCase.extensionDesired !== undefined ) {
- assert.equal( title.getExtension(), thisCase.extensionDesired, prefix + 'Extension matches desired' );
- }
assert.equal( title.getNamespaceId(), 6, prefix + 'Namespace ID matches File namespace' );
} else {
assert.strictEqual( title, null, thisCase.typeOfName + ', should not produce an mw.Title object' );