Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js

raw symbols SCIP
1 /*!
2 * VisualEditor MediaWiki UserInterface signature tool class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * MediaWiki UserInterface signature tool. This defines the menu button and its action.
10 *
11 * @class
12 * @extends ve.ui.MWTransclusionDialogTool
13 * @constructor
14 * @param {OO.ui.ToolGroup} toolGroup
15 * @param {Object} [config] Configuration options
16 */
17 ve.ui.MWSignatureTool = function VeUiMWSignatureTool() {
18 // Parent constructor
19 ve.ui.MWSignatureTool.super.apply( this, arguments );
20 };
21 OO.inheritClass( ve.ui.MWSignatureTool, ve.ui.MWTransclusionDialogTool );
22
23 ve.ui.MWSignatureTool.static.name = 'mwSignature';
24 ve.ui.MWSignatureTool.static.group = 'object';
25 ve.ui.MWSignatureTool.static.icon = 'signature';
26 ve.ui.MWSignatureTool.static.title =
27 OO.ui.deferMsg( 'visualeditor-mwsignature-tool' );
28 ve.ui.MWSignatureTool.static.modelClasses = [ ve.dm.MWSignatureNode ];
29 // Link the tool to the command defined below
30 ve.ui.MWSignatureTool.static.commandName = 'mwSignature';
31
32 ve.ui.toolFactory.register( ve.ui.MWSignatureTool );
33
34 // Commands and sequences are only registered on supported namespaces.
35 // On other namespaces the tool is still shown, but disabled.
36 if ( mw.Title.wantSignaturesNamespace( mw.config.get( 'wgNamespaceNumber' ) ) ) {
37 // Command to insert signature node.
38 ve.ui.commandRegistry.register(
39 new ve.ui.Command( 'mwSignature', 'content', 'insert', {
40 args: [
41 [
42 { type: 'mwSignature' },
43 { type: '/mwSignature' }
44 ],
45 // annotate
46 false,
47 // collapseToEnd
48 true
49 ],
50 supportedSelections: [ 'linear' ]
51 } )
52 );
53 ve.ui.sequenceRegistry.register(
54 new ve.ui.Sequence( 'wikitextSignature', 'mwSignature', '~~~~', 4 )
55 );
56 ve.ui.commandHelpRegistry.register( 'insert', 'mwSignature', {
57 sequences: [ 'wikitextSignature' ],
58 label: OO.ui.deferMsg( 'visualeditor-mwsignature-tool' )
59 } );
60 if ( mw.libs.ve.isWikitextAvailable ) {
61 // Ensure wikitextCommandRegistry has finished loading
62 mw.loader.using( 'ext.visualEditor.mwwikitext' ).then( () => {
63 ve.ui.wikitextCommandRegistry.register(
64 new ve.ui.Command( 'mwSignature', 'content', 'insert', {
65 args: [ '~~~~', false, true /* collaseToEnd */ ],
66 supportedSelections: [ 'linear' ]
67 } )
68 );
69 } );
70 }
71 } else {
72 // No-op command that is never executable
73 ve.ui.commandRegistry.register(
74 new ve.ui.Command( 'mwSignature', 'content', 'insert', {
75 args: [ [] ],
76 supportedSelections: []
77 } )
78 );
79 // Wikitext insertion warning
80 ve.ui.sequenceRegistry.register(
81 new ve.ui.Sequence( 'wikitextSignature', 'mwWikitextWarning', '~~~' )
82 );
83 }