From 09bcd258386d707c6131e3300df600f17c48c3b5 Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Thu, 1 Oct 2015 14:12:00 +0530 Subject: [PATCH] mw.Upload: Add details of error when uploading to stash Add a new method 'getStateDetails' to mw.Upload. The Upload.Booklet layout uses this in the error message. Bug: T114130 Change-Id: I932af41a7ae561774097c91f857d1daa39d8c49f --- resources/Resources.php | 48 +++++++++++++++++++ .../mediawiki.Upload.BookletLayout.js | 10 ++-- resources/src/mediawiki/mediawiki.Upload.js | 39 ++++++++++----- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 65dcfe4c14..ccc3cd5971 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1135,6 +1135,54 @@ return array( 'dom-level2-shim', 'mediawiki.api.upload', ), + 'messages' => array( + 'api-error-badaccess-groups', + 'api-error-badtoken', + 'api-error-copyuploaddisabled', + 'api-error-duplicate', + 'api-error-duplicate-archive', + 'api-error-empty-file', + 'api-error-emptypage', + 'api-error-fetchfileerror', + 'api-error-fileexists-forbidden', + 'api-error-fileexists-shared-forbidden', + 'api-error-file-too-large', + 'api-error-filename-tooshort', + 'api-error-filetype-banned', + 'api-error-filetype-banned-type', + 'api-error-filetype-missing', + 'api-error-hookaborted', + 'api-error-http', + 'api-error-illegal-filename', + 'api-error-internal-error', + 'api-error-invalid-file-key', + 'api-error-missingparam', + 'api-error-missingresult', + 'api-error-mustbeloggedin', + 'api-error-mustbeposted', + 'api-error-noimageinfo', + 'api-error-nomodule', + 'api-error-ok-but-empty', + 'api-error-overwrite', + 'api-error-stashfailed', + 'api-error-publishfailed', + 'api-error-stasherror', + 'api-error-stashedfilenotfound', + 'api-error-stashpathinvalid', + 'api-error-stashfilestorage', + 'api-error-stashzerolength', + 'api-error-stashnotloggedin', + 'api-error-stashwrongowner', + 'api-error-stashnosuchfilekey', + 'api-error-timeout', + 'api-error-unclassified', + 'api-error-unknown-code', + 'api-error-unknown-error', + 'api-error-unknown-warning', + 'api-error-unknownerror', + 'api-error-uploaddisabled', + 'api-error-verification-error', + ), ), 'mediawiki.ForeignUpload' => array( 'scripts' => 'resources/src/mediawiki/mediawiki.ForeignUpload.js', diff --git a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js index 42312dd6c8..d1e01b1908 100644 --- a/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js +++ b/resources/src/mediawiki/mediawiki.Upload.BookletLayout.js @@ -190,18 +190,16 @@ this.uploadPromise.then( function () { deferred.resolve(); layout.emit( 'fileUploaded' ); - } ); - - // These errors will be thrown while the user is on the info page - this.uploadPromise.always( function () { + }, function () { + // These errors will be thrown while the user is on the info page if ( layout.upload.getState() === mw.Upload.State.ERROR ) { - deferred.reject( new OO.ui.Error( mw.msg( 'upload-process-error' ), { + deferred.reject( new OO.ui.Error( layout.upload.getStateDetails(), { recoverable: false } ) ); return false; } if ( layout.upload.getState() === mw.Upload.State.WARNING ) { - deferred.reject( new OO.ui.Error( mw.msg( 'upload-process-error' ), { + deferred.reject( new OO.ui.Error( layout.upload.getStateDetails(), { recoverable: false } ) ); return false; diff --git a/resources/src/mediawiki/mediawiki.Upload.js b/resources/src/mediawiki/mediawiki.Upload.js index aafc37a2e0..56f4f830d6 100644 --- a/resources/src/mediawiki/mediawiki.Upload.js +++ b/resources/src/mediawiki/mediawiki.Upload.js @@ -55,7 +55,7 @@ this.comment = ''; this.filename = null; this.file = null; - this.state = Upload.State.NEW; + this.setState( Upload.State.NEW ); this.imageinfo = undefined; } @@ -187,6 +187,14 @@ ); }; + /** + * Sets the state and state details (if any) of the upload. + */ + UP.setState = function ( state, stateDetails ) { + this.state = state; + this.stateDetails = stateDetails; + }; + /** * Gets the state of the upload. * @@ -196,6 +204,15 @@ return this.state; }; + /** + * Gets details of the current state. + * + * @return {string} + */ + UP.getStateDetails = function () { + return this.stateDetails; + }; + /** * Get the imageinfo object for the finished upload. * Only available once the upload is finished! Don't try to get it @@ -223,7 +240,7 @@ return $.Deferred().reject( 'No filename set. Call setFilename to add one.' ); } - this.state = Upload.State.UPLOADING; + this.setState( Upload.State.UPLOADING ); return this.api.upload( this.getFile(), { watchlist: ( this.getWatchlist() ) ? 1 : undefined, @@ -231,11 +248,11 @@ filename: this.getFilename(), text: this.getText() } ).then( function ( result ) { - upload.state = Upload.State.UPLOADED; + upload.setState( Upload.State.UPLOADED ); upload.imageinfo = result.upload.imageinfo; return result; }, function () { - upload.state = Upload.State.ERROR; + upload.setState( Upload.State.ERROR ); } ); }; @@ -255,15 +272,15 @@ this.setFilenameFromFile(); } - this.state = Upload.State.UPLOADING; + this.setState( Upload.State.UPLOADING ); this.stashPromise = this.api.uploadToStash( this.getFile(), { filename: this.getFilename() } ).then( function ( finishStash ) { - upload.state = Upload.State.STASHED; + upload.setState( Upload.State.STASHED ); return finishStash; - }, function () { - upload.state = Upload.State.ERROR; + }, function ( result ) { + upload.setState( Upload.State.ERROR, mw.message( 'api-error-' + result ) ); } ); return this.stashPromise; @@ -282,7 +299,7 @@ } return this.stashPromise.then( function ( finishStash ) { - upload.state = Upload.State.UPLOADING; + upload.setState( Upload.State.UPLOADING ); return finishStash( { watchlist: ( upload.getWatchlist() ) ? 1 : undefined, @@ -290,11 +307,11 @@ filename: upload.getFilename(), text: upload.getText() } ).then( function ( result ) { - upload.state = Upload.State.UPLOADED; + upload.setState( Upload.State.UPLOADED ); upload.imageinfo = result.upload.imageinfo; return result; }, function () { - upload.state = Upload.State.ERROR; + upload.setState( Upload.State.ERROR ); } ); } ); }; -- 2.20.1