Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/303431
Change subject: WIP: Extend 'format' spec to include format strings.
......................................................................
WIP: Extend 'format' spec to include format strings.
TODO: validate format strings, use appropriate UI widget.
Bug: T114445
Change-Id: Ic7cfe0560efe72ff4058134bd6d3fd97b21ba5ed
---
M Specification.md
M TemplateDataBlob.php
M i18n/en.json
M modules/ext.templateDataGenerator.ui.tdDialog.js
4 files changed, 71 insertions(+), 19 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/31/303431/1
diff --git a/Specification.md b/Specification.md
index 3929441..c525778 100644
--- a/Specification.md
+++ b/Specification.md
@@ -98,25 +98,14 @@
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.
#### 3.1.6 `format`
-* Value: `null` or `string` of either `'inline'` or `'block'`
+* Value: `null` or `FormatString` or `string` of either `'inline'` or `'block'`
* Default: `null`
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.
-If the parameter is set to `'block'`, Consumers SHOULD create a wikitext
representation with a single newline after the template invocation and each
parameter value, a single space between each pipe and its subsequent parameter
key, and a space either side of the assignment separator between the parameter
key and value, like so:
+If the parameter is set to `'block'`, it MUST be interpreted as the format
string `'| _ = _\n'`. If the parameter is set to `'inline'` it MUST be
interpreted as the format string `'|_=_'`.
-```
-{{Foo
-| bar = baz
-| qux = quux
-}}
-```
-
-If the parameter is set to `'inline'`, Consumers SHOULD create a wikitext
representation with no whitespace, like so:
-
-```
-{{Foo|bar=baz|qux=quux}}
-```
+If the parameter is not null, Consumers SHOULD create a wikitext
representation corresponding to the given format string, as described in
section 3.7.
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.
@@ -289,6 +278,67 @@
The key corresponds to the name of a Consumer variable that relates to the
specified parameter(s).
+### 3.7 FormatString
+* Value: `string`
+
+A format string describes how whitespace should be added to template
parameters in wikitext. A format string contains the characters `|_=_` (in
that order), where additional space characters may occur at the beginning of
the string, end of the string, and/or between any of the elements. Each
underscore character may additionally be replaced with a series of consecutive
underscores. In addition, a newline character can occur either at the end of
the string or after the vertical bar symbol.
+
+To format a parameter according to the format string, you would replace the
first (second) sequence of underscores with the name (value) of the parameter.
If there replaced sequence is more than a single underscore, the name or value
is padded with spaces on the right until it is at least as many characters long
as the replaced underscore sequence. (A single underscore does not create an
extra space when the parameter value is empty.)
+
+If the format string ends with a newline, an extra newline is added between
the template name and the first parameter. If there is a newline somewhere in
the format string, the closing }} is always put on an extra line, no matter
what the format string says (but two sequential newlines should never be
generated).
+
+Some example format strings:
+
+Inline formatting: `|_=_`
+```
+{{Foo|bar=baz|qux=quux}}
+```
+
+Block formatting: `| _ = _\n`
+```
+{{Foo
+| bar = baz
+| qux = quux
+}}
+```
+
+No space before the parameter name: `|_ = _\n`
+```
+{{Foo
+|bar = baz
+|qux = quux
+}}
+```
+
+Indent each parameter: ` |_ = _\n`
+```
+{{Foo
+ |bar = baz
+ |qux = quux
+}}
+```
+
+Align all parameter names to a given length: `|_______________ = _\n`
+```
+{{Foo
+|bar = baz
+|qux = quux
+|veryverylongparameter = bat
+}}
+```
+
+Pipe characters at the end of the previous line: `|\n_ = _`
+```
+{{Foo|
+bar = baz|
+qux = quux}}
+```
+
+Inline style with more spaces: ` | _ = _`
+```
+{{Foo | bar = baz | qux = quux}}
+```
+
## 4 Examples
### 4.1 The "Unsigned" template
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index b8c8078..25d1245 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -132,9 +132,8 @@
];
static $formats = [
- null,
- 'block',
- 'inline'
+ 'block' => "| _ = _\n",
+ 'inline' => '|_=_',
];
static $typeCompatMap = [
@@ -170,7 +169,8 @@
// Root.format
if ( isset( $data->format ) ) {
- if ( !in_array( $data->format, $formats ) ) {
+ // XXX NEED TO VALIDATE FORMAT STRINGS
+ if ( !in_array( $data->format, $formats ) ||
!is_string( $data->format )
return Status::newFatal(
'templatedata-invalid-format',
'format'
diff --git a/i18n/en.json b/i18n/en.json
index 0cbc992..db975bc 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -51,7 +51,7 @@
"templatedata-helplink-target":
"//www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData",
"templatedata-invalid-duplicate-value": "Property \"$1\" (\"$3\") is a
duplicate of \"$2\".",
"templatedata-invalid-empty-array": "Property \"$1\" must have at least
one value in its array.",
- "templatedata-invalid-format": "Property \"$1\" is expected to be
\"inline\" or \"block\".",
+ "templatedata-invalid-format": "Property \"$1\" is expected to be
\"inline\", \"block\", or a valid format string.",
"templatedata-invalid-length": "Data too large to save
({{formatnum:$1}} {{PLURAL:$1|byte|bytes}}, {{PLURAL:$2|limit is}}
{{formatnum:$2}})",
"templatedata-invalid-missing": "Required property \"$1\" not found.",
"templatedata-invalid-param": "Invalid parameter \"$1\" for property
\"$2\".",
diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js
b/modules/ext.templateDataGenerator.ui.tdDialog.js
index 0883dbc..5db076e 100644
--- a/modules/ext.templateDataGenerator.ui.tdDialog.js
+++ b/modules/ext.templateDataGenerator.ui.tdDialog.js
@@ -150,6 +150,7 @@
this.paramImport = new mw.TemplateData.ParamImportWidget();
templateParamsFieldset.$element.append( this.paramSelect.$element,
this.paramImport.$element );
+ // XXX need a widget that lets you enter a text string.
this.templateFormatSelectWidget = new OO.ui.ButtonSelectWidget();
this.templateFormatSelectWidget.addItems( [
new OO.ui.ButtonOptionWidget( {
@@ -862,6 +863,7 @@
this.descriptionInput.setValue( this.model.getTemplateDescription(
this.language ) );
// Set up format
+ // XXX needs to reflect new widget type
this.templateFormatSelectWidget.selectItemByData(
this.model.getTemplateFormat() );
// Repopulate the parameter list
--
To view, visit https://gerrit.wikimedia.org/r/303431
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7cfe0560efe72ff4058134bd6d3fd97b21ba5ed
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits