VisualEditor/Gadgets/Creating a custom command

This is an example for how to create a custom command. It will show up in the “Page options” menu and unlink all years (i.e. remove all links to pages with a numeric title, keeping the label). Currently it only works in the 2017 wikitext editor and only when text is selected.

Function to modify wikitext
First of all, we define our function to modify wikitext. This is not specific to VisualEditor, if you're reading this because you want to adapt your scripts to VisualEditor, you should already have this function.

Just as a minor note: In the early days of Wikipedia linking every year in a text was very popular. After some time editors realized that these links didn't really help anyone in most cases, so they tried to eliminate all those links. During that time scripts to do so automatically were very popular. Nowadays the remaining links to years are sensible in most cases, so scripts to remove them should no longer be needed, but it's still a nice example.