2020-02-25 02:10:27 +00:00
|
|
|
var controller = require( 'ext.discussionTools.init' ).controller,
|
2020-03-08 14:32:38 +00:00
|
|
|
utils = require( 'ext.discussionTools.init' ).utils,
|
2021-03-08 13:23:00 +00:00
|
|
|
logger = require( 'ext.discussionTools.init' ).logger,
|
2021-02-25 22:29:22 +00:00
|
|
|
ModeTabSelectWidget = require( './ModeTabSelectWidget.js' ),
|
|
|
|
ModeTabOptionWidget = require( './ModeTabOptionWidget.js' ),
|
2021-10-04 22:37:51 +00:00
|
|
|
licenseMessages = require( './licenseMessages.json' ),
|
2021-03-08 13:25:59 +00:00
|
|
|
featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ) || {},
|
|
|
|
enable2017Wikitext = featuresEnabled.sourcemodetoolbar;
|
2019-12-10 21:46:22 +00:00
|
|
|
|
2021-01-18 18:18:32 +00:00
|
|
|
require( './AbandonCommentDialog.js' );
|
|
|
|
require( './AbandonTopicDialog.js' );
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
/**
|
|
|
|
* DiscussionTools ReplyWidget class
|
|
|
|
*
|
2019-12-10 21:46:22 +00:00
|
|
|
* @class mw.dt.ReplyWidget
|
2019-11-05 14:07:50 +00:00
|
|
|
* @extends OO.ui.Widget
|
|
|
|
* @constructor
|
2020-04-27 15:50:02 +00:00
|
|
|
* @param {CommentController} commentController Comment controller
|
2021-06-09 23:22:28 +00:00
|
|
|
* @param {CommentDetails} commentDetails
|
2019-11-05 14:07:50 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2019-11-20 20:27:08 +00:00
|
|
|
* @param {Object} [config.input] Configuration options for the comment input widget
|
2019-11-05 14:07:50 +00:00
|
|
|
*/
|
2021-12-20 17:06:24 +00:00
|
|
|
function ReplyWidget( commentController, commentDetails, config ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var widget = this;
|
2019-11-20 20:27:08 +00:00
|
|
|
|
|
|
|
config = config || {};
|
2019-11-19 19:33:14 +00:00
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Parent constructor
|
2019-12-10 21:46:22 +00:00
|
|
|
ReplyWidget.super.call( this, config );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-03-19 00:03:09 +00:00
|
|
|
this.pending = false;
|
2022-09-03 04:55:42 +00:00
|
|
|
this.isTornDown = false;
|
2020-04-27 15:50:02 +00:00
|
|
|
this.commentController = commentController;
|
2021-12-20 17:06:24 +00:00
|
|
|
var threadItem = commentController.getThreadItem();
|
2021-06-09 23:22:28 +00:00
|
|
|
this.commentDetails = commentDetails;
|
2021-12-20 17:06:24 +00:00
|
|
|
this.isNewTopic = !!threadItem.isNewTopic;
|
2021-06-09 23:22:28 +00:00
|
|
|
this.pageName = commentDetails.pageName;
|
|
|
|
this.oldId = commentDetails.oldId;
|
2021-10-25 14:27:04 +00:00
|
|
|
// pageExists can only be false for the new comment tool, so we
|
|
|
|
// don't need to worry about transcluded replies.
|
|
|
|
this.pageExists = mw.config.get( 'wgRelevantArticleId', 0 ) !== 0;
|
2021-12-20 17:06:24 +00:00
|
|
|
var contextNode = utils.closestElement( threadItem.range.endContainer, [ 'dl', 'ul', 'ol' ] );
|
2022-02-21 18:54:15 +00:00
|
|
|
this.context = contextNode ? contextNode.tagName.toLowerCase() : 'dl';
|
2020-04-10 12:57:51 +00:00
|
|
|
// TODO: Should storagePrefix include pageName?
|
2021-12-20 17:06:24 +00:00
|
|
|
this.storagePrefix = 'reply/' + threadItem.id;
|
2022-02-01 22:55:57 +00:00
|
|
|
this.storage = controller.storage;
|
2020-05-20 21:48:06 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
this.contentDir = $( '#mw-content-text' ).css( 'direction' );
|
2022-05-05 17:08:24 +00:00
|
|
|
this.hideNewCommentsWarning = false;
|
2020-06-01 13:45:55 +00:00
|
|
|
// Floating position for scroll back buttons: 'top', 'bottom', or null
|
|
|
|
this.floating = null;
|
|
|
|
// Copied from ve.init.Platform.static.isIos
|
|
|
|
this.isIos = /ipad|iphone|ipod/i.test( navigator.userAgent );
|
|
|
|
|
|
|
|
this.$window = $( this.getElementWindow() );
|
|
|
|
this.onWindowScrollThrottled = OO.ui.throttle( this.onWindowScroll.bind( this ), 100 );
|
|
|
|
this.onViewportChangeThrottled = OO.ui.throttle( this.onViewportChange.bind( this ), 100 );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var inputConfig = $.extend(
|
2020-07-20 14:13:59 +00:00
|
|
|
{
|
2020-08-29 12:00:51 +00:00
|
|
|
placeholder: this.isNewTopic ?
|
|
|
|
mw.msg( 'discussiontools-replywidget-placeholder-newtopic' ) :
|
2021-12-20 17:06:24 +00:00
|
|
|
mw.msg( 'discussiontools-replywidget-placeholder-reply', threadItem.author ),
|
2021-12-20 17:17:27 +00:00
|
|
|
authors: this.isNewTopic ?
|
|
|
|
// No suggestions in new topic tool yet (T277357)
|
|
|
|
[] :
|
2021-12-20 17:06:24 +00:00
|
|
|
// threadItem is a CommentItem when replying
|
|
|
|
threadItem.getHeading().getAuthorsBelow()
|
2020-07-20 14:13:59 +00:00
|
|
|
},
|
2020-02-25 17:57:23 +00:00
|
|
|
config.input
|
|
|
|
);
|
|
|
|
this.replyBodyWidget = this.createReplyBodyWidget( inputConfig );
|
2020-08-29 12:00:51 +00:00
|
|
|
this.replyButtonLabel = this.isNewTopic ?
|
|
|
|
mw.msg( 'discussiontools-replywidget-newtopic' ) :
|
|
|
|
mw.msg( 'discussiontools-replywidget-reply' );
|
2019-11-05 14:07:50 +00:00
|
|
|
this.replyButton = new OO.ui.ButtonWidget( {
|
|
|
|
flags: [ 'primary', 'progressive' ],
|
2020-08-29 12:00:51 +00:00
|
|
|
label: this.replyButtonLabel,
|
|
|
|
title: this.replyButtonLabel + ' ' +
|
2020-11-22 22:04:25 +00:00
|
|
|
// TODO: Use VE keyboard shortcut generating code
|
|
|
|
( $.client.profile().platform === 'mac' ?
|
|
|
|
'⌘⏎' :
|
|
|
|
mw.msg( 'visualeditor-key-ctrl' ) + '+' + mw.msg( 'visualeditor-key-enter' )
|
|
|
|
)
|
2019-11-05 14:07:50 +00:00
|
|
|
} );
|
|
|
|
this.cancelButton = new OO.ui.ButtonWidget( {
|
|
|
|
flags: [ 'destructive' ],
|
2020-02-03 20:34:13 +00:00
|
|
|
label: mw.msg( 'discussiontools-replywidget-cancel' ),
|
2020-11-22 22:04:25 +00:00
|
|
|
framed: false,
|
|
|
|
title: mw.msg( 'discussiontools-replywidget-cancel' ) + ' ' +
|
|
|
|
// TODO: Use VE keyboard shortcut generating code
|
|
|
|
( $.client.profile().platform === 'mac' ?
|
|
|
|
'⎋' :
|
|
|
|
mw.msg( 'visualeditor-key-escape' )
|
|
|
|
)
|
2019-11-05 14:07:50 +00:00
|
|
|
} );
|
|
|
|
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$headerWrapper = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-headerWrapper' );
|
2020-12-15 19:45:05 +00:00
|
|
|
|
|
|
|
if ( !OO.ui.isMobile() ) {
|
|
|
|
this.modeTabSelect = new ModeTabSelectWidget( {
|
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-modeTabs' ],
|
|
|
|
items: [
|
|
|
|
new ModeTabOptionWidget( {
|
|
|
|
label: mw.msg( 'discussiontools-replywidget-mode-visual' ),
|
|
|
|
data: 'visual'
|
|
|
|
} ),
|
|
|
|
new ModeTabOptionWidget( {
|
|
|
|
label: mw.msg( 'discussiontools-replywidget-mode-source' ),
|
|
|
|
data: 'source'
|
|
|
|
} )
|
|
|
|
],
|
|
|
|
framed: false
|
|
|
|
} );
|
|
|
|
this.modeTabSelect.$element.attr( 'aria-label', mw.msg( 'visualeditor-mweditmode-tooltip' ) );
|
|
|
|
// Make the option for the current mode disabled, to make it un-interactable
|
|
|
|
// (we override the styles to make it look as if it was selected)
|
|
|
|
this.modeTabSelect.findItemFromData( this.getMode() ).setDisabled( true );
|
|
|
|
this.modeTabSelect.connect( this, {
|
|
|
|
choose: 'onModeTabSelectChoose'
|
|
|
|
} );
|
|
|
|
this.$headerWrapper.append(
|
|
|
|
// Visual mode toolbar attached here by CommentTarget#attachToolbar
|
|
|
|
this.modeTabSelect.$element
|
|
|
|
);
|
|
|
|
}
|
2020-07-31 20:24:51 +00:00
|
|
|
|
2022-05-05 17:08:24 +00:00
|
|
|
this.$bodyWrapper = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-bodyWrapper' ).append(
|
|
|
|
this.replyBodyWidget.$element
|
|
|
|
);
|
|
|
|
|
2020-05-20 21:48:06 +00:00
|
|
|
this.$preview = $( '<div>' )
|
2021-03-13 14:39:39 +00:00
|
|
|
.addClass( 'ext-discussiontools-ui-replyWidget-preview' )
|
2020-05-20 21:48:06 +00:00
|
|
|
.attr( 'data-label', mw.msg( 'discussiontools-replywidget-preview' ) )
|
|
|
|
// Set preview direction to content direction
|
|
|
|
.attr( 'dir', this.contentDir );
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$actionsWrapper = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-actionsWrapper' );
|
|
|
|
this.$actions = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-actions' ).append(
|
2020-02-03 20:34:13 +00:00
|
|
|
this.cancelButton.$element,
|
|
|
|
this.replyButton.$element
|
|
|
|
);
|
2020-08-25 12:31:54 +00:00
|
|
|
|
|
|
|
this.editSummaryInput = new OO.ui.TextInputWidget( {
|
2021-03-13 14:39:39 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-editSummary' ]
|
2020-08-25 12:31:54 +00:00
|
|
|
} );
|
|
|
|
mw.widgets.visibleCodePointLimit( this.editSummaryInput, mw.config.get( 'wgCommentCodePointLimit' ) );
|
|
|
|
|
|
|
|
this.editSummaryField = new OO.ui.FieldLayout(
|
|
|
|
this.editSummaryInput,
|
|
|
|
{
|
|
|
|
align: 'top',
|
2021-03-13 14:39:39 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-editSummaryField' ],
|
2020-08-25 12:31:54 +00:00
|
|
|
label: mw.msg( 'discussiontools-replywidget-summary' )
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.advancedToggle = new OO.ui.ButtonWidget( {
|
|
|
|
label: mw.msg( 'discussiontools-replywidget-advanced' ),
|
|
|
|
indicator: 'down',
|
|
|
|
framed: false,
|
|
|
|
flags: [ 'progressive' ],
|
2021-03-13 14:39:39 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-advancedToggle' ]
|
2020-08-25 12:31:54 +00:00
|
|
|
} );
|
|
|
|
this.advanced = new OO.ui.MessageWidget( {
|
|
|
|
type: 'message',
|
|
|
|
$content: this.editSummaryField.$element,
|
2021-03-13 14:39:39 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-advanced' ]
|
2020-08-25 12:31:54 +00:00
|
|
|
} ).toggle( false ).setIcon( '' );
|
|
|
|
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$footer = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-footer' );
|
2020-08-19 20:03:41 +00:00
|
|
|
if ( this.pageName !== mw.config.get( 'wgRelevantPageName' ) ) {
|
2020-03-12 19:58:36 +00:00
|
|
|
this.$footer.append( $( '<p>' ).append(
|
2020-08-19 20:03:41 +00:00
|
|
|
mw.message( 'discussiontools-replywidget-transcluded', this.pageName ).parseDom()
|
2020-03-12 19:58:36 +00:00
|
|
|
) );
|
|
|
|
}
|
2021-09-21 10:15:44 +00:00
|
|
|
var $footerLinks = $( '<ul>' ).addClass( 'ext-discussiontools-ui-replyWidget-footer-links' );
|
|
|
|
if ( !mw.user.isAnon() ) {
|
|
|
|
$footerLinks.append(
|
|
|
|
$( '<li>' ).append(
|
|
|
|
$( '<a>' )
|
|
|
|
.attr( {
|
|
|
|
href: mw.util.getUrl( 'Special:Preferences#mw-prefsection-editing-discussion' ),
|
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
|
|
|
} )
|
|
|
|
.text( mw.msg( 'discussiontools-replywidget-preferences' ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$footerLinks.append(
|
|
|
|
$( '<li>' ).append(
|
2020-04-07 14:33:32 +00:00
|
|
|
$( '<a>' )
|
|
|
|
.attr( {
|
2021-05-24 13:36:43 +00:00
|
|
|
href: this.isNewTopic ?
|
|
|
|
mw.msg( 'discussiontools-replywidget-feedback-link-newtopic' ) :
|
|
|
|
mw.msg( 'discussiontools-replywidget-feedback-link' ),
|
2020-04-07 14:33:32 +00:00
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
|
|
|
} )
|
|
|
|
.text( mw.msg( 'discussiontools-replywidget-feedback' ) )
|
|
|
|
)
|
|
|
|
);
|
2021-09-21 10:15:44 +00:00
|
|
|
this.$footer.append(
|
2021-10-04 22:37:51 +00:00
|
|
|
$( '<p>' ).addClass( 'plainlinks' ).html(
|
|
|
|
this.isNewTopic ? licenseMessages.newtopic : licenseMessages.reply
|
2021-09-21 10:15:44 +00:00
|
|
|
),
|
|
|
|
$footerLinks
|
|
|
|
);
|
2020-03-12 19:58:36 +00:00
|
|
|
this.$actionsWrapper.append( this.$footer, this.$actions );
|
2019-11-20 20:27:08 +00:00
|
|
|
|
2020-06-01 13:45:55 +00:00
|
|
|
this.viewportScrollContainer = OO.ui.Element.static.getClosestScrollableContainer( document.body );
|
|
|
|
this.scrollBackTopButton = new OO.ui.ButtonWidget( {
|
2022-10-17 13:49:36 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-scrollback-top mw-sticky-header-element' ],
|
2020-06-01 13:45:55 +00:00
|
|
|
icon: 'collapse',
|
|
|
|
label: mw.msg(
|
|
|
|
this.isNewTopic ?
|
|
|
|
'discussiontools-replywidget-return-to-newtopic' :
|
|
|
|
'discussiontools-replywidget-return-to-reply'
|
|
|
|
),
|
|
|
|
flags: [ 'progressive' ]
|
|
|
|
} );
|
|
|
|
this.scrollBackBottomButton = new OO.ui.ButtonWidget( {
|
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-scrollback-bottom' ],
|
|
|
|
icon: 'expand',
|
|
|
|
label: mw.msg(
|
|
|
|
this.isNewTopic ?
|
|
|
|
'discussiontools-replywidget-return-to-newtopic' :
|
|
|
|
'discussiontools-replywidget-return-to-reply'
|
|
|
|
),
|
|
|
|
flags: [ 'progressive' ]
|
|
|
|
} );
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Events
|
|
|
|
this.replyButton.connect( this, { click: 'onReplyClick' } );
|
2020-01-13 19:29:07 +00:00
|
|
|
this.cancelButton.connect( this, { click: 'tryTeardown' } );
|
2020-08-25 12:31:54 +00:00
|
|
|
this.$element.on( 'keydown', this.onKeyDown.bind( this, true ) );
|
2019-12-10 15:15:40 +00:00
|
|
|
this.beforeUnloadHandler = this.onBeforeUnload.bind( this );
|
2020-02-26 05:20:56 +00:00
|
|
|
this.unloadHandler = this.onUnload.bind( this );
|
2021-10-25 14:27:04 +00:00
|
|
|
this.onWatchToggleHandler = this.onWatchToggle.bind( this );
|
2020-08-25 12:31:54 +00:00
|
|
|
this.advancedToggle.connect( this, { click: 'onAdvancedToggleClick' } );
|
|
|
|
this.editSummaryInput.connect( this, { change: 'onEditSummaryChange' } );
|
|
|
|
this.editSummaryInput.$input.on( 'keydown', this.onKeyDown.bind( this, false ) );
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
|
|
|
this.commentController.sectionTitle.$input.on( 'keydown', this.onKeyDown.bind( this, false ) );
|
|
|
|
}
|
2020-06-01 13:45:55 +00:00
|
|
|
this.scrollBackTopButton.connect( this, { click: 'onScrollBackButtonClick' } );
|
|
|
|
this.scrollBackBottomButton.connect( this, { click: 'onScrollBackButtonClick' } );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2019-11-20 20:27:08 +00:00
|
|
|
this.onInputChangeThrottled = OO.ui.throttle( this.onInputChange.bind( this ), 1000 );
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Initialization
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$element.addClass( 'ext-discussiontools-ui-replyWidget' ).append(
|
2020-07-31 20:24:51 +00:00
|
|
|
this.$headerWrapper,
|
2022-05-05 17:08:24 +00:00
|
|
|
this.$bodyWrapper,
|
2020-02-03 20:34:13 +00:00
|
|
|
this.$preview,
|
2020-08-25 12:31:54 +00:00
|
|
|
this.advancedToggle.$element,
|
|
|
|
this.advanced.$element,
|
2020-06-01 13:45:55 +00:00
|
|
|
this.$actionsWrapper,
|
|
|
|
this.scrollBackTopButton.$element,
|
|
|
|
this.scrollBackBottomButton.$element
|
2019-11-05 14:07:50 +00:00
|
|
|
);
|
2020-05-20 21:48:06 +00:00
|
|
|
// Set direction to interface direction
|
|
|
|
this.$element.attr( 'dir', $( document.body ).css( 'direction' ) );
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
2021-03-13 14:39:39 +00:00
|
|
|
this.$element.addClass( 'ext-discussiontools-ui-replyWidget-newTopic' );
|
2020-08-29 12:00:51 +00:00
|
|
|
}
|
2019-11-19 19:33:14 +00:00
|
|
|
|
|
|
|
if ( mw.user.isAnon() ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var returnTo = {
|
2022-05-12 01:21:44 +00:00
|
|
|
returntoquery: window.location.search.slice( 1 ),
|
2019-11-19 19:33:14 +00:00
|
|
|
returnto: mw.config.get( 'wgPageName' )
|
|
|
|
};
|
2020-02-03 20:34:13 +00:00
|
|
|
this.anonWarning = new OO.ui.MessageWidget( {
|
2021-06-22 17:01:52 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-anonWarning' ],
|
2020-02-03 20:34:13 +00:00
|
|
|
type: 'warning',
|
|
|
|
label: mw.message( 'discussiontools-replywidget-anon-warning' )
|
|
|
|
.params( [
|
|
|
|
mw.util.getUrl( 'Special:Userlogin', returnTo ),
|
|
|
|
mw.util.getUrl( 'Special:Userlogin/signup', returnTo )
|
|
|
|
] )
|
|
|
|
.parseDom()
|
|
|
|
} );
|
|
|
|
this.anonWarning.$element.append( this.$actions );
|
2021-06-22 17:01:52 +00:00
|
|
|
this.anonWarning.$label.addClass( 'plainlinks' );
|
2020-03-12 19:58:36 +00:00
|
|
|
this.$element.append( this.anonWarning.$element, this.$footer );
|
2020-02-03 20:34:13 +00:00
|
|
|
this.$actionsWrapper.detach();
|
2019-11-19 19:33:14 +00:00
|
|
|
}
|
2019-11-20 20:27:08 +00:00
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
this.checkboxesPromise = controller.getCheckboxesPromise( this.pageName, this.oldId );
|
2020-03-04 16:19:19 +00:00
|
|
|
this.checkboxesPromise.then( function ( checkboxes ) {
|
2020-08-26 22:46:34 +00:00
|
|
|
function trackCheckbox( n ) {
|
2020-06-04 17:19:46 +00:00
|
|
|
mw.track( 'dt.schemaVisualEditorFeatureUse', {
|
|
|
|
feature: 'dtReply',
|
2020-08-26 22:46:34 +00:00
|
|
|
action: 'checkbox-' + n
|
2020-06-04 17:19:46 +00:00
|
|
|
} );
|
|
|
|
}
|
2020-03-04 16:19:19 +00:00
|
|
|
if ( checkboxes.checkboxFields ) {
|
2021-03-13 14:39:39 +00:00
|
|
|
widget.$checkboxes = $( '<div>' ).addClass( 'ext-discussiontools-ui-replyWidget-checkboxes' );
|
2020-03-04 16:19:19 +00:00
|
|
|
checkboxes.checkboxFields.forEach( function ( field ) {
|
|
|
|
widget.$checkboxes.append( field.$element );
|
|
|
|
} );
|
2021-03-22 16:28:13 +00:00
|
|
|
widget.editSummaryField.$body.append( widget.$checkboxes );
|
2020-06-04 17:19:46 +00:00
|
|
|
|
|
|
|
// bind logging:
|
2021-04-08 13:46:09 +00:00
|
|
|
for ( var name in checkboxes.checkboxesByName ) {
|
2020-06-04 17:19:46 +00:00
|
|
|
checkboxes.checkboxesByName[ name ].$element.off( '.dtReply' ).on( 'click.dtReply', trackCheckbox.bind( this, name ) );
|
|
|
|
}
|
2020-03-04 16:19:19 +00:00
|
|
|
}
|
|
|
|
} );
|
2019-12-10 21:46:22 +00:00
|
|
|
}
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2019-12-10 21:46:22 +00:00
|
|
|
OO.inheritClass( ReplyWidget, OO.ui.Widget );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Create the widget for the reply body
|
|
|
|
*
|
|
|
|
* The body widget should implement #setReadOnly, #pushPending and #popPending
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @return {OO.ui.Widget}
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.createReplyBodyWidget = null;
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
/**
|
|
|
|
* Focus the widget
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @chainable
|
|
|
|
* @return {ReplyWidget}
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.focus = null;
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Get value of reply body, HTML or wikitext
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.getValue = null;
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
2021-12-20 21:17:23 +00:00
|
|
|
* Check if the reply widget is empty
|
2021-12-20 15:58:01 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.isEmpty = null;
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Get the current input mode of the reply widget, 'source' or 'visual'
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2020-04-02 15:43:49 +00:00
|
|
|
ReplyWidget.prototype.getMode = null;
|
2020-03-06 15:18:30 +00:00
|
|
|
|
2020-09-21 19:52:47 +00:00
|
|
|
/**
|
|
|
|
* Restore the widget to its original state
|
|
|
|
*
|
|
|
|
* Clear any widget values, reset UI states, and clear
|
2022-09-03 04:55:42 +00:00
|
|
|
* any (optional) auto-save values.
|
2022-02-02 16:15:50 +00:00
|
|
|
*
|
|
|
|
* @param {boolean} [preserveStorage] Preserve auto-save storage
|
2020-09-21 19:52:47 +00:00
|
|
|
*/
|
2022-02-02 16:15:50 +00:00
|
|
|
ReplyWidget.prototype.clear = function ( preserveStorage ) {
|
2022-02-02 21:49:26 +00:00
|
|
|
if ( this.saveErrorMessage ) {
|
|
|
|
this.saveErrorMessage.$element.remove();
|
|
|
|
this.saveErrorMessage = null;
|
2019-12-11 04:40:17 +00:00
|
|
|
}
|
2022-09-03 04:55:42 +00:00
|
|
|
if ( this.previewRequest ) {
|
|
|
|
this.previewRequest.abort();
|
|
|
|
this.previewRequest = null;
|
|
|
|
}
|
2020-08-19 20:03:41 +00:00
|
|
|
this.$preview.empty();
|
2020-08-29 12:00:51 +00:00
|
|
|
this.previewWikitext = null;
|
|
|
|
this.previewTitle = null;
|
2020-09-21 19:52:47 +00:00
|
|
|
this.toggleAdvanced( false );
|
|
|
|
|
2022-02-02 16:15:50 +00:00
|
|
|
if ( !preserveStorage ) {
|
|
|
|
this.clearStorage();
|
|
|
|
} else {
|
|
|
|
this.storage.set( this.storagePrefix + '/saveable', '1' );
|
|
|
|
}
|
2021-08-06 00:31:50 +00:00
|
|
|
|
|
|
|
this.emit( 'clear' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove any storage that the widget is using
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.clearStorage = function () {
|
2020-08-19 20:03:41 +00:00
|
|
|
this.storage.remove( this.storagePrefix + '/mode' );
|
|
|
|
this.storage.remove( this.storagePrefix + '/saveable' );
|
2020-08-25 12:31:54 +00:00
|
|
|
this.storage.remove( this.storagePrefix + '/summary' );
|
|
|
|
this.storage.remove( this.storagePrefix + '/showAdvanced' );
|
2021-10-18 22:18:07 +00:00
|
|
|
this.storage.remove( this.storagePrefix + '/formToken' );
|
2021-08-06 00:31:50 +00:00
|
|
|
|
|
|
|
this.emit( 'clearStorage' );
|
2019-12-11 04:40:17 +00:00
|
|
|
};
|
|
|
|
|
2020-06-01 13:45:55 +00:00
|
|
|
/**
|
|
|
|
* Handle window scroll events
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onWindowScroll = function () {
|
|
|
|
var rect = this.$element[ 0 ].getBoundingClientRect();
|
|
|
|
var viewportHeight = window.visualViewport ? visualViewport.height : this.viewportScrollContainer.clientHeight;
|
|
|
|
var floating = rect.bottom < 0 ? 'top' :
|
|
|
|
( rect.top > viewportHeight ? 'bottom' : null );
|
|
|
|
|
|
|
|
if ( floating !== this.floating ) {
|
|
|
|
this.floating = floating;
|
|
|
|
// Always remove classes as we have switched directly from top to bottom with a fast scroll
|
|
|
|
this.$element
|
|
|
|
.removeClass( 'ext-discussiontools-ui-replyWidget-floating-top ext-discussiontools-ui-replyWidget-floating-bottom' );
|
|
|
|
|
|
|
|
if ( this.floating ) {
|
|
|
|
// The following classes are used here:
|
|
|
|
// * ext-discussiontools-ui-replyWidget-floating-top
|
|
|
|
// * ext-discussiontools-ui-replyWidget-floating-bottom
|
|
|
|
this.$element.addClass( 'ext-discussiontools-ui-replyWidget-floating-' + this.floating );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle events which change the visualViewport (scroll/resize)
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onViewportChange = function () {
|
|
|
|
if ( this.floating ) {
|
|
|
|
var isKeyboardOpen = visualViewport.height < this.viewportScrollContainer.clientHeight;
|
|
|
|
this.scrollBackBottomButton.toggle( !isKeyboardOpen );
|
|
|
|
this.scrollBackTopButton.toggle( !isKeyboardOpen );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.setPending = function ( pending ) {
|
2020-03-19 00:03:09 +00:00
|
|
|
this.pending = pending;
|
2019-11-05 14:07:50 +00:00
|
|
|
if ( pending ) {
|
|
|
|
this.replyButton.setDisabled( true );
|
|
|
|
this.cancelButton.setDisabled( true );
|
2020-08-21 19:43:05 +00:00
|
|
|
this.replyBodyWidget.setReadOnly( true );
|
|
|
|
this.replyBodyWidget.pushPending();
|
2019-11-05 14:07:50 +00:00
|
|
|
} else {
|
|
|
|
this.replyButton.setDisabled( false );
|
|
|
|
this.cancelButton.setDisabled( false );
|
2020-08-21 19:43:05 +00:00
|
|
|
this.replyBodyWidget.setReadOnly( false );
|
|
|
|
this.replyBodyWidget.popPending();
|
2020-04-29 16:43:11 +00:00
|
|
|
this.updateButtons();
|
2019-11-05 14:07:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-07 19:16:14 +00:00
|
|
|
ReplyWidget.prototype.saveEditMode = function ( mode ) {
|
2020-10-23 11:02:18 +00:00
|
|
|
controller.getApi().saveOption( 'discussiontools-editmode', mode ).then( function () {
|
2020-05-07 19:16:14 +00:00
|
|
|
mw.user.options.set( 'discussiontools-editmode', mode );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2020-08-25 12:31:54 +00:00
|
|
|
ReplyWidget.prototype.onAdvancedToggleClick = function () {
|
2021-04-08 13:46:09 +00:00
|
|
|
var showAdvanced = !this.showAdvanced;
|
2020-09-14 18:46:59 +00:00
|
|
|
mw.track( 'dt.schemaVisualEditorFeatureUse', {
|
|
|
|
feature: 'dtReply',
|
2020-10-15 15:04:36 +00:00
|
|
|
action: 'advanced-' + ( showAdvanced ? 'show' : 'hide' )
|
2020-09-14 18:46:59 +00:00
|
|
|
} );
|
2020-10-28 16:57:23 +00:00
|
|
|
controller.getApi().saveOption( 'discussiontools-showadvanced', +showAdvanced ).then( function () {
|
2020-10-15 15:04:36 +00:00
|
|
|
mw.user.options.set( 'discussiontools-showadvanced', +showAdvanced );
|
|
|
|
} );
|
|
|
|
this.toggleAdvanced( showAdvanced );
|
2020-08-25 12:31:54 +00:00
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( showAdvanced ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var summary = this.editSummaryInput.getValue();
|
2020-08-29 12:00:51 +00:00
|
|
|
|
|
|
|
// If the current summary has not been edited yet, select the text following the autocomment to
|
|
|
|
// make it easier to change. Otherwise, move cursor to end.
|
2021-04-08 13:46:09 +00:00
|
|
|
var selectFromIndex = summary.length;
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var titleText = this.commentController.sectionTitle.getValue();
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( summary === this.commentController.generateSummary( titleText ) ) {
|
|
|
|
selectFromIndex = titleText.length + '/* '.length + ' */ '.length;
|
|
|
|
}
|
2020-08-25 12:31:54 +00:00
|
|
|
} else {
|
2020-08-29 12:00:51 +00:00
|
|
|
// Same as summary.endsWith( defaultReplyTrail )
|
2021-04-08 13:46:09 +00:00
|
|
|
var defaultReplyTrail = '*/ ' + mw.msg( 'discussiontools-defaultsummary-reply' );
|
|
|
|
var endCommentIndex = summary.indexOf( defaultReplyTrail );
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( endCommentIndex + defaultReplyTrail.length === summary.length ) {
|
|
|
|
selectFromIndex = endCommentIndex + 3;
|
|
|
|
}
|
2020-08-25 12:31:54 +00:00
|
|
|
}
|
2020-08-29 12:00:51 +00:00
|
|
|
|
|
|
|
this.editSummaryInput.selectRange( selectFromIndex, summary.length );
|
2020-08-25 12:31:54 +00:00
|
|
|
this.editSummaryInput.focus();
|
|
|
|
} else {
|
|
|
|
this.focus();
|
|
|
|
}
|
2020-08-29 12:00:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidget.prototype.toggleAdvanced = function ( showAdvanced ) {
|
|
|
|
this.showAdvanced = showAdvanced === undefined ? !this.showAdvanced : showAdvanced;
|
|
|
|
this.advanced.toggle( !!this.showAdvanced );
|
|
|
|
this.advancedToggle.setIndicator( this.showAdvanced ? 'up' : 'down' );
|
|
|
|
|
2020-09-21 19:38:40 +00:00
|
|
|
this.storeEditSummary();
|
2020-08-25 12:31:54 +00:00
|
|
|
this.storage.set( this.storagePrefix + '/showAdvanced', this.showAdvanced ? '1' : '' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidget.prototype.onEditSummaryChange = function () {
|
2020-09-21 19:38:40 +00:00
|
|
|
this.storeEditSummary();
|
2020-08-25 12:31:54 +00:00
|
|
|
};
|
|
|
|
|
2020-09-21 19:38:40 +00:00
|
|
|
ReplyWidget.prototype.storeEditSummary = function () {
|
|
|
|
this.storage.set( this.storagePrefix + '/summary', this.getEditSummary() );
|
|
|
|
};
|
|
|
|
|
2020-08-25 12:31:54 +00:00
|
|
|
ReplyWidget.prototype.getEditSummary = function () {
|
2020-09-17 19:06:51 +00:00
|
|
|
return this.editSummaryInput.getValue();
|
2020-08-25 12:31:54 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
ReplyWidget.prototype.onModeTabSelectChoose = function ( option ) {
|
2021-03-24 14:07:47 +00:00
|
|
|
var mode = option.getData(),
|
2020-04-27 16:23:27 +00:00
|
|
|
widget = this;
|
2020-05-07 19:16:14 +00:00
|
|
|
|
2020-05-21 17:26:08 +00:00
|
|
|
if ( mode === this.getMode() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
this.modeTabSelect.setDisabled( true );
|
2021-03-24 14:07:47 +00:00
|
|
|
this.switch( mode ).then(
|
|
|
|
null,
|
|
|
|
function () {
|
2021-03-29 19:19:52 +00:00
|
|
|
// Switch failed, clear the tab selection
|
|
|
|
widget.modeTabSelect.selectItem( null );
|
2021-03-24 14:07:47 +00:00
|
|
|
}
|
|
|
|
).always( function () {
|
|
|
|
widget.modeTabSelect.setDisabled( false );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyWidget.prototype.switch = function ( mode ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var widget = this;
|
2021-03-24 14:07:47 +00:00
|
|
|
|
|
|
|
if ( mode === this.getMode() ) {
|
|
|
|
return $.Deferred().reject().promise();
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var promise;
|
2021-03-24 14:07:47 +00:00
|
|
|
this.setPending( true );
|
2020-05-07 19:16:14 +00:00
|
|
|
switch ( mode ) {
|
2020-04-27 16:23:27 +00:00
|
|
|
case 'source':
|
|
|
|
promise = this.commentController.switchToWikitext();
|
|
|
|
break;
|
|
|
|
case 'visual':
|
|
|
|
promise = this.commentController.switchToVisual();
|
|
|
|
break;
|
|
|
|
}
|
2020-05-07 19:16:14 +00:00
|
|
|
// TODO: We rely on #setup to call #saveEditMode, so when we have 2017WTE
|
|
|
|
// we will need to save the new preference here as switching will not
|
|
|
|
// reload the editor.
|
2021-03-24 14:07:47 +00:00
|
|
|
return promise.then( function () {
|
2020-10-29 02:59:32 +00:00
|
|
|
// Switch succeeded
|
|
|
|
mw.track( 'dt.schemaVisualEditorFeatureUse', {
|
|
|
|
feature: 'editor-switch',
|
2021-03-08 13:23:00 +00:00
|
|
|
action: (
|
|
|
|
mode === 'visual' ?
|
|
|
|
'visual' :
|
|
|
|
( enable2017Wikitext ? 'source-nwe' : 'source' )
|
|
|
|
) + '-desktop'
|
2020-10-29 02:59:32 +00:00
|
|
|
} );
|
2020-04-27 16:23:27 +00:00
|
|
|
} ).always( function () {
|
|
|
|
widget.setPending( false );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the widget
|
|
|
|
*
|
2020-09-25 17:08:08 +00:00
|
|
|
* @param {Object} [data] Initial data
|
|
|
|
* @param {Mixed} [data.value] Initial value
|
|
|
|
* @param {string} [data.showAdvanced] Whether the "Advanced" menu is initially visible
|
|
|
|
* @param {string} [data.editSummary] Initial edit summary
|
2020-04-27 16:23:27 +00:00
|
|
|
* @chainable
|
|
|
|
* @return {ReplyWidget}
|
|
|
|
*/
|
2020-09-25 17:08:08 +00:00
|
|
|
ReplyWidget.prototype.setup = function ( data ) {
|
|
|
|
data = data || {};
|
|
|
|
|
2019-12-10 15:15:40 +00:00
|
|
|
this.bindBeforeUnloadHandler();
|
2020-05-07 19:16:14 +00:00
|
|
|
if ( this.modeTabSelect ) {
|
2021-02-25 22:29:22 +00:00
|
|
|
// Make the option for the current mode disabled, to make it un-interactable
|
|
|
|
// (we override the styles to make it look as if it was selected)
|
|
|
|
this.modeTabSelect.findItemFromData( this.getMode() ).setDisabled( true );
|
2020-05-07 19:16:14 +00:00
|
|
|
}
|
2021-06-29 20:57:06 +00:00
|
|
|
this.saveEditMode( this.getMode() );
|
2020-04-29 16:43:11 +00:00
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var summary = this.storage.get( this.storagePrefix + '/summary' ) || data.editSummary;
|
2020-08-25 12:31:54 +00:00
|
|
|
|
|
|
|
if ( !summary ) {
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
|
|
|
// Edit summary is filled in when the user inputs the topic title,
|
|
|
|
// in NewTopicController#onSectionTitleChange
|
|
|
|
summary = '';
|
|
|
|
} else {
|
2021-12-20 17:06:24 +00:00
|
|
|
var title = this.commentController.getThreadItem().getHeading().getLinkableTitle();
|
2020-08-29 12:00:51 +00:00
|
|
|
summary = ( title ? '/* ' + title + ' */ ' : '' ) +
|
|
|
|
mw.msg( 'discussiontools-defaultsummary-reply' );
|
|
|
|
}
|
2020-08-25 12:31:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 15:04:36 +00:00
|
|
|
this.toggleAdvanced(
|
|
|
|
!!this.storage.get( this.storagePrefix + '/showAdvanced' ) ||
|
|
|
|
!!+mw.user.options.get( 'discussiontools-showadvanced' ) ||
|
|
|
|
!!data.showAdvanced
|
|
|
|
);
|
2020-08-25 12:31:54 +00:00
|
|
|
|
|
|
|
this.editSummaryInput.setValue( summary );
|
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
|
|
|
this.commentController.sectionTitle.connect( this, { change: 'onInputChangeThrottled' } );
|
2020-12-15 19:45:05 +00:00
|
|
|
} else {
|
|
|
|
// De-indent replies on mobile
|
|
|
|
if ( OO.ui.isMobile() ) {
|
|
|
|
this.$element.css( 'margin-left', -this.$element.position().left );
|
|
|
|
}
|
2020-08-29 12:00:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-25 15:47:18 +00:00
|
|
|
mw.hook( 'wikipage.watchlistChange' ).add( this.onWatchToggleHandler );
|
2021-10-25 14:27:04 +00:00
|
|
|
|
2020-06-01 13:45:55 +00:00
|
|
|
// TODO: Use ve.addPassiveEventListener
|
|
|
|
this.$window.on( 'scroll', this.onWindowScrollThrottled );
|
|
|
|
if ( this.isIos && window.visualViewport ) {
|
|
|
|
$( visualViewport ).on( 'scroll resize', this.onViewportChangeThrottled );
|
|
|
|
}
|
|
|
|
|
2020-04-29 16:43:11 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
2021-12-20 21:17:23 +00:00
|
|
|
* Perform additional actions once the widget has been setup and is ready for input
|
2021-12-20 15:58:01 +00:00
|
|
|
*/
|
2020-04-29 16:43:11 +00:00
|
|
|
ReplyWidget.prototype.afterSetup = function () {
|
2020-04-27 16:23:27 +00:00
|
|
|
// Init preview and button state
|
|
|
|
this.onInputChange();
|
2020-04-29 16:43:11 +00:00
|
|
|
// Autosave
|
|
|
|
this.storage.set( this.storagePrefix + '/mode', this.getMode() );
|
2019-12-10 15:15:40 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 22:18:07 +00:00
|
|
|
/**
|
|
|
|
* Get a random token that is unique to this reply instance
|
|
|
|
*
|
|
|
|
* @return {string} Form token
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.getFormToken = function () {
|
|
|
|
var formToken = this.storage.get( this.storagePrefix + '/formToken' );
|
|
|
|
if ( !formToken ) {
|
2021-11-17 22:53:38 +00:00
|
|
|
// See ApiBase::PARAM_MAX_CHARS in ApiDiscussionToolsEdit.php
|
|
|
|
var maxLength = 16;
|
|
|
|
formToken = Math.random().toString( 36 ).slice( 2, maxLength + 2 );
|
2021-10-18 22:18:07 +00:00
|
|
|
this.storage.set( this.storagePrefix + '/formToken', formToken );
|
|
|
|
}
|
|
|
|
return formToken;
|
|
|
|
};
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
/**
|
|
|
|
* Try to teardown the widget, prompting the user if unsaved changes will be lost.
|
|
|
|
*
|
|
|
|
* @chainable
|
2021-01-25 22:41:35 +00:00
|
|
|
* @return {jQuery.Promise} Resolves if widget was torn down, rejects if it wasn't
|
2020-04-27 16:23:27 +00:00
|
|
|
*/
|
2020-01-13 19:29:07 +00:00
|
|
|
ReplyWidget.prototype.tryTeardown = function () {
|
2019-12-10 15:40:52 +00:00
|
|
|
var promise,
|
|
|
|
widget = this;
|
2020-01-13 19:29:07 +00:00
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( !this.isEmpty() || ( this.isNewTopic && this.commentController.sectionTitle.getValue() ) ) {
|
2021-01-18 18:18:32 +00:00
|
|
|
promise = OO.ui.getWindowManager().openWindow( this.isNewTopic ? 'abandontopic' : 'abandoncomment' )
|
2019-12-10 15:40:52 +00:00
|
|
|
.closed.then( function ( data ) {
|
|
|
|
if ( !( data && data.action === 'discard' ) ) {
|
|
|
|
return $.Deferred().reject().promise();
|
|
|
|
}
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( {
|
|
|
|
action: 'abort',
|
|
|
|
mechanism: 'cancel',
|
|
|
|
type: 'abandon'
|
|
|
|
} );
|
2019-12-10 15:40:52 +00:00
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
promise = $.Deferred().resolve().promise();
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( {
|
|
|
|
action: 'abort',
|
|
|
|
mechanism: 'cancel',
|
|
|
|
type: 'nochange'
|
|
|
|
} );
|
2019-12-10 15:40:52 +00:00
|
|
|
}
|
2021-01-25 22:41:35 +00:00
|
|
|
promise = promise.then( function () {
|
2022-08-01 21:05:38 +00:00
|
|
|
widget.teardown( 'abandoned' );
|
2019-12-10 15:40:52 +00:00
|
|
|
} );
|
2021-01-25 22:41:35 +00:00
|
|
|
return promise;
|
2019-12-10 15:15:40 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 16:23:27 +00:00
|
|
|
/**
|
|
|
|
* Teardown the widget
|
|
|
|
*
|
2022-02-02 16:15:50 +00:00
|
|
|
* @param {string} [mode] Teardown mode:
|
|
|
|
* - 'default': The reply was saved and can be discarded
|
|
|
|
* - 'abandoned': The reply was abandoned and discarded
|
|
|
|
* - 'refresh': The page is being refreshed, preserve auto-save
|
2020-04-27 16:23:27 +00:00
|
|
|
* @chainable
|
|
|
|
* @return {ReplyWidget}
|
|
|
|
*/
|
2022-02-02 16:15:50 +00:00
|
|
|
ReplyWidget.prototype.teardown = function ( mode ) {
|
2022-09-03 04:55:42 +00:00
|
|
|
// Call the change handler to save the current value in auto-save
|
|
|
|
this.onInputChange();
|
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.isNewTopic ) {
|
|
|
|
this.commentController.sectionTitle.disconnect( this );
|
|
|
|
}
|
2021-02-15 20:59:32 +00:00
|
|
|
// Make sure that the selector is blurred before it gets removed from the document, otherwise
|
|
|
|
// event handlers for arrow keys are not removed, and it keeps trying to switch modes (T274423)
|
2020-12-15 19:45:05 +00:00
|
|
|
if ( this.modeTabSelect ) {
|
|
|
|
this.modeTabSelect.blur();
|
|
|
|
}
|
2020-01-13 19:29:07 +00:00
|
|
|
this.unbindBeforeUnloadHandler();
|
2020-06-01 13:45:55 +00:00
|
|
|
this.$window.off( 'scroll', this.onWindowScrollThrottled );
|
|
|
|
if ( this.isIos && window.visualViewport ) {
|
|
|
|
$( visualViewport ).off( 'scroll resize', this.onViewportChangeThrottled );
|
|
|
|
}
|
2021-10-25 15:47:18 +00:00
|
|
|
mw.hook( 'wikipage.watchlistChange' ).remove( this.onWatchToggleHandler );
|
2021-10-25 14:27:04 +00:00
|
|
|
|
2022-09-03 04:55:42 +00:00
|
|
|
this.isTornDown = true;
|
2022-02-02 16:15:50 +00:00
|
|
|
this.clear( mode === 'refresh' );
|
|
|
|
this.emit( 'teardown', mode );
|
2020-04-27 16:23:27 +00:00
|
|
|
return this;
|
2020-01-13 19:29:07 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Handle changes to the watch state of the page
|
|
|
|
*
|
2021-10-25 15:47:18 +00:00
|
|
|
* @param {boolean} isWatched
|
|
|
|
* @param {string} expiry
|
|
|
|
* @param {string} expirySelected
|
2021-12-20 15:58:01 +00:00
|
|
|
*/
|
2021-10-25 15:47:18 +00:00
|
|
|
ReplyWidget.prototype.onWatchToggle = function ( isWatched ) {
|
2021-10-25 14:27:04 +00:00
|
|
|
var widget = this;
|
2022-01-10 22:30:09 +00:00
|
|
|
if ( this.pageName === mw.config.get( 'wgRelevantPageName' ) ) {
|
|
|
|
this.checkboxesPromise.then( function ( checkboxes ) {
|
|
|
|
if ( checkboxes.checkboxesByName.wpWatchthis ) {
|
|
|
|
checkboxes.checkboxesByName.wpWatchthis.setSelected(
|
|
|
|
!!mw.user.options.get( 'watchdefault' ) ||
|
|
|
|
( !!mw.user.options.get( 'watchcreations' ) && !widget.pageExists ) ||
|
|
|
|
isWatched
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2021-10-25 14:27:04 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Handle key down events anywhere in the reply widget
|
|
|
|
*
|
|
|
|
* @param {boolean} isMultiline The current input is multiline
|
|
|
|
* @param {jQuery.Event} e Key down event
|
|
|
|
* @return {boolean} Return false to prevent default event
|
|
|
|
*/
|
2020-08-25 12:31:54 +00:00
|
|
|
ReplyWidget.prototype.onKeyDown = function ( isMultiline, e ) {
|
2019-11-05 14:07:50 +00:00
|
|
|
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
2020-01-13 19:29:07 +00:00
|
|
|
this.tryTeardown();
|
2019-11-05 14:07:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-25 12:31:54 +00:00
|
|
|
|
|
|
|
// VE surfaces already handle CTRL+Enter, but this will catch
|
|
|
|
// the plain surface, and the edit summary input.
|
|
|
|
if ( e.which === OO.ui.Keys.ENTER && ( !isMultiline || e.ctrlKey || e.metaKey ) ) {
|
|
|
|
this.onReplyClick();
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-05 14:07:50 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Handle input change events anywhere in the reply widget
|
|
|
|
*/
|
2019-11-20 20:27:08 +00:00
|
|
|
ReplyWidget.prototype.onInputChange = function () {
|
2022-09-03 04:55:42 +00:00
|
|
|
if ( this.isTornDown ) {
|
|
|
|
// Ignore calls after teardown, which would clear the auto-save or crash
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-21 21:11:01 +00:00
|
|
|
this.updateButtons();
|
|
|
|
this.storage.set( this.storagePrefix + '/saveable', this.isEmpty() ? '' : '1' );
|
2020-07-02 15:36:57 +00:00
|
|
|
this.preparePreview();
|
2020-05-21 21:11:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the interface with the preview of the given wikitext.
|
|
|
|
*
|
2020-07-02 15:36:57 +00:00
|
|
|
* @param {string} [wikitext] Wikitext to preview, defaults to current value
|
2020-05-21 21:11:01 +00:00
|
|
|
* @return {jQuery.Promise} Promise resolved when we're done
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.preparePreview = function ( wikitext ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var widget = this;
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-04-02 15:43:49 +00:00
|
|
|
if ( this.getMode() !== 'source' ) {
|
2020-05-21 21:11:01 +00:00
|
|
|
return $.Deferred().resolve().promise();
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:13:35 +00:00
|
|
|
wikitext = wikitext !== undefined ? wikitext : this.getValue();
|
2021-03-24 16:48:10 +00:00
|
|
|
wikitext = utils.htmlTrim( wikitext );
|
2021-04-08 13:46:09 +00:00
|
|
|
var title = this.isNewTopic && this.commentController.sectionTitle.getValue();
|
2020-07-02 15:36:57 +00:00
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
if ( this.previewWikitext === wikitext && this.previewTitle === title ) {
|
2020-05-21 21:11:01 +00:00
|
|
|
return $.Deferred().resolve().promise();
|
2019-11-05 14:07:50 +00:00
|
|
|
}
|
2020-05-21 21:11:01 +00:00
|
|
|
this.previewWikitext = wikitext;
|
2020-08-29 12:00:51 +00:00
|
|
|
this.previewTitle = title;
|
2019-11-20 20:27:08 +00:00
|
|
|
|
|
|
|
if ( this.previewRequest ) {
|
|
|
|
this.previewRequest.abort();
|
|
|
|
this.previewRequest = null;
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var parsePromise;
|
2021-03-24 16:48:10 +00:00
|
|
|
if ( !wikitext ) {
|
2020-01-02 14:59:50 +00:00
|
|
|
parsePromise = $.Deferred().resolve( null ).promise();
|
2019-11-20 20:27:08 +00:00
|
|
|
} else {
|
2020-10-23 11:02:18 +00:00
|
|
|
this.previewRequest = parsePromise = controller.getApi().post( {
|
2022-02-02 00:13:32 +00:00
|
|
|
action: 'discussiontoolspreview',
|
|
|
|
type: this.isNewTopic ? 'topic' : 'reply',
|
|
|
|
page: this.pageName,
|
|
|
|
wikitext: wikitext,
|
2022-06-27 13:40:41 +00:00
|
|
|
sectiontitle: title,
|
|
|
|
useskin: mw.config.get( 'skin' ),
|
|
|
|
mobileformat: OO.ui.isMobile()
|
2019-12-27 18:30:24 +00:00
|
|
|
} );
|
2019-11-20 20:27:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 21:11:01 +00:00
|
|
|
return parsePromise.then( function ( response ) {
|
2022-02-02 00:13:32 +00:00
|
|
|
widget.$preview.html( response ? response.discussiontoolspreview.parse.text : '' );
|
2019-11-20 20:27:08 +00:00
|
|
|
|
2020-01-02 14:59:50 +00:00
|
|
|
if ( response ) {
|
2022-02-02 00:13:32 +00:00
|
|
|
mw.config.set( response.discussiontoolspreview.parse.jsconfigvars );
|
|
|
|
mw.loader.load( response.discussiontoolspreview.parse.modulestyles );
|
|
|
|
mw.loader.load( response.discussiontoolspreview.parse.modules );
|
2020-01-02 14:59:50 +00:00
|
|
|
}
|
2021-04-08 19:38:45 +00:00
|
|
|
|
|
|
|
mw.hook( 'wikipage.content' ).fire( widget.$preview );
|
2019-11-20 20:27:08 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Update buttons when widget state has changed
|
|
|
|
*/
|
2020-04-29 16:43:11 +00:00
|
|
|
ReplyWidget.prototype.updateButtons = function () {
|
|
|
|
this.replyButton.setDisabled( this.isEmpty() );
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Handle the first change in the reply widget
|
|
|
|
*
|
|
|
|
* Currently only the first change in the body, used for logging.
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onFirstChange = function () {
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( { action: 'firstChange' } );
|
|
|
|
};
|
|
|
|
|
2019-12-10 15:15:40 +00:00
|
|
|
/**
|
|
|
|
* Bind the beforeunload handler, if needed and if not already bound.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.bindBeforeUnloadHandler = function () {
|
|
|
|
$( window ).on( 'beforeunload', this.beforeUnloadHandler );
|
2020-02-26 05:20:56 +00:00
|
|
|
$( window ).on( 'unload', this.unloadHandler );
|
2019-12-10 15:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind the beforeunload handler if it is bound.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.unbindBeforeUnloadHandler = function () {
|
|
|
|
$( window ).off( 'beforeunload', this.beforeUnloadHandler );
|
2020-02-26 05:20:56 +00:00
|
|
|
$( window ).off( 'unload', this.unloadHandler );
|
2019-12-10 15:15:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to beforeunload event.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {jQuery.Event} e Event
|
|
|
|
* @return {string|undefined}
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onBeforeUnload = function ( e ) {
|
|
|
|
if ( !this.isEmpty() ) {
|
|
|
|
e.preventDefault();
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-26 05:20:56 +00:00
|
|
|
/**
|
|
|
|
* Respond to unload event.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {jQuery.Event} e Event
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onUnload = function () {
|
|
|
|
logger( {
|
|
|
|
action: 'abort',
|
|
|
|
type: this.isEmpty() ? 'nochange' : 'abandon',
|
|
|
|
mechanism: 'navigate'
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2022-02-08 15:47:28 +00:00
|
|
|
ReplyWidget.prototype.updateParentRemovedError = function ( parentRemoved ) {
|
|
|
|
if ( !parentRemoved ) {
|
|
|
|
if ( this.parentRemovedErrorMessage ) {
|
|
|
|
this.parentRemovedErrorMessage.$element.remove();
|
|
|
|
this.parentRemovedErrorMessage = null;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( !this.parentRemovedErrorMessage ) {
|
|
|
|
this.parentRemovedErrorMessage = this.createErrorMessage( mw.msg( 'discussiontools-error-comment-disappeared' ) );
|
|
|
|
}
|
|
|
|
// Don't show the reload prompt if there is nothing to reply to
|
|
|
|
this.updateNewCommentsWarning( [] );
|
|
|
|
};
|
|
|
|
|
2022-02-02 16:18:01 +00:00
|
|
|
/**
|
|
|
|
* Update "new comments" warning based on list of new comments found
|
|
|
|
*
|
|
|
|
* @param {Object[]} comments Array of JSON-serialized CommentItem's
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.updateNewCommentsWarning = function ( comments ) {
|
|
|
|
var widget = this;
|
|
|
|
if ( !comments.length ) {
|
|
|
|
if ( this.newCommentsWarning ) {
|
|
|
|
this.newCommentsWarning.toggle( false );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-02-08 15:47:28 +00:00
|
|
|
// Don't show the reload prompt if there is nothing to reply to
|
|
|
|
if ( this.parentRemovedErrorMessage ) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-02 16:18:01 +00:00
|
|
|
if ( !this.newCommentsWarning ) {
|
2022-05-05 17:08:24 +00:00
|
|
|
this.newCommentsShow = new OO.ui.ButtonWidget( {
|
|
|
|
flags: [ 'progressive' ]
|
2022-02-02 16:18:01 +00:00
|
|
|
} );
|
2022-05-05 17:08:24 +00:00
|
|
|
this.newCommentsClose = new OO.ui.ButtonWidget( {
|
|
|
|
icon: 'close',
|
|
|
|
label: mw.msg( 'ooui-popup-widget-close-button-aria-label' ),
|
|
|
|
invisibleLabel: true
|
2022-02-02 16:18:01 +00:00
|
|
|
} );
|
2022-05-05 17:08:24 +00:00
|
|
|
this.newCommentsWarning = new OO.ui.ButtonGroupWidget( {
|
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-newComments' ],
|
|
|
|
items: [
|
|
|
|
this.newCommentsShow,
|
|
|
|
this.newCommentsClose
|
|
|
|
]
|
2022-02-02 16:18:01 +00:00
|
|
|
} );
|
2022-05-05 17:08:24 +00:00
|
|
|
this.newCommentsShow.connect( this, { click: [ 'emit', 'reloadPage' ] } );
|
|
|
|
this.newCommentsClose.connect( this, { click: 'onNewCommentsCloseClick' } );
|
|
|
|
this.$bodyWrapper.append( this.newCommentsWarning.$element );
|
2022-02-02 16:18:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 17:08:24 +00:00
|
|
|
this.newCommentsShow.setLabel(
|
2022-07-04 15:57:35 +00:00
|
|
|
mw.msg( 'discussiontools-replywidget-newcomments-button', mw.language.convertNumber( comments.length ) )
|
2022-02-02 16:18:01 +00:00
|
|
|
);
|
2022-05-05 17:08:24 +00:00
|
|
|
if ( !this.hideNewCommentsWarning ) {
|
|
|
|
this.newCommentsWarning.toggle( true );
|
|
|
|
setTimeout( function () {
|
|
|
|
widget.newCommentsWarning.$element.addClass( 'ext-discussiontools-ui-replyWidget-newComments-open' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle click events on the new comments close button
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onNewCommentsCloseClick = function () {
|
|
|
|
this.newCommentsWarning.toggle( false );
|
|
|
|
// Hide the warning for the rest of the lifetime of the widget
|
|
|
|
this.hideNewCommentsWarning = true;
|
|
|
|
this.focus();
|
2022-02-02 16:18:01 +00:00
|
|
|
};
|
|
|
|
|
2022-02-02 21:49:26 +00:00
|
|
|
/**
|
|
|
|
* Create an error message widget and attach it to the DOM
|
|
|
|
*
|
|
|
|
* @param {string} message Message string
|
|
|
|
* @return {OO.ui.MessageWidget} Message widget
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.createErrorMessage = function ( message ) {
|
|
|
|
var errorMessage = new OO.ui.MessageWidget( {
|
|
|
|
type: 'error',
|
|
|
|
label: message,
|
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-error' ]
|
|
|
|
} );
|
|
|
|
errorMessage.$element.insertBefore( this.replyBodyWidget.$element );
|
2022-07-25 16:13:47 +00:00
|
|
|
errorMessage.scrollElementIntoView();
|
2022-02-02 21:49:26 +00:00
|
|
|
return errorMessage;
|
|
|
|
};
|
|
|
|
|
2021-12-20 15:58:01 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the reply button
|
|
|
|
*/
|
2019-12-10 21:46:22 +00:00
|
|
|
ReplyWidget.prototype.onReplyClick = function () {
|
2021-04-08 13:46:09 +00:00
|
|
|
var widget = this;
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-03-19 00:03:09 +00:00
|
|
|
if ( this.pending || this.isEmpty() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:49:26 +00:00
|
|
|
if ( this.saveErrorMessage ) {
|
|
|
|
this.saveErrorMessage.$element.remove();
|
|
|
|
this.saveErrorMessage = null;
|
2019-12-11 04:40:17 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 23:35:43 +00:00
|
|
|
this.saveInitiated = mw.now();
|
2019-11-05 14:07:50 +00:00
|
|
|
this.setPending( true );
|
2019-12-06 17:53:32 +00:00
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( { action: 'saveIntent' } );
|
|
|
|
|
2020-03-12 19:58:36 +00:00
|
|
|
// TODO: When editing a transcluded page, VE API returning the page HTML is a waste, since we won't use it
|
2021-12-20 17:06:24 +00:00
|
|
|
var pageName = this.pageName;
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
logger( { action: 'saveAttempt' } );
|
2021-12-20 17:06:24 +00:00
|
|
|
widget.commentController.save( pageName ).fail( function ( code, data ) {
|
2021-01-15 18:53:51 +00:00
|
|
|
// Compare to ve.init.mw.ArticleTargetEvents.js in VisualEditor.
|
2020-02-19 01:25:38 +00:00
|
|
|
var typeMap = {
|
2021-01-15 18:53:51 +00:00
|
|
|
badtoken: 'userBadToken',
|
|
|
|
assertanonfailed: 'userNewUser',
|
|
|
|
assertuserfailed: 'userNewUser',
|
|
|
|
assertnameduserfailed: 'userNewUser',
|
2020-02-19 01:25:38 +00:00
|
|
|
'abusefilter-disallowed': 'extensionAbuseFilter',
|
2021-01-15 18:53:51 +00:00
|
|
|
'abusefilter-warning': 'extensionAbuseFilter',
|
2020-02-19 01:25:38 +00:00
|
|
|
captcha: 'extensionCaptcha',
|
|
|
|
spamblacklist: 'extensionSpamBlacklist',
|
2021-01-15 18:53:51 +00:00
|
|
|
'titleblacklist-forbidden': 'extensionTitleBlacklist',
|
|
|
|
pagedeleted: 'editPageDeleted',
|
|
|
|
editconflict: 'editConflict'
|
2020-02-19 01:25:38 +00:00
|
|
|
};
|
|
|
|
|
2020-03-23 22:50:03 +00:00
|
|
|
if ( widget.captchaMessage ) {
|
|
|
|
widget.captchaMessage.$element.detach();
|
|
|
|
}
|
|
|
|
widget.captchaInput = undefined;
|
2020-02-19 01:25:38 +00:00
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
if ( OO.getProp( data, 'discussiontoolsedit', 'edit', 'captcha' ) ) {
|
2020-02-19 01:25:38 +00:00
|
|
|
code = 'captcha';
|
2020-03-23 22:50:03 +00:00
|
|
|
|
|
|
|
widget.captchaInput = new mw.libs.confirmEdit.CaptchaInputWidget(
|
2020-08-19 20:03:41 +00:00
|
|
|
OO.getProp( data, 'discussiontoolsedit', 'edit', 'captcha' )
|
2020-03-23 22:50:03 +00:00
|
|
|
);
|
|
|
|
// Save when pressing 'Enter' in captcha field as it is single line.
|
|
|
|
widget.captchaInput.on( 'enter', function () {
|
|
|
|
widget.onReplyClick();
|
|
|
|
} );
|
|
|
|
|
|
|
|
widget.captchaMessage = new OO.ui.MessageWidget( {
|
|
|
|
type: 'notice',
|
2020-12-11 16:27:07 +00:00
|
|
|
label: widget.captchaInput.$element,
|
2021-03-13 14:39:39 +00:00
|
|
|
classes: [ 'ext-discussiontools-ui-replyWidget-captcha' ]
|
2020-03-23 22:50:03 +00:00
|
|
|
} );
|
|
|
|
widget.captchaMessage.$element.insertAfter( widget.$preview );
|
|
|
|
|
|
|
|
widget.captchaInput.focus();
|
|
|
|
widget.captchaInput.scrollElementIntoView();
|
|
|
|
|
|
|
|
} else {
|
2022-02-08 15:47:28 +00:00
|
|
|
if ( !(
|
|
|
|
// Don't duplicate the parentRemovedErrorMessage
|
|
|
|
code === 'discussiontools-commentname-notfound' && widget.parentRemovedErrorMessage
|
|
|
|
) ) {
|
|
|
|
widget.saveErrorMessage = widget.createErrorMessage(
|
|
|
|
code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data )
|
|
|
|
);
|
|
|
|
}
|
2020-02-19 01:25:38 +00:00
|
|
|
}
|
2020-03-23 22:50:03 +00:00
|
|
|
|
2021-11-03 21:21:18 +00:00
|
|
|
if ( code instanceof Error ) {
|
|
|
|
code = 'exception';
|
|
|
|
}
|
2021-09-09 20:57:42 +00:00
|
|
|
// Log more precise error codes, mw.Api just gives us 'http' in all of these cases
|
2021-11-03 21:21:18 +00:00
|
|
|
if ( data ) {
|
|
|
|
if ( data.textStatus === 'timeout' || data.textStatus === 'abort' || data.textStatus === 'parsererror' ) {
|
|
|
|
code = data.textStatus;
|
|
|
|
} else if ( data.xhr ) {
|
|
|
|
code = 'http-' + ( data.xhr.status || 0 );
|
|
|
|
}
|
2021-09-09 20:57:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( {
|
|
|
|
action: 'saveFailure',
|
2021-09-13 23:35:43 +00:00
|
|
|
timing: mw.now() - widget.saveInitiated,
|
2020-02-19 01:25:38 +00:00
|
|
|
message: code,
|
|
|
|
type: typeMap[ code ] || 'responseUnknown'
|
|
|
|
} );
|
2019-12-06 17:53:32 +00:00
|
|
|
} ).always( function () {
|
2019-11-05 14:07:50 +00:00
|
|
|
widget.setPending( false );
|
2019-11-05 14:07:50 +00:00
|
|
|
} );
|
|
|
|
};
|
2019-12-10 21:46:22 +00:00
|
|
|
|
2020-06-01 13:45:55 +00:00
|
|
|
/**
|
|
|
|
* Handle click events on one of the scroll back buttons
|
|
|
|
*/
|
|
|
|
ReplyWidget.prototype.onScrollBackButtonClick = function () {
|
|
|
|
this.commentController.showAndFocus();
|
|
|
|
};
|
|
|
|
|
2019-12-10 21:46:22 +00:00
|
|
|
module.exports = ReplyWidget;
|