X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28%27votes%27%2C%20votes=%27waiting%27%29%20%7D%7D?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.Upload.BookletLayout.js;h=4038228cd7e87d899e56c2668eee43bf310dcf50;hb=3301e78e5a2e5662952c0564f830a492743f9844;hp=60c99918e555c25173cac0df7825e170f0f7e753;hpb=a8247aba334928ac125c641cef6cdf5bb4f3ca4a;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js index 60c99918e5..4038228cd7 100644 --- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js @@ -52,7 +52,7 @@ * {@link #createUpload createUpload} method to * return the new model. The {@link #saveFile saveFile}, and * the {@link #uploadFile uploadFile} methods need to be - * overriden to use the new model and data returned from the forms. + * overridden to use the new model and data returned from the forms. * * @class * @extends OO.ui.BookletLayout @@ -152,7 +152,6 @@ */ mw.Upload.BookletLayout.prototype.initialize = function () { var - apiPromise, booklet = this, deferred = $.Deferred(); @@ -160,8 +159,7 @@ this.upload = this.createUpload(); this.setPage( 'upload' ); - apiPromise = this.upload.apiPromise || $.Deferred.resolve( this.upload.api ); - apiPromise.done( function ( api ) { + this.upload.getApi().done( function ( api ) { // If the user can't upload anything, don't give them the option to. api.getUserInfo().done( function ( userInfo ) { if ( userInfo.rights.indexOf( 'upload' ) === -1 ) { @@ -171,6 +169,9 @@ } ).always( function () { deferred.resolve(); } ); + } ).fail( function ( errorMsg ) { + booklet.getPage( 'upload' ).$element.msg( errorMsg ); + deferred.resolve(); } ); return deferred.promise(); @@ -202,7 +203,8 @@ layout = this, file = this.getFile(); - this.filenameWidget.setValue( file.name ); + this.setFilename( file.name ); + this.setPage( 'info' ); if ( this.shouldRecordBucket ) { @@ -210,8 +212,8 @@ } this.upload.setFile( file ); - // Explicitly set the filename so that the old filename isn't used in case of retry - this.upload.setFilenameFromFile(); + // The original file name might contain invalid characters, so use our sanitized one + this.upload.setFilename( this.getFilename() ); this.uploadPromise = this.upload.uploadToStash(); this.uploadPromise.then( function () { @@ -286,15 +288,21 @@ warnings = stateDetails.upload && stateDetails.upload.warnings; if ( state === mw.Upload.State.ERROR ) { + if ( !error ) { + // If there's an 'exception' key, this might be a timeout, or other connection problem + return new OO.ui.Error( + $( '

' ).msg( 'api-error-unknownerror', JSON.stringify( stateDetails ) ), + { recoverable: false } + ); + } + // HACK We should either have a hook here to allow TitleBlacklist to handle this, or just have // TitleBlacklist produce sane error messages that can be displayed without arcane knowledge if ( error.info === 'TitleBlacklist prevents this title from being created' ) { // HACK Apparently the only reliable way to determine whether TitleBlacklist was involved return new OO.ui.Error( - $( '

' ).html( - // HACK TitleBlacklist doesn't have a sensible message, this one is from UploadWizard - mw.message( 'api-error-blacklisted' ).parse() - ), + // HACK TitleBlacklist doesn't have a sensible message, this one is from UploadWizard + $( '

' ).msg( 'api-error-blacklisted' ), { recoverable: false } ); } @@ -304,9 +312,7 @@ message = mw.message( 'api-error-unknownerror', JSON.stringify( stateDetails ) ); } return new OO.ui.Error( - $( '

' ).html( - message.parse() - ), + $( '

' ).append( message.parseDom() ), { recoverable: false } ); } @@ -353,16 +359,14 @@ } else if ( warnings.badfilename !== undefined ) { // Change the name if the current name isn't acceptable // TODO This might not really be the best place to do this - this.filenameWidget.setValue( warnings.badfilename ); + this.setFilename( warnings.badfilename ); return new OO.ui.Error( $( '

' ).msg( 'badfilename', warnings.badfilename ) ); } else { return new OO.ui.Error( - $( '

' ).html( - // Let's get all the help we can if we can't pin point the error - mw.message( 'api-error-unknown-warning', JSON.stringify( stateDetails ) ).parse() - ), + // Let's get all the help we can if we can't pin point the error + $( '

' ).msg( 'api-error-unknown-warning', JSON.stringify( stateDetails ) ), { recoverable: false } ); } @@ -422,7 +426,7 @@ this.descriptionWidget = new OO.ui.TextInputWidget( { indicator: 'required', required: true, - validate: /.+/, + validate: /\S+/, multiline: true, autosize: true } ); @@ -433,11 +437,13 @@ fieldset.addItems( [ new OO.ui.FieldLayout( this.filenameWidget, { label: mw.msg( 'upload-form-label-infoform-name' ), - align: 'top' + align: 'top', + help: mw.msg( 'upload-form-label-infoform-name-tooltip' ) } ), new OO.ui.FieldLayout( this.descriptionWidget, { label: mw.msg( 'upload-form-label-infoform-description' ), - align: 'top' + align: 'top', + help: mw.msg( 'upload-form-label-infoform-description-tooltip' ) } ) ] ); this.infoForm = new OO.ui.FormLayout( { items: [ fieldset ] } ); @@ -512,7 +518,30 @@ * @return {string} */ mw.Upload.BookletLayout.prototype.getFilename = function () { - return this.filenameWidget.getValue(); + var filename = this.filenameWidget.getValue(); + if ( this.filenameExtension ) { + filename += '.' + this.filenameExtension; + } + return filename; + }; + + /** + * Prefills the {@link #infoForm information form} with the given filename. + * + * @protected + * @param {string} filename + */ + mw.Upload.BookletLayout.prototype.setFilename = function ( filename ) { + var title = mw.Title.newFromFileName( filename ); + + if ( title ) { + this.filenameWidget.setValue( title.getNameText() ); + this.filenameExtension = mw.Title.normalizeExtension( title.getExtension() ); + } else { + // Seems to happen for files with no extension, which should fail some checks anyway... + this.filenameWidget.setValue( filename ); + this.filenameExtension = null; + } }; /**