Manual:Page content models/ja

MediaWiki 1.21 で導入された ContentHandler では、ウィキテキスト以外の新しいコンテンツモデルを追加できるようにします. これにより、ウィキ ページをウィキテキスト以外のデータで構成したり、任意の方法で表現できるようになります. Markdown、reStructuredText、icalendar、カスタム XML 形式などです. 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).

このページでは、拡張機能で新しいコンテンツ モデルを作成する方法を説明します. 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. また、 の一部である DataPages 拡張機能を調べることもできます.

登録
First of all, add the content model's name and handler class to your :


 * 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'. This value is exposed to users in places such as Special:ChangeContentModel and page information.
 * The right-hand value is the fully-qualified name of a class that extends.

This will require two new classes,  and , to be added to  (if their namespace isn't in ). More information about these classes is given below.

Optional content model constants
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. それらを定義していない場合、これは少し混乱するかもしれません. The definition should be done via the callback item in extension.json. For example:

内:

内:

You don't have to do it this way, and could just use the string.

Assigning content models to pages
If you want an entire wiki namespace to have a default content model, you can define it as such in 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:

ContentHandler
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.

Content
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.

編集フォーム
Now we've got the skeleton set up, we'll want to try editing a Goat. To do this, we create and specify what actions we want to map to what 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.

表示
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.

Display a description/documentation
時には JSON など、その記事に特化したコンテンツ様式を供えていて、情報や解説文書を表示したい場合があります. Actually there aren't system messages to display some text above such pages (except for MediaWiki:Clearyourcache displayed above only JavaScript and CSS pages). You may want to see T206395 for further details.

Comparing revisions
The GoatDifferenceEngine class is the representation of the difference between goat contents. We override the default  method to generate a diff.

In order to tell MediaWiki to use our GoatDifferenceEngine, we overwrite the  in our GoatContentHandler.

要約
To implement a new content model with a custom editing form, create the following:

関連項目

 * - for end-user documentation about changing a content model.
 * - for an example of a custom content model (but not yet any custom editing form).
 * - for an example of a custom content model (but not yet any custom editing form).