Alex Monk has uploaded a new change for review.
https://gerrit.wikimedia.org/r/263655
Change subject: [WIP] Add a parameter key to limit possible valid values to a
given set
......................................................................
[WIP] Add a parameter key to limit possible valid values to a given set
Bug: T53375
Change-Id: I02918f85726f792bc1a25169ccfc32acc662a31e
---
M Specification.md
M TemplateDataBlob.php
M i18n/en.json
M i18n/qqq.json
M modules/ext.templateDataGenerator.data.js
5 files changed, 59 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/55/263655/1
diff --git a/Specification.md b/Specification.md
index 0ac3ee1..6a317fa 100644
--- a/Specification.md
+++ b/Specification.md
@@ -214,6 +214,13 @@
An example text for the parameter, to help users fill in the proper value.
+#### 3.2.12 `values`
+* Value: `null` or `array`
+
+If array, all of values must be of the same type.
+
+An array of all possible values for the parameter.
+
### 3.3 Set
* Value: `Object`
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index 839afe3..0ecf925 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -99,6 +99,7 @@
'default',
'inherits',
'type',
+ 'values',
);
static $types = array(
@@ -294,6 +295,32 @@
}
} else {
$paramObj->aliases = array();
+ }
+
+ // Param.values
+ if ( isset( $paramObj->values ) ) {
+ if ( !is_array( $paramObj->values ) ) {
+ return Status::newFatal(
+ 'templatedata-invalid-type',
+ "params.{$paramName}.values",
+ 'array'
+ );
+ }
+ $type = null;
+ // TODO: I think we should actually be
comparing against the 'type' key here
+ foreach ( $paramObj->values as $val ) {
+ if ( $type === null ) {
+ $type = gettype( $val );
+ wfDebugLog( 'debug', 'type: ' .
$type );
+ } elseif ( gettype( $val ) !== $type ) {
+ return Status::newFatal(
+
'templatedata-invalid-values',
+
"params.{$paramName}.values"
+ );
+ }
+ }
+ } else {
+ $paramObj->values = null;
}
// Param.autovalue
@@ -733,6 +760,11 @@
. Html::element(
'th',
array(),
+ wfMessage( 'templatedata-doc-param-values'
)->inLanguage( $lang )->text()
+ )
+ . Html::element(
+ 'th',
+ array(),
wfMessage( 'templatedata-doc-param-status'
)->inLanguage( $lang )->text()
)
. '</tr></thead>'
@@ -847,6 +879,19 @@
),
Html::element( 'code', array(), $paramObj->type
)
)
+ // Values
+ . Html::rawElement(
+ 'td',
+ array( 'class' => array(
'mw-templatedata-doc-param-values' ) ),
+ is_null( $paramObj->values ) ?
+ '<i>(unrestricted)</i>' : // TODO
+ '<ul>' . implode( "<br>", array_map(
+ function ( $val ) {
+ return '<li>' .
htmlspecialchars( $val ) . '</li>';
+ },
+ $paramObj->values
+ ) ) . '</ul>'
+ )
// Status
. Html::element( 'td', array(), wfMessage( $status
)->inLanguage( $lang )->text() )
. '</tr>';
diff --git a/i18n/en.json b/i18n/en.json
index 52532a3..bf60e82 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -31,6 +31,7 @@
"templatedata-doc-param-status-required": "required",
"templatedata-doc-param-status-suggested": "suggested",
"templatedata-doc-param-type": "Type",
+ "templatedata-doc-param-type": "Values",
"templatedata-doc-params": "Template parameters",
"templatedata-editbutton": "Manage TemplateData",
"templatedata-errormsg-jsonbadformat": "Bad JSON format. You can cancel
this operation so you can correct it, delete the current <templatedata> tags
and try again, or continue to replace the current TemplateData with a new one.",
@@ -47,6 +48,7 @@
"templatedata-invalid-type": "Property \"$1\" is expected to be of type
\"$2\".",
"templatedata-invalid-unknown": "Unexpected property \"$1\".",
"templatedata-invalid-value": "Invalid value for property \"$1\".",
+ "templatedata-invalid-values": "Property \"$1\" is expected to contain
values all of the same type.",
"templatedata-modal-button-add-language": "Add language",
"templatedata-modal-button-addparam": "Add parameter",
"templatedata-modal-button-apply": "Apply",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 209002c..eedd1f3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -41,6 +41,7 @@
"templatedata-doc-param-status-required": "Displayed when a template
parameter is required (should not be a full sentence, used in a
table).\n{{Identical|Required}}",
"templatedata-doc-param-status-suggested": "Displayed when a template
parameter is suggested (should not be a full sentence, used in a
table).\n{{Identical|Suggested}}",
"templatedata-doc-param-type": "{{Identical|Type}}",
+ "templatedata-doc-param-values": "Used as a column heading in the
table.\n{{Related|Templatedata-doc-param}}",
"templatedata-doc-params": "Used as caption for the table which
describes the parameter or parameters of the current template. If using plural
is an issue in your language, you may try and translate as \"Description of
each parameter\" or similar.\nThe table has the following headings:\n*
{{msg-mw|Templatedata-doc-param-name}}\n*
{{msg-mw|Templatedata-doc-param-desc}}\n*
{{msg-mw|Templatedata-doc-param-default}}\n*
{{msg-mw|Templatedata-doc-param-status}}\n{{Identical|Template parameter}}",
"templatedata-editbutton": "The label of the button to manage
templatedata, appearing above the editor field.",
"templatedata-errormsg-jsonbadformat": "Error message that appears in
case the JSON string is not possible to parse. The user is asked to choose
between correcting or deleting the json or continuing with the editing process
and replacing the string completely.",
@@ -57,6 +58,7 @@
"templatedata-invalid-type": "Error message when a property is of the
wrong type.\n* $1 - name of property. e.g. \"params.1.required\"\n* $2 -
expected type of property. e.g. \"boolean\"",
"templatedata-invalid-unknown": "Error message when an unknown property
is found.\n* $1 - name of property. e.g. \"params.1.foobar\"",
"templatedata-invalid-value": "Error message when a property that
cannot contain free-form text has an invalid value.\n* $1 - name of property.
e.g. \"params.1.type\"",
+ "templatedata-invalid-values": "Error message when the values property
(an array) contains multiple different types.\n* $1 - name of property, e.g.
\"params.1.values\"",
"templatedata-modal-button-add-language": "Label for the button to add
a language in the edit dialog.\n{{Identical|Add language}}",
"templatedata-modal-button-addparam": "Button to add a
parameter.\n{{Identical|Add parameter}}",
"templatedata-modal-button-apply": "Label of the apply
button.\n{{Identical|Apply}}",
diff --git a/modules/ext.templateDataGenerator.data.js
b/modules/ext.templateDataGenerator.data.js
index 7bf85f5..f33eddf 100644
--- a/modules/ext.templateDataGenerator.data.js
+++ b/modules/ext.templateDataGenerator.data.js
@@ -154,6 +154,9 @@
],
'default': 'undefined'
},
+ values: {
+ type: 'array'
+ },
'default': {
type: 'string',
multiline: true,
--
To view, visit https://gerrit.wikimedia.org/r/263655
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I02918f85726f792bc1a25169ccfc32acc662a31e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits