I`m trying to insert a custom link to a special page in VisualEditor toolbar. See the image below.
I googled a lot but without success. Someone please give a path...
I`m trying to insert a custom link to a special page in VisualEditor toolbar. See the image below.
I googled a lot but without success. Someone please give a path...
My answer is based on the following resources:
Also, I'm pretty sure, that there is no documented way of adding a tool to the toolbar in VE, as far as I know. Although it's possible to add a tool to a group, which is already added, mostly used for the "Insert" tool group, like in Syntaxhighlight_GeSHi). There is, probably, a much easier or "better" way of doing this :)
First, VisualEditor provides a way to load additional modules (called plugins) when the main part of VE loads (mostly, when you click the "Edit" button). The modules needs to be registered via the global variable
$wgVisualEditorPluginModules
(or the equivalent in extension.json, if you're using the new extension registration). In your extension registration file, you should initialize a module (with your required script files to add the tool) and add it as a VE plugin.Example PHP (old extension registration via PHP files):
extension.json (new JSON-based extension registration):
Now, if VE starts, it will load your module, named
ext.extName.visualeditor
in this example, with the scriptve.ui.ExtNameTool.js
. In this script, you can now do, what ever you want. As an example, this is a way to add a new module to the end of the toolgroup list in the toolbar:Example of ve.ui.ExtNameTool.js:
After installing the extension in your
LocalSettings.php
and starting VE, you should see a new tool in the toolbar with the given name. Clicking it will show an alert box with content "Hello". Like written in the inline comments: In the click handler (onSelect
) you can do whatever you want, e.g. open a link in a new tab, e.g. to a Special page. To get the link to a special page I would suggest to usemw.Title
to get a localized namespace. For example:The first parameter of
mw.Title.newFromText()
is the name of the page, the second parameter is the ID of the namespace (-1 is the default for special pages and should always work).I hope that helps!
I am not sure I understand your question entirely. It is as simple as selecting some text, clicking the chain icon, then clicking the
External Link
tab and pasting your link there.