Replace the default WikiEditor signature button with a custom signature button

From ProWiki - Demo and Test Wiki

This is the latest revision of this page; it has no approved revision.

Created and tested for MediaWiki 1.39.x and may work for more recent versions, too.

JavaScript

Add the following code to the "MediaWiki:Common.js" page

// <nowiki>
var customizeToolbar = function () {
    /**
     * Add the custom signature button to the existing "main" group
     */
    $('#wpTextbox1').wikiEditor('addToToolbar', {
        section: 'main',
        group: 'insert',
        tools: {
            "customSignature": {
                label: 'Signatur einfügen',
                type: 'button',
                icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c0/OOjs_UI_icon_signature-ltr.svg/20px-OOjs_UI_icon_signature-ltr.svg.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: ' --~~~~',
                        post: '',
                        ownline: false
                    }
                }
            }
        }
    });
};

/**
 * Check if the view is in edit mode and the required modules are available. Then, customize the toolbar …
 */
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
    mw.loader.using('user.options').then(function () {
        if (mw.user.options.get('usebetatoolbar') == 1) {
            $.when(
                mw.loader.using('ext.wikiEditor'), $.ready
            ).then(customizeToolbar);
        }
    });
}
// </nowiki>

CSS

Add the following code to the "MediaWiki:Common.css" page

/** WikiEditor
 * Hide the custom signature button from the existing "main" group
 */
div#wikiEditor-ui-toolbar span[rel="signature"] {
    display: none;
}

Q & A

Question: What is the difference to the default signature button?
Answer: This custom signature button prepends a space to the signature code in contrast to the code added by the default button, i.e.  --~~~~ instead of --~~~~. This is helpfull if you would like to add signatures to tables without interfering with the table code itself.