Don't execute upload.loadConfig when it may not exist
authorMatthias Mullie <git@mullie.eu>
Thu, 5 Jan 2017 15:31:06 +0000 (16:31 +0100)
committerMatthias Mullie <git@mullie.eu>
Mon, 9 Jan 2017 07:02:01 +0000 (00:02 -0700)
Upload.BookletLayout creates a mw.Upload object, which has no
loadConfig method.
ForeignStructuredUpload.BookletLayout, which is a child of
Upload.BookletLayout, creates a mw.ForeignStructuredUpload
object, which does have this method.
Thus, that method should be moved to where we know the object
will have it.

Change-Id: Ibb1c0f2b8260a8b0a7cc9f02e3434aed7d163637

resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js

index a5cf1d8..543ece8 100644 (file)
                                                                        e.stopPropagation();
                                                                } );
                                                } );
+                                       }, function ( errorMsg ) {
+                                               booklet.getPage( 'upload' ).$element.msg( errorMsg );
+                                               return $.Deferred().resolve();
                                        } )
                                );
                        }
index c7ebfd8..f736036 100644 (file)
 
                return this.upload.getApi().then(
                        function ( api ) {
-                               return $.when(
-                                       booklet.upload.loadConfig().then(
-                                               null,
-                                               function ( errorMsg ) {
-                                                       booklet.getPage( 'upload' ).$element.msg( errorMsg );
-                                                       return $.Deferred().resolve();
-                                               }
-                                       ),
-                                       // If the user can't upload anything, don't give them the option to.
-                                       api.getUserInfo().then( function ( userInfo ) {
+                               // If the user can't upload anything, don't give them the option to.
+                               return api.getUserInfo().then(
+                                       function ( userInfo ) {
                                                if ( userInfo.rights.indexOf( 'upload' ) === -1 ) {
                                                        if ( mw.user.isAnon() ) {
                                                                booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
                                                        }
                                                }
                                                return $.Deferred().resolve();
-                                       } )
-                               ).then(
-                                       null,
+                                       },
                                        // Always resolve, never reject
                                        function () { return $.Deferred().resolve(); }
                                );