Manual:How to make a MediaWiki skin

If you are familiar with the front end technologies of CSS, JavaScript and JSON you can make a MediaWiki skin. It will help if you are familiar with Mustache templates. MediaWiki supports LESS CSS but is not essential for making skins.

Getting started
To begin making a skin, you have two options.

Option 1 - Fork Example skin
The Example skin https://github.com/wikimedia/mediawiki-skins-Example provides the bare bones implementation of a skin. Clone the repository in your skins folder making sure the folder is called "Example" and add the following to your LocalSettings.php: If all has gone to plan your skin should be available on the Special:Preferences page of your wiki.

Option 2 - Use the skins lab
The skins lab tool allows you to setup a skin with basic CSS and templates. Once you feel comfortable, you can click "download as ZIP" which will compile the necessary boiler plate for your skin. Hopefully the resulting repository is easy to navigate. When you have downloaded the ZIP place it in your mediawiki skins folder and update LocalSettings.php with the following: If all has gone to plan your skin should be available on the Special:Preferences page of your wiki.

Let people know!
Making a skin will be more fun with other people and much easier too! Once you have got something usable, please consider publishing it to Github or Gerrit. Once the code is publicly available, you should create a skin page (make sure you change the title!) to let people know you are open for collaboration!

Setting up a wiki page has many other benefits. You'll be able to handle bug reports in Phabricator or Github issues and receive patches from other volunteers in the MediaWiki community. Somebody should also be able to help you setup translation.

Mustache
In 1.35 we added support for Mustache in skins. We found using Mustache to be very helpful in the development of the Skin:Minerva and Skin:Vector skins as it allows you to separate data from presentation. Mustache partials can be used to reuse templates. To use a partial Partial.mustache in MediaWiki, simply add them to the folder you are working in and reference them using in the master template `skin.mustache`.

The data sent to Mustache templates is relatively flexible. If something is missing, you can use PHP to add data by extending the SkinMustache::getTemplateData function.

The SkinJson skin can be added to a MediaWiki development instance, to inspect the data available to skins. Note that arrays are prefixed "array-", booleans are prefixed with "is-" and objects are prefixed "data-" to help you conceptualize the data you are working with.

Making your skin translateable (i18n)
In skin.json under ValidSkinNames, you can use the `messages` option to define translateable message keys. These keys should correspond to entries inside the i18n/en.json folder. Once registered for the skin, these will be available in your template with a prefix "msg-". For example in the example below, the message "sitetitle" can be rendered in a Mustache template using See Localisation for more information on why this is important.

Defaults
A skin at minimum requires a single style ResourceLoader module. It will look a bit like this:

The features key allows you to use useful boiler plate defaults for a variety of things including i18n and normalize which are documented in the MediaWiki core php documentation. Features can be a list of keys (opt-in policy) or in 1.36 an object (opt-out policy). If you are not sure, please omit the features key to use the recommended defaults.

CSS / LESS
The skin.json is a manifest of all the assets your skin uses. Under the `ResourceModules` key you should find the style module for your skin listed under `skins.example`. Here, under the "styles" key you can add LESS or CSS files. They will be loaded in the order they are listed. With LESS you can use @import statements in the same folder. More information about what's possible can be found in ResourceLoader/Developing_with_ResourceLoader.

When using images you should be able to use relative URIs to access the image assets.

JavaScript
JavaScript code in skins, runs in an environment where you can rely on the `mw` and `jQuery` objects having been loaded. We recommend using ResourceLoader/Package_files which will allow you to require file assets.

For information on the available API and libraries see core JS documentation.

More advanced
More advanced information will provided on an as requested basis. Please ask a question on the talk page to accelerate the addition of documentation!

Changing menu content
The composition of menus can be changed by using hooks. For example in Vector, the SkinTemplateNavigation hook is used to relocate the watch star icon. When doing this, remember to check the skin being operated on, to avoid side effects in other skins.

Your feedback is important
If something is not easy, we'd like to make it easier, so your feedback is important. If you hit a snag in what you are trying to build please file a bug describing the problem you are hitting in the mediawiki skin core architecture phabricator and we'll try and find an elegant solution.