Extension:WikiEditor/Toolbar customization

If you're just here to get some quick code that you can copypaste into your user JS and will just work out of the box, see the customizations library. The rest of this article explains the technical details of customizing the toolbar and requires a basic level of understanding of JavaScript.

Basic setup
Before a script is able to manipulate the toolbar provided by WikiEditor, two things must happen: To customize the toolbar, put the following code in your User:YourUserName/common.js:
 * The module "ext.wikiEditor.toolbar" needs to be loaded.
 * "$wgAllowUserJs = true;" needs to be set in Localsettings.php
 * The document needs to be read.

. . . and replace the line  by the code which defines each button added. Multiple snippets can be added by simply pasting them below each other, inside of the function.

Configuration structure
The toolbar widget is defined by a jQuery plugin from module jquery.wikiEditor. You can look at the configuration for the default toolbar on module jquery.wikiEditor.toolbar.config to see how you can modify the toolbar. Complete documentation is to be written shortly.

You can modify the toolbar even after it's been built (see example above) by calling the  function on the textarea. You will need to do this inside an  call, as already mentioned.

action

 * type: one of "encapsulate", "replace", "callback", "dialog"
 * options: for "encapsulate" or "replace" types, carries options for jquery.textSelection module (pre, peri, post); regex, regexReplace
 * execute: for "callback" type, a callable function which will be passed the WikiEditor context
 * module: for "dialog" type, named reference to a WikiEditor add-in dialog module to open

Example:

'action': { 'type': 'encapsulate', 'options': { 'pre': "'''", 'periMsg': 'wikieditor-toolbar-tool-bold-example', 'post': "'''" }       }    }

Another example from it.source, using callback:

action: { type: 'callback', execute: function(context){ indentSelection; }      }

button

 * type: "button"
 * icon string required: short key name or URL to icon
 * label string: non-localizable label string
 * labelMsg string: key for localizable message string
 * 

booklet

 * type: "booklet"
 * label string: non-localizable label string
 * labelMsg string: key for localizable message string
 * deferLoad boolean
 * pages object: map of name keys to further objects:
 * layout string required: 'table' or 'characters'
 * label string: non-localizable label string
 * labelMsg string: key for localizable message string
 * headings string[]: array of objects? {textMsg: key} ??
 * rows object[] optional?: array of objects? {'row key name': {message object?}}
 * characters string[] optional?: array of strings of little character bits for insertion (???!)

Q: How can we receive an event or callback when our booklet gets triggered?

Default sections
The default WikiEditor toolbar has the following sections:
 * The main section which is always visible, with the groups format and insert.
 * The advanced section, with the groups heading, format, size, insert and search.
 * The characters section, with pages latin, latinextended, ipa, symbols, greek, cyrillic, arabic, hebrew, bangla, telugu, sinhala and gujarati
 * The help section, with pages format, link, heading, list, file, reference and discussion.

Adding things
When using the code below, remember it depends on the module "ext.wikiEditor.toolbar" and needs to wait until the page is loaded. To avoid executing it before everything is properly initialized, you should copy it inside of the function  defined above, or something equivalent.

The general format for adding things is as follows: Some specific examples are displayed in the sections below.

Add a special characters page
Note that this only works after the 'characters' section has been built.

Add characters to an existing special characters page
Additional characters can be injected during the building of the 'characters' section: There is also an API function, but it only works after the 'characters' section has been built:

Removing things
Use the  call to remove buttons from the toolbar. The following example removes the Search and Replace button:

Modifying things
Warning: Binding doesn't seem to work with  but does work if called with   from module "mediawiki.legacy.wikibits" (make sure to add it to your script's dependencies).

A working example could be found at the bottom of [//ru.wikipedia.org/w/index.php?title=MediaWiki:ToolbarNew.js&oldid=25331363 ru:MediaWiki:ToolbarNew.js]

We don't really have a nice API to modify things, unfortunately. The best we have is a hook to change the configuration of a section just before it's being built:

Determining when toolbar load is done
To be notified when the initial toolbar load is done, put:

This is in WikiEditor wmf/1.21wmf8 and later. For example, GuidedTour repositions absolutely positioned guiders (a type of tooltip) at this point.