Debian Codegraph @

extensions/TemplateData/Specification.md

raw symbols SCIP
1 # TemplateData Specification
2
3 ## Living Standard
4
5 **This version**
6 https://phabricator.wikimedia.org/diffusion/ETDA/browse/master/Specification.md
7
8 **Editors**
9 Timo Tijhof, Trevor Parscal, James D. Forrester, Marielle Volz, Moriel Schottlender, C.Scott Ananian, eranroz, Adam Wight
10
11 ***
12
13 ## 1 Introduction
14
15 This document specifies the structure that TemplateData blobs must follow.
16
17 The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](http://tools.ietf.org/html/rfc2119).
18
19 ## 2 Terminology
20
21 ### 2.1 Template
22
23 A page on a MediaWiki website that can be transcluded into other pages. Refer to [mediawiki.org](https://www.mediawiki.org/wiki/Help:Templates) for documentation about what templates are capable of and how to create or use them.
24
25 ### 2.2 Parameter
26
27 A key–value pair associated with the transclusion of a template in order to alter the behaviour of a template (and by extend, the content it will return as part of the transclusion).
28
29 ### 2.3 Author
30
31 A program that creates and modifies TemplateData blobs, and distributes them to TemplateData consumer programs.
32
33 ### 2.4 Consumer
34
35 A program interpreting TemplateData blobs (supplied by a TemplateData author).
36
37 ### 2.5 User
38
39 A person using a TemplateData consumer program.
40
41 ## 3 Structures
42
43 Authors MUST ensure TemplateData blobs have exactly one top-most structure of key–value pairs (hereafter referred to as "objects" having "properties") that follow the specification for the "Root" structure, as specified in section 3.1 below.
44
45 All objects share the following requirements:
46
47 1. Authors MUST ensure they only have properties described in this specification. Properties not specified here MUST not be present. Authors MUST ensure that properties and structures marked as "Required" are present. Other properties MAY be omitted.
48
49 2. Authors MUST ensure objects do not have multiple properties with the same key.
50
51 Requirements for non-Required ("optional") properties only apply if the property is present.
52
53 ### 3.1 Root
54
55 #### 3.1.1 `description`
56 * Value: `null` or `InterfaceText`
57
58 #### 3.1.2 `params`
59 * Required
60 * Value: `Object` containing `Param` objects, see 3.2
61
62 Describes each of the template's parameters to a User.
63
64 Authors MUST ensure that the `params` object maps parameter names to `Param` objects.
65
66 #### 3.1.3 `paramOrder`
67 * Value: `Array` of `string`
68
69 The logical order of the parameters.
70
71 Authors MUST ensure the `paramOrder` array contains all parameter names exactly once.
72
73 Consumers SHOULD display the parameters in this order.
74
75 #### 3.1.4 `sets`
76 * Required
77 * Value: `Array` of `Set` objects, see 3.3
78
79 List of groups of parameters that can be used together.
80
81 Authors MUST ensure that the `sets` object contains only `Set` objects. Authors MAY include a parameter in multiple `Set` objects. Authors are NOT REQUIRED to reference each parameter in at least one `Set` object.
82
83 A Consumer MAY encourage users to interact with parameters in a `Set` together (e.g. add, edit, or remove those parameters at once).
84
85 #### 3.1.5 `maps`
86 * Required
87 * Value: `Object` containing `Map` objects, see 3.6
88
89 An object describing which parameter(s) specific Consumers SHOULD use for some purpose.
90
91 The `maps` property contains key–value pairs where the key identifies a given Consumer, and the value a `Map` object.
92
93 Consumers are NOT REQUIRED to have a corresponding `Map` object.
94
95 Consumers that look for a `Map` SHOULD publicly document their identifier key.
96
97 Authors MUST ensure that the `maps` object contains only `Map` objects. Authors MAY include a parameter in multiple `Map` objects. Authors are NOT REQUIRED to reference each parameter in at least one `Map` object.
98
99 #### 3.1.6 `format`
100 * Value: `null` or `FormatString` (see 3.7) or `string` of either `'inline'` or `'block'`
101 * Default: `null`
102
103 How the template's wikitext representation SHOULD be laid out. Authors MAY choose to use this parameter to express that a template will be better understood by other human readers of the wikitext representation if a template is in one form or the other.
104
105 If the parameter is set to `'block'`, it MUST be interpreted as the format string `'{{_\n| _ = _\n}}'`. If the parameter is set to `'inline'` it MUST be interpreted as the format string `'{{_|_=_}}'`.
106
107 If the parameter is not null, Consumers SHOULD create a wikitext representation corresponding to the given format string, as described in section 3.7.
108
109 If the parameter is set to `null`, Consumers SHOULD create the same representation as for `'inline'` format for new template transclusions, and SHOULD attempt to use the same formatting for new parameters as for existing ones for existing transclusions that are edited.
110
111 In the absence of the parameter being set, the system will supply `null` as a fallback value.
112
113 ### 3.2 Param
114 * Value: `Object`
115
116 #### 3.2.1 `label`
117 * Value: `null` or `InterfaceText`
118 * Default: Key of this `Param` object as referenced from `Root.params`.
119
120 Label of this parameter.
121
122 Authors are RECOMMENDED to provide unique labels for each parameter.
123
124 Consumers SHOULD use this when referring to a parameter in the interface for users.
125
126 #### 3.2.2 `description`
127 * Value: `null` or `InterfaceText`
128
129 Explanatory text describing the purpose of this parameter to a User.
130
131 Authors are RECOMMENDED to give each parameter a description. Authors MAY use include hints as to how to the format the parameter value.
132
133 For example, a template parameter called `name` might have as its description _"The name of the author of the book, to positively identify and attribute the claim. The name should be given as it would appear in the author's native language, script and culture."_.
134
135 Consumers SHOULD provide this description to a the User when selecting and altering parameter values.
136
137 #### 3.2.3 `required`
138 * Value: `boolean`
139 * Default: `false`
140
141 Whether the template being described requires this parameter to be present in order to function properly. For example, a template used to render a hyperlink to a book viewer might mark its "ISBN" parameter as required, whereas it might consider a parameter "publication date" to be optional.
142
143 Authors SHOULD only set this flag if the template will not function correctly without this parameter being set.
144
145 Consumers SHOULD encourage the User to fill in these parameters, and MAY prevent users from transcluding a template when a required parameter has not been set.
146
147 #### 3.2.4 `suggested`
148 * Value: `boolean`
149 * Default: `false`
150
151 Whether the parameter is recommended to be set to an explicit value for the template transclusion to be useful. This status is less strong an indicator than `required`. For example, in a book template the author's name might be `suggested`, whereas the title might be `required`.
152
153 Authors MUST NOT use `suggested` for parameters without which the template will not function correctly.
154
155 Consumers MAY encourage users to fill in a suggested parameter, but SHOULD NOT prevent users from transcluding a template when a suggested parameter is not set.
156
157 #### 3.2.5 `deprecated`
158 * Value: `boolean` or `string`
159 * Default: `false`
160
161 Whether this parameter is discouraged from usage. Seting to `false` indicates the parameter is not deprecated.
162
163 Authors are RECOMMENDED to, when marking a parameter as deprecated, provide a `string` of explanatory text describing why the parameter is deprecated (and what parameter or parameters the user should use instead). Alternatively, Authors MAY use the value `true` in absence of explanatory text.
164
165 #### 3.2.6 `aliases`
166 * Value: `Array` of `integer` or `string`
167 * Default: `[]`
168
169 An array of alternative names for the parameter.
170
171 Authors MUST NOT provide a `Param` object in `Root.params` for any alias. To describe a discouraged parameter with additional information, authors SHOULD describe the parameter as deprecated instead of alias.
172
173 Consumers SHOULD display aliases where entered as secondary to the primary name.
174
175 #### 3.2.7 `type`
176 * Value: `Type`, see 3.4
177
178 The kind of value the template expects to be associated with this parameter.
179
180 Consumers MAY provide user interfaces that restrict or simplify entering values based on the parameter type.
181
182 #### 3.2.8 `inherits`
183 * Value: `string`
184
185 The key of another parameter from which this parameter will inherit properties. Local properties will override the inherited properties.
186
187 Authors MUST ensure that the value matches the key of a `Param` object in `Root.params`.
188
189 #### 3.2.9 `autovalue`
190 * Value: `null` or `string`
191
192 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}}`.
193
194 Consumers MUST insert a parameter's autovalue by default if this parameter is used in a transclusion, and SHOULD indicate this value to the user and give them the opportunity to change the value.
195
196 #### 3.2.10 `default`
197 * Value: `null` or `InterfaceText`
198
199 The default value in wikitext (or description thereof) of a parameter as assumed by the template when the parameter is not present in a transclusion.
200
201 Consumers SHOULD indicate this default value to the user when inserting or editing a template.
202
203 #### 3.2.11 `suggestedvalues`
204 * Value: `Array` of `string`
205 * Default: `[]`
206
207 A list of commonly used, suggested values.
208
209 Consumers SHOULD provide this list to the user when filling out the field, but MAY implement suggested values only for some field types.
210
211 Consumers MUST allow the user to enter free-form values not on this list.
212
213 #### 3.2.12 `example`
214 * Value: `null` or `InterfaceText`
215
216 An example text for the parameter, to help users fill in the proper value.
217
218 ### 3.3 Set
219 * Value: `Object`
220
221 #### 3.3.1 label
222 * Required
223 * Value: `InterfaceText`
224
225 A label for this set.
226
227 Authors are RECOMMENDED to ensure these are unique and distinguishable from other labels.
228
229 #### 3.3.2 params
230 * Required
231 * Value: `Array` of `string`
232
233 A list of one or more `Root.params` keys.
234
235 ### 3.4 Type
236 * Value: `string`
237 * Default: `'unknown'`
238
239 One of the following:
240
241 - `unknown`<br/>
242 When no type is specified.
243 - `string`<br/>
244 Any textual value.
245 - `number`<br/>
246 Any numerical value (without decimal points or thousand separators).
247 - `boolean`<br/>
248 A boolean value ('1' for true, '0' for false, '' for unknown).
249 - `date`<br/>
250 A date in ISO 8601 format, e.g. "2014-05-09" or "2014-05-09T16:01:12Z".
251 - `url`<br/>
252 A URL, including protocol, e.g. "http://www.example.org",
253 "https://example.org", or "//example.org".
254 - `wiki-page-name`<br/>
255 A valid MediaWiki page name for the current wiki. Doesn't have to exist,
256 but if not, should be a valid page name to create.
257 - `wiki-user-name`<br/>
258 A valid MediaWiki user name for the current wiki. Doesn't have to exist,
259 but if not, should be a valid user name to create. Should not include any
260 localised or standard namespace prefix ("Foo" not "User:Foo").
261 - `wiki-file-name`<br/>
262 A valid MediaWiki file name for the current wiki. Doesn't have to exist,
263 but if not, should be a valid file name to upload. Should not include any
264 localised or standard namespace prefix ("Foo" not "File:Foo").
265 - `wiki-template-name`<br/>
266 A valid MediaWiki template name for the current wiki. Doesn't have to exist,
267 but if not, should be a valid template name to create. Should not include any
268 localised or standard namespace prefix ("Foo" not "Template:Foo").
269 - `content`<br/>
270 Page content (such as text style, links and images etc.).
271 - `unbalanced-wikitext`<br/>
272 Raw wikitext that should not be treated as standalone content because it
273 is unbalanced (eg. templates concatenating incomplete wikitext as a bigger
274 whole such as `{{echo|before=<u>|after=</u>}}`)
275 - `line`<br/>
276 Short text field - use for names, labels, and other short-form fields.
277
278 ### 3.5 InterfaceText
279 * Value: `string` or `Object`
280
281 A free-form string (no wikitext) in the content-language of the wiki, or,
282 an object containing those strings keyed by language code.
283
284 ### 3.6 Map
285 * Value: `Object`
286
287 Each key in a `Map` object can be arbitrary. The value must match a parameter name, a list of parameter names, or list containing lists of parameter names.
288
289 The key corresponds to the name of a Consumer variable that relates to the specified parameter(s).
290
291 ### 3.7 FormatString
292 * Value: `string`
293
294 A format string describes how whitespace should be added to a template instantiation in wikitext. A format string looks like `{{_|_=_}}`, with optional whitespace and extended underscores. Formally, its structure is given by the following grammar:
295 ```
296 FormatString = StartFormat ParameterFormat EndFormat
297 StartFormat = nl? "{{" ws* Hole
298 ParameterFormat = nl? ws* "|" nl? ws* Hole ws* "=" ws* Hole
299 EndFormat = nl? ws* "}}" nl?
300 Hole = "_"+
301 ws = " "
302 nl = "\n"
303 ```
304
305 To format a template invocation according to the format string, first split it in three parts, corresponding to `StartFormat`, `ParameterFormat`, and `EndFormat` in the grammar above. In the following, to "replace the `Hole`" with some value means to first pad a non-empty value with spaces on the right until it is at least as many characters long as the replaced underscore sequence. Zero-length values are not padded.
306
307 Begin with `StartFormat`, and replace the `Hole` with the name of the template to create the "output string". If `StartFormat` begins with a newline and template is already at the start of a line (the character preceding this template invocation is a newline or the template is at the start of the output), delete the initial newline from the output string.
308
309 For each parameter, if `ParameterFormat` begins with a newline and the last line in the output string is nothing but whitespace and comments, then delete the newline from the beginning of the `ParameterFormat`. Then append `ParameterFormat` to the output string after replacing the first `Hole` with the name of the parameter and the second `Hole` with the value of the parameter.
310
311 Finally, if `EndFormat` begins with a newline and the last line in the output string is nothing but whitespace and comments, then delete the newline from the beginning of the `EndFormat`. Or, if there were no parameters, also delete the newline from the beginning of the `EndFormat`. Append the `EndFormat` to the output string.
312
313 Some example format strings:
314
315 Inline formatting: `{{_|_=_}}`
316 ```
317 {{Foo|bar=baz|qux=quux}}{{Bar}}
318 ```
319
320 Block formatting: `{{_\n| _ = _\n}}`
321 ```
322 {{Foo
323 | bar = baz
324 | qux = quux
325 }}{{Bar}}
326 ```
327
328 No space before the parameter name, each template on its own line: `\n{{_\n|_ = _\n}}\n`
329 ```
330 {{Foo
331 |bar = baz
332 |qux = quux
333 }}
334 {{Bar}}
335 ```
336
337 Indent each parameter: `{{_\n |_ = _\n}}`
338 ```
339 {{Foo
340 |bar = baz
341 |qux = quux
342 }}{{Bar}}
343 ```
344
345 Align all parameter names to a given length: `{{_\n|_______________ = _\n}}\n`
346 ```
347 {{Foo
348 |bar = baz
349 |qux = quux
350 |veryverylongparameter = bat
351 }}
352 {{Bar}}
353 ```
354
355 Pipe characters at the end of the previous line: `{{_|\n _______________ = _}}`
356 ```
357 {{Foo|
358 bar = baz|
359 qux = quux}}{{Bar}}
360 ```
361
362 Inline style with more spaces, must be at start of line: `\n{{_ | _ = _}}`
363 ```
364 {{Foo | bar = baz | qux = quux}}
365 {{Bar }}
366 ```
367
368 ## 4 Examples
369
370 ### 4.1 The "Unsigned" template
371
372 ```json
373 {
374 "description": "Label unsigned comments in a conversation.",
375 "params": {
376 "user": {
377 "label": "User's name",
378 "type": "wiki-user-name",
379 "required": true,
380 "description": "User name of person who forgot to sign their comment.",
381 "aliases": ["1"]
382 },
383 "date": {
384 "label": "Date",
385 "suggested": true,
386 "description": {
387 "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."
388 },
389 "aliases": ["2"],
390 "autovalue": "{{subst:#time:Y-m-d}}"
391 },
392 "year": {
393 "label": "Year",
394 "type": "number"
395 },
396 "month": {
397 "label": "Month",
398 "inherits": "year"
399 },
400 "day": {
401 "label": "Day",
402 "inherits": "year"
403 },
404 "comment": {
405 "required": false
406 }
407 },
408 "sets": [
409 {
410 "label": "Date",
411 "params": ["year", "month", "day"]
412 }
413 ],
414 "maps": {
415 "ExampleConsumer": {
416 "foo": "user",
417 "bar": ["year", "month", "day"],
418 "quux": [
419 "date",
420 ["day", "month"],
421 ["month", "year"],
422 "year"
423 ]
424 }
425 }
426 }
427 ```
428
429 Example transclusions
430 ```
431 {{unsigned|JohnDoe|2012-10-18}}
432
433 {{unsigned|user=JohnDoe|year=2012|month=10|day=18|comment=blabla}}
434 ```