Manual:How to make a MediaWiki skin/Migrating SkinTemplate based skins to SkinMustache/fr

As part of the 1.35 release in 2020, the SkinMustache class was added to MediaWiki core. Ce développement rend possible l'utilisation des modèles Mustache pour créer des habillages. It should appeal to skin developers who do not wish to use PHP, or would like to reduce their dependency on PHP. This tutorial aims to demonstrate the steps you may need to convert a PHP based SkinTemplate skin to SkinMustache.



Etape 1 : enregistrer un habillage
Previously, a skin would need to declare a Skin PHP class that extends the SkinTemplate. It would need to define several properties that were used to define the skins internal key and the associated PHP template.

Since 1.35, this information can be defined at time of skin registration.

Historically, skins have required the creation of 2 PHP classes. With the new registration process, you need at most 1 PHP class.

When declaring a skin, it's possible you can set the  value to "SkinTemplate" to use the default core interface:

If your Skin contains hooks, we recommend pulling those out into a separate file.

Voici un exemple pour l'habillage Monobook : 701142



Etape 2 : débloquer la puissance de la modélisation
To follow this next step, it's assumed that a little knowledge of the Mustache template language has been acquired. Au minimum vous devez connaître les bases suivantes de Mustache décrites dans l'exemple ci-dessous :

Hello World
Create a Mustache file with the relative path templates/skin.mustache

To use the SkinMustache class, declare the class property as SkinMustache.

Chargez l'habillage dans votre navigateur et vous devriez voir le contenu de votre fichier Mustache.



Utiliser une classe personnalisée
To aid migration, you'll want to use your own custom class that extends SkinMustache, at least as an interim step and start redirecting the code from your skin template into templates.

Créer une nouvelle classe d'habillage qui étend SkinMustache, par exemple pour l'habillage MonoBook, elle pourrait s'appeler SkinMonoBook.

Lorsque vous utilisez un modèle basé sur PHP tel que MonoBookTemplate, on s'attend à ce que le développeur d'habillage implémente une fonction execute qui renvoie le HTML.

In SkinMustache, the approach is different. Nous fournissons un tableau associatif de template data qui est passé au modèle Mustache.

Dans l'exemple suivant, de nouvelles données sont initialisées et passées au modèle Mustache :

With this change we can make the following change to our template to output the data.

Using this technique we can bridge our old skin with SkinMustache.

First we may need to refactor our execute method to separate out a function that returns a string which represents the body of the skin. It's important to note in SkinMustache, you are restricted to templating the content of the body tag. In SkinMustache with this refactor done, we can extend the data we pass to a template as demonstrated with the html-hello example above. We can add a new template variable html-quick-template-migration which can be rendered inside our skin.mustache as raw HTML.



Step 3: donnée entre accolades
At this point you should have a skin implementing SkinMustache which is leveraging BaseTemplate to generate HTML. The PHP inside your PHP template that implements BaseTemplate should be possible with Mustache.

SkinMustache skins are data driven, which we believe gives better flexibility in how you want to render the data. The data is informed by skins in the wild. This data is documented elsewhere at Manual:SkinMustache.php#Template data.

There is little guidance on this step, other than explore how you can generate HTML code identical to your code in BaseTemplate using only the data and templates. Challenges you face while doing this should be raised on the talk page to help others.



Step 4: remplir les données manquantes
During step 3 you may find HTML you are trying to generate cannot be rendered using the data inside SkinMustache. Hopefully from step 2 however you've realized you are not limited to the data you pass to your template.

However, it's useful for us to know about data that was missing, as it's likely your skin is doing something unique that may benefit other skins.

Simply by your code existing, you've communicated bits of data that would be helpful but you are invited to explicitly file Phabricator ticket requesting the data you need.