2020-04-08 18:23:22 +00:00
|
|
|
// Adapted from ve.ui.MWWikitextDataTransferHandlerFactory
|
|
|
|
function importRegistry( parent, child ) {
|
|
|
|
var name;
|
|
|
|
// Copy existing items
|
|
|
|
for ( name in parent.registry ) {
|
|
|
|
child.register( parent.registry[ name ] );
|
|
|
|
}
|
|
|
|
// Copy any new items when they're added
|
2020-08-26 22:46:34 +00:00
|
|
|
parent.on( 'register', function ( n, data ) {
|
2020-04-08 18:23:22 +00:00
|
|
|
child.register( data );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new registries so that we can override the behavior for signatures
|
|
|
|
// without affecting normal VisualEditor.
|
2021-04-08 13:46:09 +00:00
|
|
|
var commandRegistry = new ve.ui.CommandRegistry();
|
2020-04-08 18:23:22 +00:00
|
|
|
importRegistry( ve.ui.commandRegistry, commandRegistry );
|
2021-04-08 13:46:09 +00:00
|
|
|
var sequenceRegistry = new ve.ui.SequenceRegistry();
|
2020-04-08 18:23:22 +00:00
|
|
|
importRegistry( ve.ui.sequenceRegistry, sequenceRegistry );
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var wikitextCommandRegistry = new ve.ui.MWWikitextCommandRegistry( commandRegistry );
|
2020-09-21 20:13:35 +00:00
|
|
|
importRegistry( ve.ui.wikitextCommandRegistry, wikitextCommandRegistry );
|
2021-04-08 13:46:09 +00:00
|
|
|
var wikitextSequenceRegistry = new ve.ui.SequenceRegistry();
|
2020-09-21 20:13:35 +00:00
|
|
|
importRegistry( ve.ui.wikitextSequenceRegistry, wikitextSequenceRegistry );
|
|
|
|
|
2020-09-25 14:17:15 +00:00
|
|
|
// Disable find-and-replace (T263570)
|
|
|
|
commandRegistry.unregister( 'findAndReplace' );
|
|
|
|
commandRegistry.unregister( 'findNext' );
|
|
|
|
commandRegistry.unregister( 'findPrevious' );
|
2020-09-21 20:13:35 +00:00
|
|
|
wikitextCommandRegistry.unregister( 'findAndReplace' );
|
|
|
|
wikitextCommandRegistry.unregister( 'findNext' );
|
|
|
|
wikitextCommandRegistry.unregister( 'findPrevious' );
|
2020-09-25 14:17:15 +00:00
|
|
|
|
2020-04-08 18:23:22 +00:00
|
|
|
// Command to insert signature node. Unlike normal VisualEditor, we want to select
|
|
|
|
// the node (collapseToEnd=false), because we want to show its context menu.
|
|
|
|
commandRegistry.unregister( 'mwSignature' );
|
|
|
|
commandRegistry.register(
|
|
|
|
new ve.ui.Command( 'dtMwSignature', 'content', 'insert', {
|
|
|
|
args: [
|
|
|
|
[
|
|
|
|
{ type: 'dtMwSignature' },
|
|
|
|
{ type: '/dtMwSignature' }
|
|
|
|
],
|
|
|
|
// annotate
|
|
|
|
false,
|
|
|
|
// collapseToEnd
|
|
|
|
false
|
|
|
|
],
|
|
|
|
supportedSelections: [ 'linear' ]
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
// Unlike normal VisualEditor, this is registered regardless of the namespace.
|
|
|
|
sequenceRegistry.unregister( 'wikitextSignature' );
|
|
|
|
sequenceRegistry.register(
|
|
|
|
new ve.ui.Sequence( 'dtWikitextSignature', 'dtMwSignature', '~~~~', 4 )
|
|
|
|
);
|
|
|
|
|
2020-09-21 20:13:35 +00:00
|
|
|
// TODO: Show a warning when typing ~~~~ in wikitext mode?
|
|
|
|
|
2022-07-30 23:57:22 +00:00
|
|
|
// Show wikitext warnings for disabled sequences (disabled via excludeCommands):
|
|
|
|
var sequenceRegistryForReplyTool = new ve.ui.SequenceRegistry();
|
|
|
|
importRegistry( sequenceRegistry, sequenceRegistryForReplyTool );
|
2021-02-16 19:08:39 +00:00
|
|
|
|
|
|
|
// insertTable
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistryForReplyTool.unregister( 'wikitextTable' );
|
|
|
|
sequenceRegistryForReplyTool.register(
|
|
|
|
new ve.ui.Sequence( 'wikitextTableWarning', 'mwWikitextWarning', '{|' )
|
2021-02-16 19:08:39 +00:00
|
|
|
);
|
2021-06-17 20:24:31 +00:00
|
|
|
|
2021-02-16 19:08:39 +00:00
|
|
|
// transclusionFromSequence
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistryForReplyTool.unregister( 'wikitextTemplate' );
|
|
|
|
sequenceRegistryForReplyTool.register(
|
|
|
|
new ve.ui.Sequence( 'wikitextTemplateWarning', 'mwWikitextWarning', '{{' )
|
2021-02-16 19:08:39 +00:00
|
|
|
);
|
2021-06-17 20:24:31 +00:00
|
|
|
|
2022-07-30 23:57:22 +00:00
|
|
|
// blockquoteWrap - note, this one applies to `sequenceRegistry` as well
|
|
|
|
sequenceRegistry.unregister( 'wikitextDescription' );
|
2021-02-16 19:08:39 +00:00
|
|
|
sequenceRegistry.register(
|
2022-07-30 23:57:22 +00:00
|
|
|
new ve.ui.Sequence( 'wikitextDescriptionWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, ':' ] )
|
2021-02-16 19:08:39 +00:00
|
|
|
);
|
2021-06-17 20:24:31 +00:00
|
|
|
|
2021-02-16 19:08:39 +00:00
|
|
|
// heading1-6
|
|
|
|
// This sequence doesn't usually have a command as we don't know what
|
|
|
|
// heading level is required, but for warnings this doesn't matter.
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistryForReplyTool.unregister( 'wikitextHeading' );
|
|
|
|
sequenceRegistryForReplyTool.register(
|
|
|
|
new ve.ui.Sequence( 'wikitextHeadingWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, '=', '=' ] )
|
2021-02-16 19:08:39 +00:00
|
|
|
);
|
|
|
|
|
2021-06-17 20:30:07 +00:00
|
|
|
// horizontal rule
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistryForReplyTool.unregister( 'horizontalRule' );
|
|
|
|
sequenceRegistryForReplyTool.register(
|
|
|
|
new ve.ui.Sequence( 'horizontalRuleWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, '-', '-', '-', '-' ] )
|
2021-06-17 20:30:07 +00:00
|
|
|
);
|
|
|
|
|
2020-04-08 18:23:22 +00:00
|
|
|
module.exports = {
|
|
|
|
commandRegistry: commandRegistry,
|
2020-09-21 20:13:35 +00:00
|
|
|
sequenceRegistry: sequenceRegistry,
|
2022-07-30 23:57:22 +00:00
|
|
|
sequenceRegistryForReplyTool: sequenceRegistryForReplyTool,
|
2020-09-21 20:13:35 +00:00
|
|
|
wikitextCommandRegistry: wikitextCommandRegistry,
|
|
|
|
wikitextSequenceRegistry: wikitextSequenceRegistry
|
2020-04-08 18:23:22 +00:00
|
|
|
};
|