Sambungan:TemplateData
TemplateData Release status: stable |
|
---|---|
Implementation | Tag , API |
Description | Membolehkan untuk menyimpan, mengambil dan menggambarkan maklumat mengenai templat |
Author(s) | Timo Tijhof, Moriel Schottlender, James Forrester, Trevor Parscal, Bartosz Dziewoński, Marielle Volz, ... |
Latest version | 0.1.2 (Kemas kini berterusan) |
Compatibility policy | Snapshots releases along with MediaWiki. Master is not backward compatible. |
MediaWiki | >= 1.43 |
PHP | 5.4+ |
Database changes | No |
License | GNU General Public License 2.0 or later |
Download | |
|
|
<templatedata> |
|
Quarterly downloads | 275 (Ranked 18th) |
Public wikis using | 6,971 (Ranked 24th) |
Translate the TemplateData extension if it is available at translatewiki.net | |
Issues | Open tasks · Report a bug |
Sambungan TemplateData memperkenalkan tag <templatedata>
dan API membenarkan para penyunting untuk menentukan cara templat dan parameternya harus digunakan.
Maklumat ini tersedia sebagai jadual yang diformat dengan baik untuk pengguna akhir dan sebagai API JSON yang membenarkan sistem-sistem lain (contohnya VisualEditor ) membina antara muka untuk berkerja dengan templat.
See Help:TemplateData for in-depth help.
Pemasangan
- Download and move the extracted
TemplateData
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'TemplateData' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Menyunting data
Sambungan TemplateData berfungsi dengan mempunyai tag <templatedata>
yang ditakrifkan dalam teks wiki halaman templat (sebagai pilihan, ia boleh ditransklusikan daripada halaman lain juga).
Ini direka bentuk supaya serasi dengan susun atur biasa yang banyak wiki punyai untuk mentransklusikan pendokumenan templat dari halaman yang berasingan (tetapi tidak diperlukan).
Kandungan tag <templatedata>
ini mestilah JSON yang sah menggunakan format yang diterangkan di bawah; ambil perhatian bahawa semua penerangan mestilah dalam teks biasa (tiada teks wiki diterima di dalam data templat).
Apabila blok <templatedata>
dimasukkan ke dalam suatu halaman, sambungan TemplateData melakukan pemeriksaan berikut apabila halaman itu disimpan:
- Kandungan mestilah JSON yang sah;
- Setiap butir di dalam struktur JSON mestilah jenis yang dijangka seperti yang dinyatakan di bawah (contohnya objek, tatasusunan, atau primitif); dan
- Untuk butir yang mempunyai senarai nilai mungkin yang ditentukan (contohnya
type
bagi parameter), nilai dalam objek JSON mestilah padan dengan salah satu nilai tersebut.
Sekiranya mana-mana semakan ini gagal, pelayan tidak akan memberi kebenaran untuk menyimpan dan mesej ralat akan dipaparkan di atas halaman suntingan.
Untuk butir-butir autovalue
, T4700 menghalang subst:
daripada bekerja di mana-mana templat yang ditambahkan ke dalam tag, termasuklah tag <ref>
dan <gallery>
.
Blok TemplateData akan disimpan dengan betul, tetapi teks wiki yang dihasilkan tidak akan dihuraikan dengan betul apabila templat itu digunakan.
Elakkan daripada menggunakan {{#tag:templatedata}}
kerana hal ini menjadikannya mustahil untuk menggunakan penyunting data templat.
Format
Berikut adalah versi visual data JSON seperti yang ditakrifkan di halaman templat yang disertakan dengan tag <templatedata></templatedata>
.
Spesifikasi rasmi boleh didapati di repositori TemplateData.
Rujuk Specification.md untuk versi yang terkini.
Objek TemplateData
Objek TemplateData merupakan unsur akar JSON yang disertakan dalam unsur <templatedata>
pada halaman templat.
Kunci | Jenis | Penerangan |
---|---|---|
description
|
InterfaceText atau null
|
Penerangan ringkas templat. Mestilah dalam teks biasa. Once filled, it can be displayed as caption when editing a single template and perhaps in search results when users pick one of many. The default is null .
→ For more details see: description |
params
|
Object containing Param objects | An object that maps each parameter name of the template to a corresponding Param object describing the properties of that parameter.
→ For more details see: params |
paramOrder
|
Array containing parameter name strings | The logical order in which parameters should be displayed. The array contains each parameter key exactly once. Each string must be a valid key in the params object.
→ For more details see: paramOrder |
sets
|
Array containing Set objects |
An array containing set specifications. A set is a group of parameters that should be used together. The default is []. Note that the sets functionality is still in development.
|
format
|
string, either inline or block
|
How the template's wikitext representation SHOULD be laid out. The default is inline . See #Custom_formats for other custom formats.
|
maps
|
Object containing Map objects | An object that links a simplified name of a third party consumer of the template data (i.e. Citoid, Special:MyLanguage/Wikidata, etc.) to a map object that in turn links a name of a consumer parameter to one or more corresponding names of template parameters. |
Param object
Key | Type | Default | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
label |
InterfaceText | null
|
A (very) brief name for the parameter. Try to keep under 20-ish characters.
→ For more details see: label | ||||||||||||||||||||||||||||
description
|
InterfaceText | null
|
A brief description of the parameter, for users to know which to pick from an option list.
→ For more details see: description | ||||||||||||||||||||||||||||
required
|
boolean | false
|
Whether the parameter is required for the template to work (true if this parameter must be specified).
→ For more details see: required | ||||||||||||||||||||||||||||
suggested
|
boolean | false
|
Whether the parameter is suggested for the template to be useful (true if this parameter should be specified).
→ For more details see: suggested | ||||||||||||||||||||||||||||
deprecated
|
boolean or string | false
|
Whether the parameter is deprecated. The value can be a string of instructions giving the user guidance what instead can be done, or be simply true .
→ For more details see: deprecated | ||||||||||||||||||||||||||||
aliases |
Array containing strings | [] |
List of aliases. An alias is an alternative name for the parameter that may be used instead of (not in addition to) the primary name. Aliases are not documented in a separate Parameter object. If they need more information, they should be in their own property marked "deprecated".
→ For more details see: aliases | ||||||||||||||||||||||||||||
default |
InterfaceText | null |
A fixed default value used by the template if no value is assigned to the parameter, or a description thereof.
→ For more details see: default | ||||||||||||||||||||||||||||
autovalue |
string | null |
A dynamically-generated default value in wikitext, such as today's date or the editing user's name; this will often involve wikitext substitution, such as {{subst:CURRENTYEAR}} .
→ For more details see: autovalue | ||||||||||||||||||||||||||||
example
|
InterfaceText | null
|
An example text for the parameter, to help users fill in the proper value.
→ For more details see: example | ||||||||||||||||||||||||||||
type |
string | "unknown" |
The type of the parameter, for (soft) type hinting. One of:
→ For more details see: type | ||||||||||||||||||||||||||||
inherits |
string | none substituted |
The name key of another parameter (must be a valid key in the params object). The current Parameter Object will inherit properties from the specified Parameter Object, with local properties overriding the inherited ones.
→ For more details see: inherits | ||||||||||||||||||||||||||||
suggestedvalues |
Array containing strings | []
|
An optional parameter property. Creates a list of parameter values to help users select the desired value. For the suggested values to be displayed as a combo box in VisualEditor, the parameter’s type must be set to one of the following: content, line, string, number, unknown or unbalanced wikitext.
→ For more details see: suggestedvalues |
Set object
Key |
Object or primitive type |
Description |
---|---|---|
label
|
InterfaceText | A (very) brief name for the parameter set. Try to keep under 20-ish characters. |
params
|
Array of strings | One or more names of parameters to include in the set (each must be a valid key in the params object). A parameter may be in multiple sets. Not every parameter must be in a set.
|
Maps structure
Maps is a single data structure that goes multiple levels deep. It became common to call the second level a “map object”.
Key | Type | Default | Description |
---|---|---|---|
name of consumer | object | {} | An object that links a name of a consumer to a map object that in turn links a name of a consumer parameter to one or more corresponding names of template parameters.
The names of the template parameters can be specified either as a string (one name), an array of strings (several names), or an array of arrays of strings (several sets of names); each of these strings must be a valid key in the A specific template parameter may be in multiple maps, and it may be used in the values of multiple keys in a given map, but not every template parameter must be in a map. A shortened example from English Wikipedia's Template:Cite_news#TemplateData illustrates the structure of map objects. { "proveit": { "main": "title", "textarea": [ "quote" ] }, "citoid": { "title": "title", "url": "url", "publisher": "publisher", "publicationTitle": "work", "date": "date", "ISSN": [ "issn" ], "ISBN": [ "isbn" ], "contributor": "others", "author": [ [ "first", "last" ], [ "first2", "last2" ], [ "first9", "last9" ] ], "editor": [ [ "editor-first", "editor-last" ] ] } } |
InterfaceText (string or object)
A free-form plain-text string (i.e. no wikitext or HTML) in the content-language of the wiki, or an object containing those strings keyed by language code.
The default value for all InterfaceText fields is null
.
String type
If it is a string, it must contain a non-localized string in the content language of the local wiki.
Object type
If it is an object, the object must have this mapping:
Key | Type | Description |
---|---|---|
Wikipedia language code | string | Localized string for users of that interface language. |
Example of object mapping:
Key | Value |
---|---|
"en" | "Welcome to Wikipedia" |
"de" | "Willkommen bei Wikipedia" |
"fr" | "Bienvenue sur Wikipédia" |
"nl" | "Welkom op Wikipedia" |
"it" | "Benvenuti su Wikipedia" |
"es" | "Bienvenidos a Wikipedia" |
"ru" | "Добро пожаловать в Википедию" |
Example
An example TemplateData structure as specified within wikitext on a template page.
<templatedata>
{
"description": "Label unsigned comments in a conversation.",
"params": {
"user": {
"label": "User's name",
"type": "wiki-user-name",
"required": true,
"description": "User name of person who forgot to sign their comment.",
"aliases": ["1"]
},
"date": {
"label": "Date",
"suggested": true,
"description": {
"en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."
},
"aliases": ["2"],
"autovalue": "{{subst:#time:Y-m-d}}"
},
"year": {
"label": "Year",
"type": "number"
},
"month": {
"label": "Month",
"inherits": "year"
},
"day": {
"label": "Day",
"inherits": "year"
},
"comment": {
"required": false
}
},
"sets": [
{
"label": "Date",
"params": ["year", "month", "day"]
}
],
"maps": {
"ExampleConsumer": {
"foo": "user",
"bar": ["year", "month", "day"],
"quux": [
"date",
["day", "month"],
["month", "year"],
"year"
]
}
}
}
</templatedata>
Below is how the above example would be displayed on the template page:
Label unsigned comments in a conversation.
Parameter | Description | Type | Status | |
---|---|---|---|---|
User's name | user 1 | User name of person who forgot to sign their comment. | User | required |
Date | date 2 | Timestamp of when the comment was posted, in YYYY-MM-DD format.
| Unknown | suggested |
Year | year | no description | Number | optional |
Month | month | no description | Number | optional |
Day | day | no description | Number | optional |
comment | comment | no description | Unknown | optional |
API
See the generated help at Special:ApiHelp/templatedata. A sample invocation (formatted for human readability) is:
This returns the template data for Template:Cite web.
The <templatedata>...</templatedata>
block for this template is on its transcluded template documentation page, en:Template:Cite web/doc.
Additions and changes to JSON as received from the API
The JSON structure provided in response to an API HTTP get request is significantly different than that which is defined in the <templatedata>...</templatedata>
block.
In response to the API request, extension TemplateData makes the following changes to the JSON object:
- Adds two wrapping objects:
- An overall Pages Object containing one or more Page Objects
- An object with a numeric key: a Page Object
- Additions/changes to the actual TemplateData Object
- Add the
title
key with the name of the page from which the data was requested (e.g. "Template:Cite web"). - Add the
sets
key - Change all TemplateText occurrences that are just strings to objects with a single key for the current wiki's Wikipedia language code
- Remove all
inherits
keys.- Add all properties from parameter from which an inheritance is defined which are not superseded by explicitly defined keys in the inheritor's Parameter Object.
- Add default values for all keys in each Parameter Object which have not been explicitly defined or inherited.
- Add the
Visualised differences in a TemplateData JSON object delivered by the API
| ||||||
|
Key | Type | Description |
---|---|---|
title
|
string | The page name of the template (e.g. "Template:Cite web"). This key is not contained in the JSON structure on the template page. It is added to the structure by the MediaWiki software in route to delivery via the API. |
sets
|
Array containing Set Objects | An array containing set specifications. A set is a group of parameters that should be used together. If this does not exist on the template page it is added as an empty array to the structure provided by the API. |
Key | Type | Description |
---|---|---|
label |
InterfaceText | translated to InterfaceText object, if not already in that format. |
required |
boolean | If not defined, default value of false added. |
description |
InterfaceText or null |
If defined as a string, converted to a InterfaceText object. If not defined, key is added with a null value.
|
deprecated |
boolean or string | If not defined, default value of false added. |
aliases |
Array of strings | If not defined, a default empty array is assigned (i.e. [] ). |
default |
string | If not defined, default of "" is assigned. |
type |
string | If not defined, default of "unknown" is assigned. |
inherits |
(removed) | This key is removed and all inherited keys are added. Keys defined for the current parameter take precedence and any keys not defined on either the current param, or the one from which it inherits are given the default value. |
Key | Object or primitive type |
Description |
---|---|---|
Object (containing localized strings by Wikipedia language code) If a TemplateData field on the template page contains a string, not an object with localized strings, MediaWiki translates it into an InterfaceText Object with a string assigned to the key name of the source Wikipedia Wikipedia language code. The default for all InterfaceText fields is null .
| ||
(Wiki language code) | rentetan | Rentetan tempatan untuk pengguna bahasa antara muka itu. |
Contoh objek JSON yang disediakan oleh API
The response to an API request for the TemplateData structure in the Example section (above) can be seen:
- Dalam format HTML: https://www.mediawiki.org/w/api.php?action=templatedata&titles=Extension:TemplateData&format=jsonfm
- Seperti yang disampaikan oleh API: https://www.mediawiki.org/w/api.php?action=templatedata&titles=Extension:TemplateData
Tatarajah
Pemboleh ubah | Lalai | Penerangan |
---|---|---|
$wgTemplateDataUseGUI
|
true
|
Antara muka dialog uji kaji untuk menyunting JSON data templat |
Lihat juga
- Sambungan:TemplateWizard – user interface for selecting and inserting templates' wikitext, based on their TemplateData.
- GitHub: jeblad/TemplateData – versi alternatif dengan beberapa fungsi Lua.
- Templat boleh terjemah
- Wikibase/Maps TemplateData
This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. |
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Extensions bundled with MediaWiki 1.35/ms
- Stable extensions/ms
- Tag extensions/ms
- API extensions/ms
- GPL licensed extensions/ms
- Extensions in Wikimedia version control/ms
- EditPage::showEditForm:fields extensions/ms
- EditPage::showEditForm:initial extensions/ms
- MultiContentSave extensions/ms
- OutputPageBeforeHTML extensions/ms
- ParserFetchTemplateData extensions/ms
- ParserFirstCallInit extensions/ms
- ResourceLoaderRegisterModules extensions/ms
- All extensions/ms
- Extensions used on Wikimedia/ms
- Extensions included in BlueSpice/ms
- Extensions included in Canasta/ms
- Extensions available as Debian packages/ms
- Extensions included in Fandom/ms
- Extensions included in Miraheze/ms
- Extensions included in MyWikis/ms
- Extensions included in ProWiki/ms
- Extensions included in semantic::core/ms
- Extensions included in ShoutWiki/ms
- Extensions included in wiki.gg/ms
- Extensions included in WikiForge/ms
- Metadata/ms