r97368 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97367‎ | r97368 | r97369 >
Date:04:51, 17 September 2011
Author:neilk
Status:ok
Tags:
Comment:
fix bug 30676 - Foo.jpg.jpg silently fixed to Foo.jpg
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -47,8 +47,7 @@
4848 _this.titleId = "title" + _this.upload.index;
4949 _this.titleInput = $j( '<input type="text" id="' + _this.titleId + '" name="' + _this.titleId + '" class="mwe-title" maxlength="250"/>' )
5050 .keyup( function() {
51 - _this.upload.title.setNameText( _this.titleInput.value );
52 - // TODO update a display of filename
 51+ _this.setCleanTitle( $( _this.titleInput ).val() );
5352 } )
5453 .destinationChecked( {
5554 api: _this.upload.api,
@@ -56,7 +55,8 @@
5756 preprocess: function( name ) {
5857 if ( name !== '' ) {
5958 // turn the contents of the input into a MediaWiki title ("File:foo_bar.jpg") to look up
60 - return _this.upload.title.setNameText( name ).toString();
 59+ // side effect -- also sets this as our current title
 60+ return _this.setCleanTitle( name ).toString();
6161 } else {
6262 return name;
6363 }
@@ -931,7 +931,18 @@
932932 .addClass( 'mwe-upwiz-status-' + statusStr );
933933 },
934934
935 - dateInputCount: 0
 935+ dateInputCount: 0,
936936
 937+ /**
 938+ * Apply some special cleanups for titles before adding to model. These cleanups are not reflected in what the user sees in the title input field.
 939+ * For example, we remove an extension in the title if it matches the extension we're going to add anyway. (bug #30676)
 940+ * @param {String} title in human-readable form, e.g. "Foo bar", rather than "File:Foo_bar.jpg"
 941+ * @return {String} cleaned title with prefix and extension, stringified.
 942+ */
 943+ setCleanTitle: function( s ) {
 944+ var re = new RegExp( '\\.' + this.upload.title.getExtension() + '$', 'i' );
 945+ var cleaned = $j.trim( s.replace( re, '' ) );
 946+ return this.upload.title.setNameText( cleaned ).toString();
 947+ }
937948
938949 };

Status & tagging log