X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.ForeignStructuredUpload.BookletLayout.js;h=844d74cc393024197bf7f23f152843314e414cb3;hb=53779578b44575ef91feb3fad488f09b52f737d7;hp=0f61d975f1dd3ab9f719a5475e20179bc5bfaede;hpb=62f6c629bea49405a53fcd56e4c314d74650bcdb;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js index 0f61d975f1..844d74cc39 100644 --- a/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js @@ -309,6 +309,50 @@ } ); }; + /** + * @param {mw.Title} filename + * @return {jQuery.Promise} Resolves (on success) or rejects with OO.ui.Error + */ + mw.ForeignStructuredUpload.BookletLayout.prototype.validateFilename = function ( filename ) { + return ( new mw.Api() ).get( { + action: 'query', + prop: 'info', + titles: filename.getPrefixedDb(), + formatversion: 2 + } ).then( + function ( result ) { + // if the file already exists, reject right away, before + // ever firing finishStashUpload() + if ( !result.query.pages[ 0 ].missing ) { + return $.Deferred().reject( new OO.ui.Error( + $( '

' ).msg( 'fileexists', filename.getPrefixedDb() ), + { recoverable: false } + ) ); + } + }, + function () { + // API call failed - this could be a connection hiccup... + // Let's just ignore this validation step and turn this + // failure into a successful resolve ;) + return $.Deferred().resolve(); + } + ); + }; + + /** + * @inheritdoc + */ + mw.ForeignStructuredUpload.BookletLayout.prototype.saveFile = function () { + var title = mw.Title.newFromText( + this.getFilename(), + mw.config.get( 'wgNamespaceIds' ).file + ); + + return this.uploadPromise + .then( this.validateFilename.bind( this, title ) ) + .then( mw.ForeignStructuredUpload.BookletLayout.parent.prototype.saveFile.bind( this ) ); + }; + /* Getters */ /**