mediawiki.Upload.BookletLayout: If the user can't upload, don't show them the form
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 22 Oct 2015 19:25:32 +0000 (21:25 +0200)
committerMarkTraceur <mtraceur@member.fsf.org>
Tue, 15 Dec 2015 16:25:08 +0000 (16:25 +0000)
Second attempt. First, reverted one: I6f68122b5399f4b8766825c752e964478ae7563d.

To improve in the future:
* Use a better error message when not all logged-in users can upload

Bug: T115866
Change-Id: I1ac083fd491c7445240b4fd9f7b3badacb2d2d37

resources/Resources.php
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js

index fce4383..3bce665 100644 (file)
@@ -1186,6 +1186,7 @@ return array(
                ),
                'dependencies' => array(
                        'oojs-ui',
+                       'mediawiki.user',
                        'mediawiki.Upload',
                        'mediawiki.jqueryMsg',
                ),
index 47f4388..60c9991 100644 (file)
         * @return {jQuery.Promise} Promise resolved when everything is initialized
         */
        mw.Upload.BookletLayout.prototype.initialize = function () {
+               var
+                       apiPromise,
+                       booklet = this,
+                       deferred = $.Deferred();
+
                this.clear();
                this.upload = this.createUpload();
                this.setPage( 'upload' );
-               return $.Deferred().resolve().promise();
+
+               apiPromise = this.upload.apiPromise || $.Deferred.resolve( this.upload.api );
+               apiPromise.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 ) {
+                                       // TODO Use a better error message when not all logged-in users can upload
+                                       booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
+                               }
+                       } ).always( function () {
+                               deferred.resolve();
+                       } );
+               } );
+
+               return deferred.promise();
        };
 
        /**