Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js |
— | — | @@ -47,8 +47,7 @@ |
48 | 48 | _this.titleId = "title" + _this.upload.index; |
49 | 49 | _this.titleInput = $j( '<input type="text" id="' + _this.titleId + '" name="' + _this.titleId + '" class="mwe-title" maxlength="250"/>' ) |
50 | 50 | .keyup( function() { |
51 | | - _this.upload.title.setNameText( _this.titleInput.value ); |
52 | | - // TODO update a display of filename |
| 51 | + _this.setCleanTitle( $( _this.titleInput ).val() ); |
53 | 52 | } ) |
54 | 53 | .destinationChecked( { |
55 | 54 | api: _this.upload.api, |
— | — | @@ -56,7 +55,8 @@ |
57 | 56 | preprocess: function( name ) { |
58 | 57 | if ( name !== '' ) { |
59 | 58 | // 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(); |
61 | 61 | } else { |
62 | 62 | return name; |
63 | 63 | } |
— | — | @@ -931,7 +931,18 @@ |
932 | 932 | .addClass( 'mwe-upwiz-status-' + statusStr ); |
933 | 933 | }, |
934 | 934 | |
935 | | - dateInputCount: 0 |
| 935 | + dateInputCount: 0, |
936 | 936 | |
| 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 | + } |
937 | 948 | |
938 | 949 | }; |