Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -266,7 +266,8 @@ |
267 | 267 | 'mwe-upwiz-thanks-caption', |
268 | 268 | 'mwe-upwiz-help-popup', |
269 | 269 | 'mwe-upwiz-help-popup-title', |
270 | | - 'mwe-upwiz-thumbnail-failed' |
| 270 | + 'mwe-upwiz-thumbnail-failed', |
| 271 | + 'mwe-upwiz-unparseable-filename' |
271 | 272 | ), |
272 | 273 | 'group' => 'ext.uploadWizard' |
273 | 274 | ), |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -211,8 +211,8 @@ |
212 | 212 | 'mwe-upwiz-thanks-caption' => 'Add caption here', |
213 | 213 | 'mwe-upwiz-help-popup' => 'Help', |
214 | 214 | 'mwe-upwiz-help-popup-title' => 'Title', |
215 | | - 'mwe-upwiz-thumbnail-failed' => 'The upload succeeded, but the server could not get a preview thumbnail' |
216 | | - |
| 215 | + 'mwe-upwiz-thumbnail-failed' => 'The upload succeeded, but the server could not get a preview thumbnail', |
| 216 | + 'mwe-upwiz-unparseable-filename' => 'Could not understand the file name "$1"' |
217 | 217 | |
218 | 218 | ); |
219 | 219 | |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardUploadInterface.js |
— | — | @@ -290,7 +290,22 @@ |
291 | 291 | // visible filename |
292 | 292 | $j( _this.form ).find( '.mwe-upwiz-visible-file-filename-text' ).html( path ); |
293 | 293 | |
294 | | - _this.upload.title = new mw.Title( mw.UploadWizardUtil.getBasename( path ), 'file' ); |
| 294 | + var filename = mw.UploadWizardUtil.getBasename( path ); |
| 295 | + try { |
| 296 | + _this.upload.title = new mw.Title( filename, 'file' ); |
| 297 | + } catch ( e ) { |
| 298 | + $( '<div>' ) |
| 299 | + .msg( 'mwe-upwiz-unparseable-filename', filename ) |
| 300 | + .dialog({ |
| 301 | + width: 500, |
| 302 | + zIndex: 200000, |
| 303 | + autoOpen: true, |
| 304 | + modal: true |
| 305 | + }); |
| 306 | + _this.$fileInputCtrl.val(); |
| 307 | + return; |
| 308 | + } |
| 309 | + |
295 | 310 | $j( _this.filenameCtrl ).val( _this.upload.title.getMain() ); |
296 | 311 | |
297 | 312 | if ( ! _this.isFilled ) { |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -97,12 +97,24 @@ |
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
| 101 | + // default error state |
| 102 | + var code = 'unknown'; |
| 103 | + var info = 'unknown'; |
| 104 | + |
101 | 105 | if ( result.upload && result.upload.warnings && result.upload.warnings.exists ) { |
102 | | - var fileTitle = new mw.Title( result.upload.warnings.exists, 'file' ).toString(); |
103 | | - var fileUri = new mw.Uri( document.URL ); |
104 | | - fileUri.path = wgScript; |
105 | | - fileUri.query = { title: fileTitle, action: 'view' }; |
106 | | - _this.setError( 'duplicate', fileUri.toString() ); |
| 106 | + var duplicateName = result.upload.warnings.exists; |
| 107 | + try { |
| 108 | + var fileTitle = new mw.Title( duplicateName, 'file' ).toString(); |
| 109 | + var fileUri = new mw.Uri( document.URL ); |
| 110 | + fileUri.path = wgScript; |
| 111 | + fileUri.query = { title: fileTitle, action: 'view' }; |
| 112 | + code = 'duplicate'; |
| 113 | + info = fileUri.toString(); |
| 114 | + } catch ( e ) { |
| 115 | + code = 'unknown'; |
| 116 | + info = 'Warned about duplicate but filename is unparseable: "' + duplicateName + "'"; |
| 117 | + } |
| 118 | + _this.setError( code, info ); |
107 | 119 | } else if ( result.upload && result.upload.result === 'Success' ) { |
108 | 120 | if ( result.upload.imageinfo ) { |
109 | 121 | // success |
— | — | @@ -127,8 +139,6 @@ |
128 | 140 | _this.setError( 'noimageinfo' ); |
129 | 141 | } |
130 | 142 | } else { |
131 | | - var code = 'unknown'; |
132 | | - var info = 'unknown'; |
133 | 143 | if ( result.error ) { |
134 | 144 | if ( result.error.code ) { |
135 | 145 | code = result.error.code; |
— | — | @@ -147,11 +157,16 @@ |
148 | 158 | * Called when the file is entered into the file input |
149 | 159 | * Get as much data as possible -- maybe exif, even thumbnail maybe |
150 | 160 | */ |
151 | | - extractLocalFileInfo: function( localFilename ) { |
| 161 | + extractLocalFileInfo: function( filename ) { |
152 | 162 | if ( false ) { // FileAPI, one day |
153 | 163 | this.transportWeight = getFileSize(); |
154 | 164 | } |
155 | | - this.title = new mw.Title( mw.UploadWizardUtil.getBasename( localFilename ), 'file' ); |
| 165 | + // XXX sanitize filename |
| 166 | + try { |
| 167 | + this.title = new mw.Title( mw.UploadWizardUtil.getBasename( filename ).replace( /:/g, '_' ), 'file' ); |
| 168 | + } catch ( e ) { |
| 169 | + this.setError( 'mwe-upwiz-unparseable-filename', filename ); |
| 170 | + } |
156 | 171 | }, |
157 | 172 | |
158 | 173 | /** |
— | — | @@ -188,6 +203,7 @@ |
189 | 204 | } |
190 | 205 | |
191 | 206 | if ( _this.title.getExtension() === null ) { |
| 207 | + 1; |
192 | 208 | // TODO v1.1 what if we don't have an extension? Should be impossible as it is currently impossible to upload without extension, but you |
193 | 209 | // never know... theoretically there is no restriction on extensions if we are uploading to the stash, but the check is performed anyway. |
194 | 210 | /* |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js |
— | — | @@ -316,7 +316,14 @@ |
317 | 317 | $j( _this.titleInput ).data( 'valid', false ); |
318 | 318 | |
319 | 319 | // result is NOT unique |
320 | | - var title = new mw.Title( result.title ).setNamespace( 'file' ).getNameText(); |
| 320 | + var title; |
| 321 | + try { |
| 322 | + title = new mw.Title( result.title ).setNamespace( 'file' ).getNameText(); |
| 323 | + } catch ( e ) { |
| 324 | + // unparseable result from unique test? |
| 325 | + title = '[unparseable name]'; |
| 326 | + } |
| 327 | + |
321 | 328 | /* var img = result.img; |
322 | 329 | var href = result.href; */ |
323 | 330 | |