mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
CommentController: Merge (mode, hideErrors, suppressNotifications) into options
Change-Id: Ib8b75fd44fcf560d30e2a6a6f79a9e833c0e5200
This commit is contained in:
parent
70f3c2a1e4
commit
31dc9b4e1c
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 ), $( [] ) );
|
||||
|
|
Loading…
Reference in a new issue