mediawiki-extensions-Visual.../modules/ve-mw/ui/tools/ve.ui.MWSignatureTool.js
Bartosz Dziewoński 9be5c85db4 Provide a tool to insert a signature in namespaces that need it
VisualEditor is usually not enabled in talk namespaces... but
sometimes it is. And when users see the button to edit with VE,
they're going to click it and expect to be able to sign their posts.

This tool is only loaded on talk pages and pages in additional
namespaces defined in $wgExtraSignatureNamespaces.

Code adapted with small tweaks from my own gadget
<https://meta.wikimedia.org/wiki/User:Matma_Rex/visualeditor-signature.js?oldid=13461327>,
which is already available under the MIT license.

Changes include:
* The tool is now always visible if the wiki allows signatures in any
  VE namespaces, but disabled when not allowed in the current namespace.
* Register '~~~~' sequence to insert the signature.
* Code style tweaks for stricter lint checks in this repository.
* Documentation corrections.

Swedish translation provided by André Costa (already credited
as a translator as Lokal_Profil).

Depends on changes in VisualEditor core:
* I89fe53890ab59d12260ea6b41de802c38c24e8b9
* I14cd7efac521687ea38580341ae08ddc522edeeb

Bug: T53154
Change-Id: I6be5fb2118cf3eef5098d4c5320228aa81411ccb
2015-11-16 18:06:32 +01:00

75 lines
2.2 KiB
JavaScript

/*!
* VisualEditor MediaWiki UserInterface signature tool class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
var allowsSignatures = $.inArray(
new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId(),
mw.config.get( 'wgVisualEditorConfig' ).signatureNamespaces
) !== -1;
/**
* MediaWiki UserInterface signature tool. This defines the menu button and its action.
*
* @class
* @extends ve.ui.MWTransclusionDialogTool
* @constructor
* @param {OO.ui.ToolGroup} toolGroup
* @param {Object} [config] Configuration options
*/
ve.ui.MWSignatureTool = function VeUiMWSignatureTool( toolGroup, config ) {
// Parent constructor
ve.ui.MWTransclusionDialogTool.call( this, toolGroup, config );
};
OO.inheritClass( ve.ui.MWSignatureTool, ve.ui.MWTransclusionDialogTool );
ve.ui.MWSignatureTool.static.name = 'mwSignature';
ve.ui.MWSignatureTool.static.group = 'object';
ve.ui.MWSignatureTool.static.icon = 'signature';
ve.ui.MWSignatureTool.static.title =
OO.ui.deferMsg( 'visualeditor-mwsignature-tool' );
ve.ui.MWSignatureTool.static.modelClasses = [ ve.dm.MWSignatureNode ];
// Link the tool to the command defined below
ve.ui.MWSignatureTool.static.commandName = 'mwSignature';
ve.ui.toolFactory.register( ve.ui.MWSignatureTool );
if ( allowsSignatures ) {
// Command to insert signature node.
ve.ui.commandRegistry.register(
new ve.ui.Command( 'mwSignature', 'content', 'insert', {
args: [
[
{ type: 'mwSignature' },
{ type: '/mwSignature' }
],
// annotate
false,
// collapseToEnd
true
]
} )
);
ve.ui.sequenceRegistry.register(
new ve.ui.Sequence( 'wikitextSignature', 'mwSignature', '~~~~', 4 )
);
ve.ui.commandHelpRegistry.register( 'insert', 'mwSignature', {
sequences: [ 'wikitextSignature' ],
label: OO.ui.deferMsg( 'visualeditor-mwsignature-tool' )
} );
} else {
// No-op command that is never executable
ve.ui.commandRegistry.register(
new ve.ui.Command( 'mwSignature', 'content', 'insert', {
args: [ [] ],
supportedSelections: []
} )
);
// Wikitext insertion warning
ve.ui.sequenceRegistry.register(
new ve.ui.Sequence( 'wikitextSignature', 'mwWikitextWarning', '~~~' )
);
}