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,
|
2020-02-25 02:10:27 +00:00
|
|
|
logger = require( 'ext.discussionTools.init' ).logger;
|
2019-12-10 21:46:22 +00:00
|
|
|
|
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-03-12 19:58:36 +00:00
|
|
|
* @param {Object} parsoidData Result from controller#getParsoidCommentData
|
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
|
|
|
*/
|
2020-03-12 19:58:36 +00:00
|
|
|
function ReplyWidget( parsoidData, config ) {
|
2020-03-04 16:19:19 +00:00
|
|
|
var returnTo, contextNode, inputConfig,
|
|
|
|
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;
|
2020-03-12 19:58:36 +00:00
|
|
|
this.comment = parsoidData.comment;
|
|
|
|
this.pageData = parsoidData.pageData;
|
2020-03-08 14:32:38 +00:00
|
|
|
contextNode = utils.closestElement( this.comment.range.endContainer, [ 'dl', 'ul', 'ol' ] );
|
2019-11-20 20:27:08 +00:00
|
|
|
this.context = contextNode ? contextNode.nodeName.toLowerCase() : 'dl';
|
2020-04-10 12:57:51 +00:00
|
|
|
// TODO: Should storagePrefix include pageName?
|
|
|
|
this.storagePrefix = 'reply/' + this.comment.id;
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-02-25 17:57:23 +00:00
|
|
|
inputConfig = $.extend(
|
2020-03-12 19:58:36 +00:00
|
|
|
{ placeholder: mw.msg( 'discussiontools-replywidget-placeholder-reply', this.comment.author ) },
|
2020-02-25 17:57:23 +00:00
|
|
|
config.input
|
|
|
|
);
|
|
|
|
this.replyBodyWidget = this.createReplyBodyWidget( inputConfig );
|
2019-11-05 14:07:50 +00:00
|
|
|
this.replyButton = new OO.ui.ButtonWidget( {
|
|
|
|
flags: [ 'primary', 'progressive' ],
|
2019-12-06 18:43:46 +00:00
|
|
|
label: mw.msg( 'discussiontools-replywidget-reply' )
|
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' ),
|
|
|
|
framed: false
|
2019-11-05 14:07:50 +00:00
|
|
|
} );
|
|
|
|
|
2020-02-03 20:34:13 +00:00
|
|
|
this.$preview = $( '<div>' ).addClass( 'dt-ui-replyWidget-preview' ).attr( 'data-label', mw.msg( 'discussiontools-replywidget-preview' ) );
|
|
|
|
this.$actionsWrapper = $( '<div>' ).addClass( 'dt-ui-replyWidget-actionsWrapper' );
|
|
|
|
this.$actions = $( '<div>' ).addClass( 'dt-ui-replyWidget-actions' ).append(
|
|
|
|
this.cancelButton.$element,
|
|
|
|
this.replyButton.$element
|
|
|
|
);
|
2020-03-12 19:58:36 +00:00
|
|
|
this.$footer = $( '<div>' ).addClass( 'dt-ui-replyWidget-footer' );
|
|
|
|
if ( this.pageData.pageName !== mw.config.get( 'wgRelevantPageName' ) ) {
|
|
|
|
this.$footer.append( $( '<p>' ).append(
|
|
|
|
mw.message( 'discussiontools-replywidget-transcluded', this.pageData.pageName ).parseDom()
|
|
|
|
) );
|
|
|
|
}
|
2020-04-07 14:33:32 +00:00
|
|
|
this.$footer.append(
|
|
|
|
$( '<p>' ).append(
|
|
|
|
mw.message( 'discussiontools-replywidget-terms-click', mw.msg( 'discussiontools-replywidget-reply' ) ).parseDom()
|
|
|
|
),
|
|
|
|
$( '<p>' ).append(
|
|
|
|
$( '<a>' )
|
|
|
|
.attr( {
|
|
|
|
href: mw.msg( 'discussiontools-replywidget-feedback-link' ),
|
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
|
|
|
} )
|
|
|
|
.text( mw.msg( 'discussiontools-replywidget-feedback' ) )
|
|
|
|
)
|
|
|
|
);
|
2020-03-12 19:58:36 +00:00
|
|
|
this.$actionsWrapper.append( this.$footer, this.$actions );
|
2019-11-20 20:27:08 +00:00
|
|
|
|
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' } );
|
2019-11-05 14:07:50 +00:00
|
|
|
this.$element.on( 'keydown', this.onKeyDown.bind( this ) );
|
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 );
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2019-11-20 20:27:08 +00:00
|
|
|
this.api = new mw.Api();
|
|
|
|
this.onInputChangeThrottled = OO.ui.throttle( this.onInputChange.bind( this ), 1000 );
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 'dt-ui-replyWidget' ).append(
|
2019-11-05 14:07:50 +00:00
|
|
|
this.replyBodyWidget.$element,
|
2020-02-03 20:34:13 +00:00
|
|
|
this.$preview,
|
|
|
|
this.$actionsWrapper
|
2019-11-05 14:07:50 +00:00
|
|
|
);
|
2019-11-19 19:33:14 +00:00
|
|
|
|
|
|
|
if ( mw.user.isAnon() ) {
|
|
|
|
returnTo = {
|
|
|
|
returntoquery: encodeURIComponent( window.location.search ),
|
|
|
|
returnto: mw.config.get( 'wgPageName' )
|
|
|
|
};
|
2020-02-03 20:34:13 +00:00
|
|
|
this.anonWarning = new OO.ui.MessageWidget( {
|
|
|
|
classes: [ 'dt-ui-replyWidget-anonWarning' ],
|
|
|
|
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 );
|
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-03-04 16:19:19 +00:00
|
|
|
this.checkboxesPromise = controller.getCheckboxesPromise( this.pageData );
|
|
|
|
this.checkboxesPromise.then( function ( checkboxes ) {
|
|
|
|
if ( checkboxes.checkboxFields ) {
|
|
|
|
widget.$checkboxes = $( '<div>' ).addClass( 'dt-ui-replyWidget-checkboxes' );
|
|
|
|
checkboxes.checkboxFields.forEach( function ( field ) {
|
|
|
|
widget.$checkboxes.append( field.$element );
|
|
|
|
} );
|
|
|
|
widget.$actions.prepend( widget.$checkboxes );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-04-10 12:57:51 +00:00
|
|
|
this.initAutoSave();
|
|
|
|
|
2020-02-29 02:58:28 +00:00
|
|
|
// Init preview and button state
|
|
|
|
this.onInputChange();
|
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 */
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
ReplyWidget.prototype.createReplyBodyWidget = null;
|
|
|
|
|
|
|
|
ReplyWidget.prototype.focus = null;
|
|
|
|
|
|
|
|
ReplyWidget.prototype.getValue = null;
|
|
|
|
|
|
|
|
ReplyWidget.prototype.isEmpty = null;
|
|
|
|
|
2020-04-02 15:43:49 +00:00
|
|
|
ReplyWidget.prototype.getMode = null;
|
2020-03-06 15:18:30 +00:00
|
|
|
|
2020-04-10 12:57:51 +00:00
|
|
|
ReplyWidget.prototype.initAutoSave = null;
|
|
|
|
|
2019-12-11 04:40:17 +00:00
|
|
|
ReplyWidget.prototype.clear = function () {
|
|
|
|
if ( this.errorMessage ) {
|
|
|
|
this.errorMessage.$element.remove();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
} else {
|
|
|
|
this.replyButton.setDisabled( false );
|
|
|
|
this.cancelButton.setDisabled( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-10 15:15:40 +00:00
|
|
|
ReplyWidget.prototype.setup = function () {
|
|
|
|
this.bindBeforeUnloadHandler();
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
if ( !this.isEmpty() ) {
|
2019-12-10 15:40:52 +00:00
|
|
|
// TODO: Override messages in dialog to be more ReplyWidget specific
|
|
|
|
promise = OO.ui.getWindowManager().openWindow( 'abandonedit' )
|
|
|
|
.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
|
|
|
}
|
|
|
|
promise.then( function () {
|
2020-01-13 19:29:07 +00:00
|
|
|
widget.teardown();
|
2019-12-10 15:40:52 +00:00
|
|
|
} );
|
2019-12-10 15:15:40 +00:00
|
|
|
};
|
|
|
|
|
2020-01-13 19:29:07 +00:00
|
|
|
ReplyWidget.prototype.teardown = function () {
|
|
|
|
this.unbindBeforeUnloadHandler();
|
|
|
|
this.clear();
|
|
|
|
this.$preview.empty();
|
|
|
|
this.emit( 'teardown' );
|
|
|
|
};
|
|
|
|
|
2019-12-10 21:46:22 +00:00
|
|
|
ReplyWidget.prototype.onKeyDown = function ( 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-20 20:27:08 +00:00
|
|
|
ReplyWidget.prototype.onInputChange = function () {
|
|
|
|
var wikitext, parsePromise,
|
|
|
|
widget = this,
|
|
|
|
indent = {
|
|
|
|
dl: ':',
|
|
|
|
ul: '*',
|
|
|
|
ol: '#'
|
|
|
|
}[ this.context ];
|
2019-11-05 14:07:50 +00:00
|
|
|
|
2020-02-29 02:58:28 +00:00
|
|
|
this.replyButton.setDisabled( this.isEmpty() );
|
|
|
|
|
2020-04-02 15:43:49 +00:00
|
|
|
if ( this.getMode() !== 'source' ) {
|
2019-11-05 14:07:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-20 20:27:08 +00:00
|
|
|
|
|
|
|
if ( this.previewRequest ) {
|
|
|
|
this.previewRequest.abort();
|
|
|
|
this.previewRequest = null;
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:07:50 +00:00
|
|
|
wikitext = this.getValue();
|
2019-11-20 20:27:08 +00:00
|
|
|
if ( !wikitext.trim() ) {
|
2020-01-02 14:59:50 +00:00
|
|
|
parsePromise = $.Deferred().resolve( null ).promise();
|
2019-11-20 20:27:08 +00:00
|
|
|
} else {
|
2020-04-09 19:26:15 +00:00
|
|
|
wikitext = controller.sanitizeWikitextLinebreaks(
|
|
|
|
controller.autoSignWikitext( wikitext )
|
|
|
|
);
|
2020-02-18 15:43:06 +00:00
|
|
|
wikitext = wikitext.slice( 0, -4 ) + '<span style="opacity: 0.6;">~~~~</span>';
|
2019-11-20 20:27:08 +00:00
|
|
|
wikitext = indent + wikitext.replace( /\n/g, '\n' + indent );
|
2020-01-02 14:59:50 +00:00
|
|
|
this.previewRequest = parsePromise = this.api.post( {
|
|
|
|
formatversion: 2,
|
|
|
|
action: 'parse',
|
|
|
|
text: wikitext,
|
2019-12-27 18:30:24 +00:00
|
|
|
pst: true,
|
2020-03-09 13:04:43 +00:00
|
|
|
prop: [ 'text', 'modules', 'jsconfigvars' ],
|
2019-12-27 18:30:24 +00:00
|
|
|
title: mw.config.get( 'wgPageName' )
|
|
|
|
} );
|
2019-11-20 20:27:08 +00:00
|
|
|
}
|
|
|
|
// TODO: Add list context
|
|
|
|
|
2020-01-02 14:59:50 +00:00
|
|
|
parsePromise.then( function ( response ) {
|
|
|
|
widget.$preview.html( response ? response.parse.text : '' );
|
2019-11-20 20:27:08 +00:00
|
|
|
|
2020-01-02 14:59:50 +00:00
|
|
|
if ( response ) {
|
2020-03-09 13:04:43 +00:00
|
|
|
mw.config.set( response.parse.jsconfigvars );
|
2020-01-02 14:59:50 +00:00
|
|
|
mw.loader.load( response.parse.modulestyles );
|
|
|
|
mw.loader.load( response.parse.modules );
|
|
|
|
}
|
2019-11-20 20:27:08 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
ReplyWidget.prototype.onFirstTransaction = function () {
|
|
|
|
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'
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2019-12-10 21:46:22 +00:00
|
|
|
ReplyWidget.prototype.onReplyClick = function () {
|
2020-02-15 04:03:18 +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;
|
|
|
|
}
|
|
|
|
|
2019-12-11 04:40:17 +00:00
|
|
|
if ( this.errorMessage ) {
|
|
|
|
this.errorMessage.$element.remove();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2020-02-15 04:03:18 +00:00
|
|
|
// We must get a new copy of the document every time, otherwise any unsaved replies will pile up
|
2020-03-12 19:58:36 +00:00
|
|
|
controller.getParsoidCommentData( this.pageData.pageName, this.pageData.oldId, this.comment.id ).then( function ( parsoidData ) {
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( { action: 'saveAttempt' } );
|
2020-03-06 15:18:30 +00:00
|
|
|
return controller.save( widget, parsoidData );
|
2019-11-13 13:57:57 +00:00
|
|
|
} ).then( function ( data ) {
|
2020-03-12 19:58:36 +00:00
|
|
|
var
|
|
|
|
pageUpdated = $.Deferred(),
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$container = $( '#mw-content-text' );
|
2019-11-13 13:57:57 +00:00
|
|
|
|
2020-01-15 16:21:59 +00:00
|
|
|
widget.teardown();
|
|
|
|
// TODO: Tell controller to teardown all other open widgets
|
|
|
|
|
2019-11-13 13:57:57 +00:00
|
|
|
// Update page state
|
2020-03-12 19:58:36 +00:00
|
|
|
if ( widget.pageData.pageName === mw.config.get( 'wgRelevantPageName' ) ) {
|
|
|
|
// We can use the result from the VisualEditor API
|
|
|
|
$container.html( data.content );
|
|
|
|
mw.config.set( {
|
|
|
|
wgCurRevisionId: data.newrevid,
|
|
|
|
wgRevisionId: data.newrevid
|
|
|
|
} );
|
|
|
|
mw.config.set( data.jsconfigvars );
|
|
|
|
// Note: VE API merges 'modules' and 'modulestyles'
|
|
|
|
mw.loader.load( data.modules );
|
|
|
|
// TODO update categories, displaytitle, lastmodified
|
|
|
|
// (see ve.init.mw.DesktopArticleTarget.prototype.replacePageContent)
|
|
|
|
|
|
|
|
pageUpdated.resolve();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// We saved to another page, we must purge and then fetch the current page
|
|
|
|
widget.api.post( {
|
|
|
|
action: 'purge',
|
|
|
|
titles: mw.config.get( 'wgRelevantPageName' )
|
|
|
|
} ).then( function () {
|
|
|
|
return widget.api.get( {
|
|
|
|
formatversion: 2,
|
|
|
|
action: 'parse',
|
|
|
|
prop: [ 'text', 'modules', 'jsconfigvars' ],
|
|
|
|
page: mw.config.get( 'wgRelevantPageName' )
|
|
|
|
} );
|
|
|
|
} ).then( function ( parseResp ) {
|
|
|
|
$container.html( parseResp.parse.text );
|
|
|
|
mw.config.set( parseResp.parse.jsconfigvars );
|
|
|
|
mw.loader.load( parseResp.parse.modulestyles );
|
|
|
|
mw.loader.load( parseResp.parse.modules );
|
|
|
|
// TODO update categories, displaytitle, lastmodified
|
|
|
|
// We may not be able to use prop=displaytitle without making changes in the action=parse API,
|
|
|
|
// VE API has some confusing code that changes the HTML escaping on it before returning???
|
|
|
|
|
|
|
|
pageUpdated.resolve();
|
|
|
|
|
|
|
|
} ).catch( function () {
|
|
|
|
// We saved the reply, but couldn't purge or fetch the updated page. Seems difficult to
|
|
|
|
// explain this problem. Redirect to the page where the user can at least see their reply…
|
|
|
|
window.location = mw.util.getUrl( widget.pageData.pageName );
|
|
|
|
} );
|
|
|
|
}
|
2020-02-19 01:25:38 +00:00
|
|
|
|
2020-03-12 19:58:36 +00:00
|
|
|
pageUpdated.then( function () {
|
|
|
|
// Re-initialize
|
|
|
|
controller.init( $container.find( '.mw-parser-output' ), {
|
|
|
|
repliedTo: widget.comment.id
|
|
|
|
} );
|
|
|
|
mw.hook( 'wikipage.content' ).fire( $container );
|
|
|
|
|
|
|
|
logger( {
|
|
|
|
action: 'saveSuccess',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
revision_id: data.newrevid
|
|
|
|
} );
|
2020-02-19 01:25:38 +00:00
|
|
|
} );
|
2020-03-12 19:58:36 +00:00
|
|
|
|
2019-12-11 04:40:17 +00:00
|
|
|
}, function ( code, data ) {
|
2020-02-19 01:25:38 +00:00
|
|
|
var typeMap = {
|
|
|
|
// Compare to ve.init.mw.ArticleTargetEvents.js in VisualEditor.
|
|
|
|
editconflict: 'editConflict',
|
|
|
|
wasdeleted: 'editPageDeleted',
|
|
|
|
abusefilter: 'extensionAbuseFilter',
|
|
|
|
'abusefilter-disallowed': 'extensionAbuseFilter',
|
|
|
|
captcha: 'extensionCaptcha',
|
|
|
|
spamprotectiontext: 'extensionSpamBlacklist',
|
|
|
|
titleblacklist: 'extensionTitleBlacklist',
|
|
|
|
'titleblacklist-forbidden-edit': 'extensionTitleBlacklist',
|
|
|
|
badtoken: 'userBadToken',
|
|
|
|
newuser: 'userNewUser',
|
|
|
|
spamblacklist: 'extensionSpamBlacklist',
|
|
|
|
empty: 'responseEmpty',
|
|
|
|
unknown: 'responseUnknown',
|
|
|
|
pagedeleted: 'editPageDeleted'
|
|
|
|
};
|
|
|
|
|
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-03-23 22:50:03 +00:00
|
|
|
if ( OO.getProp( data, 'visualeditoredit', '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(
|
|
|
|
OO.getProp( data, 'visualeditoredit', 'edit', 'captcha' )
|
|
|
|
);
|
|
|
|
// 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',
|
|
|
|
label: widget.captchaInput.$element
|
|
|
|
} );
|
|
|
|
widget.captchaMessage.$element.insertAfter( widget.$preview );
|
|
|
|
|
|
|
|
widget.captchaInput.focus();
|
|
|
|
widget.captchaInput.scrollElementIntoView();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
widget.errorMessage = new OO.ui.MessageWidget( {
|
|
|
|
type: 'error',
|
|
|
|
label: widget.api.getErrorMessage( data )
|
|
|
|
} );
|
|
|
|
widget.errorMessage.$element.insertBefore( widget.replyBodyWidget.$element );
|
2020-02-19 01:25:38 +00:00
|
|
|
}
|
2020-03-23 22:50:03 +00:00
|
|
|
|
2020-02-19 01:25:38 +00:00
|
|
|
logger( {
|
|
|
|
action: 'saveFailure',
|
|
|
|
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
|
|
|
|
2019-12-10 15:40:52 +00:00
|
|
|
/* Window registration */
|
|
|
|
|
|
|
|
OO.ui.getWindowManager().addWindows( [ new mw.widgets.AbandonEditDialog() ] );
|
|
|
|
|
2019-12-10 21:46:22 +00:00
|
|
|
module.exports = ReplyWidget;
|