User:Krinkle/Scripts/InsertWikiEditorButton - Meta-Wiki (original) (raw)

From Meta, a Wikimedia project coordination wiki

This script enables you easily add new buttons to the "new" WikiEditor toolbar (similar to the way one did in in MonoBook / old toolbar).

section

{String} (optional) The name of the section in the WikiEditor. Defaults to 'main'

id

{String} (required) Unique id (ie. 'my-button')

icon

{String} (recommended) URL to the icon, should be a square. It will be rendered at 22px. When using a file from Wikimedia Commons, use 40px or an original SVG, for high-quality rendering on HiDPI screens. See also phab:T414805#11849180, Common thumbnail sizes.

label

{String} (required) Tooltip displayed when hovering button

insertBefore

{String} (optional) Wikitext to be inserted before the cursor on-click

sampleText

{String} (optional) Text inserted in place of the cursor if no text was selected

insertAfter

{String} (optional) Wikitext to be inserted after the cursor on-click

callback

{Function} (optional) Called when the button is clicked

autoSummary

{mixed} (optional) Null or an Object with the following properties:

// OLD WAY - "classic toolbar": mw.toolbar.addButton({ imageId: 'mw-customeditbutton-myspecialbutton', imageFile: 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/40px-Gnome-face-smile.svg.png', speedTip: "Title label", tagOpen: "Smile (", tagClose: ")", sampleText: "sample" });

// NEW WAY - "WikiEditor": krInsertWikiEditorButton({ id: 'mw-customeditbutton-myspecialbutton', icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/40px-Gnome-face-smile.svg.png', label: 'Title label', insertBefore: 'Smile (', insertAfter: ')', sampleText: 'sample' });

The [[File:Krinkle_InsertWikiEditorButton.js]] code is used for statistics (optional).

/**

});

In the above example the script adds two buttons (Happy face and Monkey).

If you experiences any issues, have suggestions for how something could be better, have a good idea for a feature request – or want to report a bug? Send me a message on my Tools talkpage.