mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-09-23 18:38:18 +00:00
Support the enable2017Wikitext option
Bug: T257391 Change-Id: If2511609035c26063203512f4b860bd0060e08af
This commit is contained in:
parent
d26d8de182
commit
01ac28540a
|
@ -8,15 +8,17 @@ var
|
|||
logger = require( './logger.js' ),
|
||||
storage = mw.storage.session,
|
||||
scrollPadding = { top: 10, bottom: 10 },
|
||||
dtConf = require( './config.json' ),
|
||||
defaultEditMode = mw.user.options.get( 'discussiontools-editmode' ) || mw.config.get( 'wgDiscussionToolsFallbackEditMode' ),
|
||||
defaultVisual = defaultEditMode === 'visual',
|
||||
enable2017Wikitext = dtConf.enable2017Wikitext,
|
||||
conf = mw.config.get( 'wgVisualEditorConfig' ),
|
||||
visualModules = [ 'ext.discussionTools.ReplyWidgetVisual' ]
|
||||
.concat( conf.pluginModules.filter( mw.loader.getState ) ),
|
||||
plainModules = [ 'ext.discussionTools.ReplyWidgetPlain' ];
|
||||
|
||||
// Start loading reply widget code
|
||||
if ( defaultVisual ) {
|
||||
if ( defaultVisual || enable2017Wikitext ) {
|
||||
mw.loader.using( visualModules );
|
||||
} else {
|
||||
mw.loader.using( plainModules );
|
||||
|
@ -152,9 +154,9 @@ CommentController.prototype.setup = function ( mode, hideErrors ) {
|
|||
action: 'init',
|
||||
type: this.constructor.static.initType || 'page',
|
||||
mechanism: 'click',
|
||||
// TODO: Use 'wikitext-2017' when config.enable2017Wikitext is set
|
||||
// eslint-disable-next-line camelcase
|
||||
editor_interface: mode === 'visual' ? 'visualeditor' : 'wikitext'
|
||||
editor_interface: mode === 'visual' ? 'visualeditor' :
|
||||
( enable2017Wikitext ? 'wikitext-2017' : 'wikitext' )
|
||||
} );
|
||||
|
||||
this.$replyLinkButtons.addClass( 'dt-init-replylink-active' );
|
||||
|
@ -208,6 +210,9 @@ CommentController.prototype.getReplyWidgetClass = function ( visual ) {
|
|||
visual = defaultVisual;
|
||||
}
|
||||
|
||||
// If 2017WTE mode is enabled, always use ReplyWidgetVisual.
|
||||
visual = visual || enable2017Wikitext;
|
||||
|
||||
return mw.loader.using( visual ? visualModules : plainModules ).then( function () {
|
||||
return require( visual ? 'ext.discussionTools.ReplyWidgetVisual' : 'ext.discussionTools.ReplyWidgetPlain' );
|
||||
} );
|
||||
|
@ -216,6 +221,10 @@ CommentController.prototype.getReplyWidgetClass = function ( visual ) {
|
|||
CommentController.prototype.createReplyWidget = function ( comment, pageName, oldId, config, visual ) {
|
||||
var commentController = this;
|
||||
|
||||
if ( enable2017Wikitext ) {
|
||||
config.mode = visual ? 'visual' : 'source';
|
||||
}
|
||||
|
||||
return this.getReplyWidgetClass( visual ).then( function ( ReplyWidget ) {
|
||||
return new ReplyWidget( commentController, comment, pageName, oldId, config );
|
||||
} );
|
||||
|
@ -369,7 +378,7 @@ CommentController.prototype.switchToWikitext = function () {
|
|||
oldWidget.comment,
|
||||
oldWidget.pageName,
|
||||
oldWidget.oldId,
|
||||
{},
|
||||
{ mode: 'source' },
|
||||
false
|
||||
);
|
||||
|
||||
|
@ -492,7 +501,7 @@ CommentController.prototype.switchToVisual = function () {
|
|||
oldWidget.comment,
|
||||
oldWidget.pageName,
|
||||
oldWidget.oldId,
|
||||
{},
|
||||
{ mode: 'visual' },
|
||||
true
|
||||
);
|
||||
|
||||
|
|
|
@ -74,9 +74,11 @@ CommentTarget.prototype.attachToolbar = function () {
|
|||
};
|
||||
|
||||
CommentTarget.prototype.getSurfaceConfig = function ( config ) {
|
||||
config = ve.extendObject( { mode: this.defaultMode }, config );
|
||||
return CommentTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( {
|
||||
commandRegistry: registries.commandRegistry,
|
||||
sequenceRegistry: registries.sequenceRegistry,
|
||||
commandRegistry: config.mode === 'source' ? registries.wikitextCommandRegistry : registries.commandRegistry,
|
||||
sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry : registries.sequenceRegistry,
|
||||
dataTransferHandlerFactory: config.mode === 'source' ? ve.ui.wikitextDataTransferHandlerFactory : ve.ui.dataTransferHandlerFactory,
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
$overlayContainer: $( '#content' )
|
||||
}, config ) );
|
||||
|
|
|
@ -58,9 +58,12 @@ CommentTargetWidget.prototype.createTarget = function () {
|
|||
* @inheritdoc
|
||||
*/
|
||||
CommentTargetWidget.prototype.setDocument = function ( docOrHtml ) {
|
||||
var doc = typeof docOrHtml === 'string' ? this.target.parseDocument( docOrHtml ) : docOrHtml,
|
||||
var mode = this.target.getDefaultMode(),
|
||||
doc = ( mode === 'visual' && typeof docOrHtml === 'string' ) ?
|
||||
this.target.parseDocument( docOrHtml ) :
|
||||
docOrHtml,
|
||||
// TODO: This could be upstreamed:
|
||||
dmDoc = this.target.constructor.static.createModelFromDom( doc, this.target.getDefaultMode() );
|
||||
dmDoc = this.target.constructor.static.createModelFromDom( doc, mode );
|
||||
|
||||
// Parent method
|
||||
CommentTargetWidget.super.prototype.setDocument.call( this, dmDoc );
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
|
||||
*/
|
||||
|
||||
var controller = require( 'ext.discussionTools.init' ).controller;
|
||||
var openCommand, insertAndOpenCommand, sequence,
|
||||
controller = require( 'ext.discussionTools.init' ).controller;
|
||||
|
||||
/**
|
||||
* MWUsernameCompletionAction action.
|
||||
|
@ -156,23 +157,20 @@ MWUsernameCompletionAction.prototype.shouldAbandon = function ( input ) {
|
|||
|
||||
ve.ui.actionFactory.register( MWUsernameCompletionAction );
|
||||
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
openCommand = new ve.ui.Command(
|
||||
'openMWUsernameCompletions', MWUsernameCompletionAction.static.name, 'open',
|
||||
{ supportedSelections: [ 'linear' ] }
|
||||
)
|
||||
);
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
insertAndOpenCommand = new ve.ui.Command(
|
||||
'insertAndOpenMWUsernameCompletions', MWUsernameCompletionAction.static.name, 'insertAndOpen',
|
||||
{ supportedSelections: [ 'linear' ] }
|
||||
)
|
||||
);
|
||||
ve.ui.sequenceRegistry.register(
|
||||
new ve.ui.Sequence( 'autocompleteMWUsernames', 'openMWUsernameCompletions', '@', 0 )
|
||||
);
|
||||
ve.ui.wikitextSequenceRegistry.register(
|
||||
new ve.ui.Sequence( 'autocompleteMWUsernamesWikitext', 'openMWUsernameCompletions', '@', 0 )
|
||||
);
|
||||
sequence = new ve.ui.Sequence( 'autocompleteMWUsernames', 'openMWUsernameCompletions', '@', 0 );
|
||||
ve.ui.commandRegistry.register( openCommand );
|
||||
ve.ui.commandRegistry.register( insertAndOpenCommand );
|
||||
ve.ui.wikitextCommandRegistry.register( openCommand );
|
||||
ve.ui.wikitextCommandRegistry.register( insertAndOpenCommand );
|
||||
ve.ui.sequenceRegistry.register( sequence );
|
||||
ve.ui.wikitextSequenceRegistry.register( sequence );
|
||||
|
||||
module.exports = MWUsernameCompletionAction;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var commandRegistry, sequenceRegistry;
|
||||
var commandRegistry, sequenceRegistry,
|
||||
wikitextCommandRegistry, wikitextSequenceRegistry;
|
||||
|
||||
// Adapted from ve.ui.MWWikitextDataTransferHandlerFactory
|
||||
function importRegistry( parent, child ) {
|
||||
|
@ -20,10 +21,18 @@ importRegistry( ve.ui.commandRegistry, commandRegistry );
|
|||
sequenceRegistry = new ve.ui.SequenceRegistry();
|
||||
importRegistry( ve.ui.sequenceRegistry, sequenceRegistry );
|
||||
|
||||
wikitextCommandRegistry = new ve.ui.CommandRegistry();
|
||||
importRegistry( ve.ui.wikitextCommandRegistry, wikitextCommandRegistry );
|
||||
wikitextSequenceRegistry = new ve.ui.SequenceRegistry();
|
||||
importRegistry( ve.ui.wikitextSequenceRegistry, wikitextSequenceRegistry );
|
||||
|
||||
// Disable find-and-replace (T263570)
|
||||
commandRegistry.unregister( 'findAndReplace' );
|
||||
commandRegistry.unregister( 'findNext' );
|
||||
commandRegistry.unregister( 'findPrevious' );
|
||||
wikitextCommandRegistry.unregister( 'findAndReplace' );
|
||||
wikitextCommandRegistry.unregister( 'findNext' );
|
||||
wikitextCommandRegistry.unregister( 'findPrevious' );
|
||||
|
||||
// Command to insert signature node. Unlike normal VisualEditor, we want to select
|
||||
// the node (collapseToEnd=false), because we want to show its context menu.
|
||||
|
@ -49,6 +58,8 @@ sequenceRegistry.register(
|
|||
new ve.ui.Sequence( 'dtWikitextSignature', 'dtMwSignature', '~~~~', 4 )
|
||||
);
|
||||
|
||||
// TODO: Show a warning when typing ~~~~ in wikitext mode?
|
||||
|
||||
// Show wikitext warnings for disabled sequences (disabled via excludeCommand):
|
||||
|
||||
// insertTable
|
||||
|
@ -72,5 +83,7 @@ sequenceRegistry.register(
|
|||
|
||||
module.exports = {
|
||||
commandRegistry: commandRegistry,
|
||||
sequenceRegistry: sequenceRegistry
|
||||
sequenceRegistry: sequenceRegistry,
|
||||
wikitextCommandRegistry: wikitextCommandRegistry,
|
||||
wikitextSequenceRegistry: wikitextSequenceRegistry
|
||||
};
|
||||
|
|
|
@ -562,7 +562,7 @@ ReplyWidget.prototype.preparePreview = function ( wikitext ) {
|
|||
// ol: '#'
|
||||
// }[ this.context ];
|
||||
indent = ':';
|
||||
wikitext = wikitext || this.getValue();
|
||||
wikitext = wikitext !== undefined ? wikitext : this.getValue();
|
||||
title = this.isNewTopic && this.commentController.sectionTitle.getValue();
|
||||
|
||||
if ( this.previewWikitext === wikitext && this.previewTitle === title ) {
|
||||
|
|
|
@ -25,9 +25,8 @@ require( './dt-ve/dt.ce.PingNode.js' );
|
|||
* @param {number} oldId
|
||||
* @param {Object} [config]
|
||||
*/
|
||||
function ReplyWidgetVisual() {
|
||||
// TODO: Support 2017 wikitext editor
|
||||
this.defaultMode = 'visual';
|
||||
function ReplyWidgetVisual( commentController, comment, pageName, oldId, config ) {
|
||||
this.defaultMode = config.mode;
|
||||
|
||||
// Parent constructor
|
||||
ReplyWidgetVisual.super.apply( this, arguments );
|
||||
|
@ -87,7 +86,7 @@ ReplyWidgetVisual.prototype.setup = function ( data ) {
|
|||
htmlOrDoc = this.storage.get( this.storagePrefix + '/ve-dochtml' );
|
||||
target.recovered = true;
|
||||
} else {
|
||||
htmlOrDoc = data.value || '<p></p>';
|
||||
htmlOrDoc = data.value || ( this.getMode() === 'visual' ? '<p></p>' : '' );
|
||||
}
|
||||
|
||||
target.originalHtml = htmlOrDoc instanceof HTMLDocument ? ve.properInnerHtml( htmlOrDoc.body ) : htmlOrDoc;
|
||||
|
|
Loading…
Reference in a new issue