Extension:WikiEditor/Toolbar customization

This article describes techniques for MediaWiki versions prior to 1.26. See talk page for some updated insights.

The article explains the technical details of customizing the toolbar. It requires a basic level of understanding of JavaScript.

If you just need some quick code that you can copypaste into your user JS, which will just work out of the box, see the customizations library.

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:
 * (or  depending on how the script will be executed) needs to be set in Localsettings.php
 * The module "ext.wikiEditor.toolbar" needs to be loaded.
 * 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:

Another example from it.source, using callback:

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.

Filter which namespaces should or should not generate added buttons

 * Ex. - To have a button generated only when editing any Talk: namespace page, add the highlighted line below.


 * Ex. - To have a button generated in all namespaces except the User: and Template: namespaces, add the highlighted line 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
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.