mw.Upload: Add details of error when uploading to stash
authorPrateek Saxena <prtksxna@gmail.com>
Thu, 1 Oct 2015 08:42:00 +0000 (14:12 +0530)
committerPrateek Saxena <prtksxna@gmail.com>
Fri, 2 Oct 2015 11:44:07 +0000 (17:14 +0530)
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
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
resources/src/mediawiki/mediawiki.Upload.js

index 65dcfe4..ccc3cd5 100644 (file)
@@ -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',
index 42312dd..d1e01b1 100644 (file)
                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;
index aafc37a..56f4f83 100644 (file)
@@ -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;
        }
                );
        };
 
+       /**
+        * 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.
         *
                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
                        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,
                        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 );
                } );
        };
 
                        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;
                }
 
                return this.stashPromise.then( function ( finishStash ) {
-                       upload.state = Upload.State.UPLOADING;
+                       upload.setState( Upload.State.UPLOADING );
 
                        return finishStash( {
                                watchlist: ( upload.getWatchlist() ) ? 1 : undefined,
                                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 );
                        } );
                } );
        };