diff --git a/modules/CommentController.js b/modules/CommentController.js index f1511a9aa..f72d922a3 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -109,15 +109,18 @@ CommentController.static.initType = 'page'; /** * Create and setup the reply widget * - * @param {string} [mode] Optionally force a mode, 'visual' or 'source' - * @param {boolean} [hideErrors] Suppress errors, e.g. when restoring auto-save - * @param {boolean} [suppressNotifications] Don't notify the user if recovering auto-save + * @param {Object} [options] + * @param {string} [options.mode] Optionally force a mode, 'visual' or 'source' + * @param {boolean} [options.hideErrors] Suppress errors, e.g. when restoring auto-save + * @param {boolean} [options.suppressNotifications] Don't notify the user if recovering auto-save */ -CommentController.prototype.setup = function ( mode, hideErrors, suppressNotifications ) { +CommentController.prototype.setup = function ( options ) { const threadItem = this.getThreadItem(); - if ( mode === undefined ) { - mode = mw.user.options.get( 'discussiontools-editmode' ) || + options = options || {}; + + if ( options.mode === undefined ) { + options.mode = mw.user.options.get( 'discussiontools-editmode' ) || ( defaultVisual ? 'visual' : 'source' ); } @@ -127,17 +130,17 @@ CommentController.prototype.setup = function ( mode, hideErrors, suppressNotific mechanism: 'click', integration: 'discussiontools', // eslint-disable-next-line camelcase - editor_interface: mode === 'visual' ? 'visualeditor' : + editor_interface: options.mode === 'visual' ? 'visualeditor' : ( enable2017Wikitext ? 'wikitext-2017' : 'wikitext' ) } ); if ( !this.replyWidgetPromise ) { this.replyWidgetPromise = this.getTranscludedFromSource().then( - ( commentDetails ) => this.createReplyWidget( commentDetails, { mode: mode } ), + ( commentDetails ) => this.createReplyWidget( commentDetails, { mode: options.mode } ), ( code, data ) => { this.onReplyWidgetTeardown(); - if ( !hideErrors ) { + if ( !options.hideErrors ) { OO.ui.alert( code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data ), { size: 'medium' } @@ -205,7 +208,7 @@ CommentController.prototype.setup = function ( mode, hideErrors, suppressNotific } $( this.newListItem ).empty().append( replyWidget.$element ); - this.setupReplyWidget( replyWidget, {}, suppressNotifications ); + this.setupReplyWidget( replyWidget, {}, options.suppressNotifications ); this.showAndFocus(); diff --git a/modules/NewTopicController.js b/modules/NewTopicController.js index e8d502a84..bb3d2e5a8 100644 --- a/modules/NewTopicController.js +++ b/modules/NewTopicController.js @@ -67,7 +67,7 @@ NewTopicController.static.suppressedEditNotices = [ /** * @inheritdoc */ -NewTopicController.prototype.setup = function ( mode ) { +NewTopicController.prototype.setup = function () { const rootScrollable = OO.ui.Element.static.getRootScrollableElement( document.body ); // Insert directly after the page content on already existing pages @@ -82,7 +82,7 @@ NewTopicController.prototype.setup = function ( mode ) { this.$pageContainer.append( this.container.$element ); } - NewTopicController.super.prototype.setup.call( this, mode ); + NewTopicController.super.prototype.setup.apply( this, arguments ); if ( this.threadItem.preloadtitle ) { this.sectionTitle.setValue( this.threadItem.preloadtitle ); diff --git a/modules/controller.js b/modules/controller.js index c0505e6f3..90dc35695 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -347,17 +347,18 @@ function init( $container, state ) { * * @param {ThreadItem} comment * @param {jQuery} $link Add section link for new topic controller - * @param {string} [mode] Optionally force a mode, 'visual' or 'source' - * @param {boolean} [hideErrors] Suppress errors, e.g. when restoring auto-save - * @param {boolean} [suppressNotifications] Don't notify the user if recovering auto-save + * @param {Object} [options] Options, see CommentController + * @param {string} [options.mode] Optionally force a mode, 'visual' or 'source' + * @param {boolean} [options.hideErrors] Suppress errors, e.g. when restoring auto-save + * @param {boolean} [options.suppressNotifications] Don't notify the user if recovering auto-save * @param {MemoryStorage} [storage] Storage object for autosave */ - function setupController( comment, $link, mode, hideErrors, suppressNotifications, storage ) { - let commentController, $addSectionLink; - + function setupController( comment, $link, options, storage ) { if ( !storage ) { storage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + comment.id, STORAGE_EXPIRY ); } + + let commentController, $addSectionLink; if ( comment.id === utils.NEW_TOPIC_COMMENT_ID ) { // eslint-disable-next-line no-jquery/no-global-selector $addSectionLink = $( '#ca-addsection' ).find( 'a' ); @@ -396,7 +397,7 @@ function init( $container, state ) { } ); } ); - commentController.setup( mode, hideErrors, suppressNotifications ); + commentController.setup( options ); if ( lastControllerScrollOffset ) { $( document.documentElement ).scrollTop( $( document.documentElement ).scrollTop() + @@ -486,7 +487,11 @@ function init( $container, state ) { } // Wait for the 'hashchange' event to be handled by the mobile code setTimeout( () => { - setupController( comment, $link, mode, true, !state.firstLoad, replyStorage ); + setupController( comment, $link, { + mode: mode, + hideErrors: true, + suppressNotifications: !state.firstLoad + }, replyStorage ); } ); } ); return false; @@ -496,7 +501,11 @@ function init( $container, state ) { const newTopicStorage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + utils.NEW_TOPIC_COMMENT_ID, STORAGE_EXPIRY ); if ( newTopicStorage.get( 'saveable' ) || newTopicStorage.get( 'title' ) ) { const mode = newTopicStorage.get( 'mode' ); - setupController( newTopicComment(), $( [] ), mode, true, !state.firstLoad, newTopicStorage ); + setupController( newTopicComment(), $( [] ), { + mode: mode, + hideErrors: true, + suppressNotifications: !state.firstLoad + }, newTopicStorage ); } else if ( mw.config.get( 'wgDiscussionToolsStartNewTopicTool' ) ) { const data = linksController.parseNewTopicLink( location.href ); setupController( newTopicComment( data ), $( [] ) );