Manual:Page content models/fr

The ContentHandler introduced in MediaWiki 1.21 allows you to add new content models other than wikitext. It makes it possible for wiki pages to be composed of data other than wikitext, and represented in any way — for example: Markdown, reStructuredText, icalendar, or a custom XML format. The display and editing of these content models can be handled in custom ways (e.g. different syntax highlighting, or whole new data-entry forms).

This page steps through how to create a new content model in an extension. It assumes some familiarity with general extension development practices. For a brief summary of the requirements, see the Summary section at the bottom of this page.

A meaningless "Goat" content model will be used for the examples. You can also examine the DataPages extension, which is part of.

Enregistrement
D'abord, ajoutez le nom du modèle de contenu de la classe du gestionnaire à votre :


 * The left-hand value here is the name of the content type, it can be any unique string you want, and it lives alongside the five built-in content types: 'wikitext', 'JavaScript', 'CSS', 'plain text', 'JSON'. Cette valeur est exposée aux utilisateurs à des endroits tels que Special:ChangeContentModel et les informations de page.
 * The right-hand value is the fully-qualified name of a class that extends.

Ceci nécessite que deux nouvelles classes,  et , soient ajoutées à  (si leur espace de noms n'est pas dans ). D'autres informations concernant ces classes sont données ci-dessous.

Constantes optionnelles du modèle de contenu
The 'goat' string above is the content model's ID (generally called  in code), and is usually also defined as a constant. These constants are defined for all built-in content models, and lots of documentation refers to the "CONTENT_MODEL_XXX" constants. If you have not defined them, this can be a bit confusing. The definition should be done via the callback item in extension.json. For example:

Dans  :

Dans  :

Vous ne devez pas le faire de cette façon, mais simplement utiliser la chaîne de caractères.

Assigner des modèles de contenu aux pages
Si vous voulez que l'espace de noms entier d'un wiki ait un modèle de contenu par défaut, vous pouvez le définir comme tel dans extension.json :

Or if you want to determine the content type by the addition of a quasi-file-type suffix on the wiki page name, you can use the hook. For example:

Gestionnaire de contenu
The next thing to define is the GoatContentHandler class, which is where we also specify what format this content type will be stored as (in this case, text). ContentHandlers don't know anything about any particular page content, but determine the general structure and storage of the content.

Contenu
The GoatContent class is the representation of the content's data, and does not know anything about pages, revisions, or how it is stored in the database. Beside the required seven inherited methods, you can add other public methods are domain-specific; in this case we want to be able to retrieve the goat's name.

Formulaire de modification
Maintenant que nous avons configuré le squelette, nous allons essayer de modifier une chèvre. Pour faire ceci, nous créons  en spécifiant quelles actions que nous voulons associer aux classes. To start with, we'll just deal with 'edit' (which corresponds to  in the URL).

And we'll create our new GoatEditAction class, basically the same as the core EditAction but using our own GoatEditPage:

Our new GoatEditPage class is where the action happens (excuse the pun):

You should now be able to edit a page and see your form. But when you put data into it, and hit 'preview', you'll see that things are not yet working fully and that you get no output, nor is your submitted text shown again in the form.

So we must override the 'submit' action as well, with a new GoatSubmitAction class and the addition of  to our   method. Our GoatSubmitAction class should be the same as that of core, but inheriting from our GoatEditAction.

Affichage
A content model is responsible for producing any required output for display. This usually involves working with its data and producing HTML in some way, to add to the parser output.

Afficher une description/documentation
Sometimes you may want to display some informations or some documentation for an article that have a custom content model such as JSON. Actually there aren't system messages to display some text above such pages (with the exception of MediaWiki:Clearyourcache displayed above only JavaScript and CSS pages). You may want to see T206395 for further details.

Résumé
Pour implémenter un nouveau modèle de contenu avec un formulaire d'édition personnalisé, créez ceci :

Voir aussi

 * - pour la documentation de l'utilisateur final concernant la modification d'un modèle de contenu.
 * - pour un exemple de modèle de contenu personnalisé (mais pas encore n'importe quel formulaire de modification personnalisé).
 * - pour un exemple de modèle de contenu personnalisé (mais pas encore n'importe quel formulaire de modification personnalisé).