From a074db332cc103319adacabcc52b1f615217e222 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 12 Sep 2015 06:45:00 +0100 Subject: [PATCH] mediawiki.Title: Remove fileExtension option from newFromFileName Follows-up cc8b00ed5b, 55a4946533. Has confusing behaviour and is not used anywhere in Wikimedia Git, nor in on-wiki scripts. Change-Id: Ibc1a821df93fab67856d025cf6671f41efdaebb1 --- resources/src/mediawiki/mediawiki.Title.js | 31 ++------------ .../mediawiki/mediawiki.Title.test.js | 40 +++---------------- 2 files changed, 10 insertions(+), 61 deletions(-) diff --git a/resources/src/mediawiki/mediawiki.Title.js b/resources/src/mediawiki/mediawiki.Title.js index 14297b129a..7f95b1c4d4 100644 --- a/resources/src/mediawiki/mediawiki.Title.js +++ b/resources/src/mediawiki/mediawiki.Title.js @@ -481,7 +481,6 @@ * @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. @@ -503,7 +502,6 @@ // merge options into defaults options = $.extend( { - fileExtension: '', forUploading: true }, options ); @@ -535,7 +533,7 @@ } if ( namespace === NS_MEDIA - || ( ( options.forUploading || options.fileExtension ) && ( namespace === NS_FILE ) ) + || ( options.forUploading && ( namespace === NS_FILE ) ) ) { title = sanitize( title, [ 'generalRule', 'fileRule' ] ); @@ -550,17 +548,6 @@ // 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( '.' ) ); @@ -572,16 +559,8 @@ // 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 { @@ -608,13 +587,11 @@ * @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 } ); }; diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js index af055beb16..641a5a5df3 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js @@ -531,9 +531,6 @@ cases = [ { title: 'DCS0001557854455.JPG', - options: { - fileExtension: 'PNG' - }, expected: 'DCS0001557854455.JPG', description: 'Title in normal namespace without anything invalid but with "file extension"' }, @@ -559,18 +556,12 @@ }, { 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' } ]; @@ -590,15 +581,14 @@ } } ); - 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', @@ -610,8 +600,7 @@ 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', @@ -667,20 +656,6 @@ 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', @@ -699,7 +674,7 @@ 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 + '] '; @@ -707,9 +682,6 @@ 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' ); -- 2.20.1