Eranroz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243138
Change subject: Introducing template format
......................................................................
Introducing template format
Adding format for template data, which defines the preffered format for
template.
Possible formats:
* Inline - all parameters in single line
* Block - Each paramter is in its own line
Bug: T64217
Change-Id: Id856c4a38890526060d0619432f06174d66f7792
---
M Specification.md
M TemplateDataBlob.php
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/ext.templateDataGenerator.data.js
M modules/ext.templateDataGenerator.ui.js
M modules/ext.templateDataGenerator.ui.tdDialog.js
8 files changed, 113 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/38/243138/1
diff --git a/Specification.md b/Specification.md
index 6a361a3..107551e 100644
--- a/Specification.md
+++ b/Specification.md
@@ -97,6 +97,9 @@
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: `inline` or `block`
+
### 3.2 Param
* Value: `Object`
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index f05aa16..db75ab1 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -47,6 +47,7 @@
$tdb->data->description = null;
$tdb->data->params = new stdClass();
$tdb->data->paramOrder = array();
+ $tdb->data->format = 'inline';
$tdb->data->sets = array();
$tdb->data->maps = new stdClass();
}
@@ -83,6 +84,7 @@
'paramOrder',
'sets',
'maps',
+ 'format',
);
static $paramKeys = array(
@@ -115,6 +117,11 @@
'wiki-template-name',
);
+ static $formats = array(
+ 'block',
+ 'inline'
+ );
+
static $typeCompatMap = array(
'string/line' => 'line',
'string/wiki-page-name' => 'wiki-page-name',
@@ -144,6 +151,19 @@
$data->description = self::normaliseInterfaceText(
$data->description );
} else {
$data->description = null;
+ }
+
+ // Root.format
+ if ( isset( $data->format ) ) {
+ if ( !in_array( $data->format, $formats ) ) {
+ return Status::newFatal(
+ 'templatedata-invalid-value',
+ 'format'
+ );
+ $data->format = self::normaliseInterfaceText(
$data->format );
+ }
+ } else {
+ $data->format = 'inline';
}
// Root.params
@@ -674,6 +694,16 @@
$data->description :
wfMessage(
'templatedata-doc-desc-empty' )->inLanguage( $lang )->text()
)
+ . Html::element(
+ 'p',
+ array(
+ 'class' => array(
+ 'mw-templatedata-doc-format',
+ 'mw-templatedata-doc-muted' =>
$data->format === null,
+ )
+ ),
+ wfMessage( 'templatedata-doc-format-' .
$data->format )->inLanguage( $lang )->text()
+ )
. '<table class="wikitable mw-templatedata-doc-params
sortable">'
. Html::element(
'caption',
diff --git a/extension.json b/extension.json
index 48d1d01..c782b67 100644
--- a/extension.json
+++ b/extension.json
@@ -111,6 +111,8 @@
"templatedata-modal-errormsg",
"templatedata-modal-errormsg-import-noparams",
"templatedata-modal-errormsg-import-paramsalreadyexist",
+ "templatedata-modal-format-inline",
+ "templatedata-modal-format-block",
"templatedata-modal-json-error-replace",
"templatedata-modal-notice-import-numparams",
"templatedata-modal-placeholder-paramkey",
@@ -151,6 +153,7 @@
"templatedata-modal-title-language",
"templatedata-modal-title-paramorder",
"templatedata-modal-title-templatedesc",
+ "templatedata-modal-title-templateformat",
"templatedata-modal-title-templateparam-details",
"templatedata-modal-title-templateparams",
"templatedata-helplink",
diff --git a/i18n/en.json b/i18n/en.json
index 816141a..44539fe 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -13,6 +13,8 @@
"apihelp-templatedata-param-lang": "Return localized values in this
language. By default all available translations are returned.",
"templatedata-desc": "Implement data storage for template parameters
(using JSON)",
"templatedata-doc-desc-empty": "No description.",
+ "templatedata-doc-format-inline": "Inline format template",
+ "templatedata-doc-format-block": "Block format template",
"templatedata-doc-no-params-set": "No parameters specified",
"templatedata-doc-param-autovalue": "Auto value",
"templatedata-doc-param-autovalue-empty": "empty",
@@ -59,6 +61,8 @@
"templatedata-modal-errormsg": "Errors found. Please make sure there
are no empty or duplicate parameter names, and that the parameter name does not
include \"$1\", \"$2\" or \"$3\".",
"templatedata-modal-errormsg-import-noparams": "No new parameters found
during import.",
"templatedata-modal-errormsg-import-paramsalreadyexist":
"{{PLURAL:$1|One parameter was not imported, because it already exists|Some
parameters were not imported, because they already exist}} in the editor: $1",
+ "templatedata-modal-format-inline": "Inline",
+ "templatedata-modal-format-block": "Block",
"templatedata-modal-json-error-replace": "Replace",
"templatedata-modal-notice-import-numparams": "$1 new
{{PLURAL:$1|parameter was|parameters were}} imported: $2",
"templatedata-modal-placeholder-paramkey": "Parameter name",
@@ -98,6 +102,7 @@
"templatedata-modal-title-language": "Language",
"templatedata-modal-title-paramorder": "Parameter order",
"templatedata-modal-title-templatedesc": "Template description ($1)",
+ "templatedata-modal-title-templateformat": "Template preferred format",
"templatedata-modal-title-templateparam-details": "Parameter details:
$1",
"templatedata-modal-title-templateparams": "Template parameters"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 67c8a3d..50fb64c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -22,6 +22,8 @@
"apihelp-templatedata-param-lang":
"{{doc-apihelp-param|templatedata|lang}}",
"templatedata-desc": "{{desc|name=Template
Data|url=https://www.mediawiki.org/wiki/Extension:TemplateData}}",
"templatedata-doc-desc-empty": "Displayed when a template has no
description (should be a valid sentence).\n{{Identical|No description}}",
+ "templatedata-doc-format-inline": "Display the preffered format for a
template as inline",
+ "templatedata-doc-format-block": "Display the preffered format for a
template as block",
"templatedata-doc-no-params-set": "A message shown when there are no
parameters set in the TemplateData string.",
"templatedata-doc-param-autovalue": "Used as column heading in the
table for auto fill value.\n{{Related|Templatedata-doc-param}}",
"templatedata-doc-param-autovalue-empty": "Displayed when a template
parameter has no auto filled value (should not be a full sentence, used in a
table).\n{{Identical|Empty}}",
@@ -68,6 +70,8 @@
"templatedata-modal-errormsg": "Error message that appears in the
TemplateData generator GUI in case there are empty, duplicate or invalid
parameter names.\n\nInvalid characters are supplied as parameters to avoid
parsing errors in translation strings.\n\nParameters:\n* $1 - pipe
(<code>|</code>)\n* $2 - equal sign (<code>=</code>)\n* $3 - double curly
brackets (<code><nowiki>}}</nowiki></code>)",
"templatedata-modal-errormsg-import-noparams": "Error message that
appears in the TemplateData generator GUI in case no template parameters were
found during the import attempt.",
"templatedata-modal-errormsg-import-paramsalreadyexist": "Error message
that appears when some parameters were not imported from the template code
because they already exist in the editor.\n\nParameters:\n* $1 - list of
parameters that were not imported",
+ "templatedata-modal-format-inline": "Label for inline format",
+ "templatedata-modal-format-block": "Label for block format",
"templatedata-modal-json-error-replace": "Label for the button in the
error message, agreeing to replace the existing faulty TemplateData string with
a new one.\n{{Identical|Replace}}",
"templatedata-modal-notice-import-numparams": "Message that appears in
the TemplateData generator GUI showing how many new parameters were imported
into the GUI from an existing template.\n\nParameters:\n* $1 - number of
parameters\n* $2 - list of parameters that were imported",
"templatedata-modal-placeholder-paramkey": "Placeholder for the input
that contains new parameter name in the add parameter panel in the edit
dialog.",
@@ -107,6 +111,7 @@
"templatedata-modal-title-language": "Label for the language dropdown
in the edit menu.\n{{Identical|Language}}",
"templatedata-modal-title-paramorder": "The title for the parameter
order drag/drop widget in the edit dialog.",
"templatedata-modal-title-templatedesc": "The title for the template
description textbox. Parameters:\n* $1 - currently used language",
+ "templatedata-modal-title-templateformat": "The title for the template
preferred format",
"templatedata-modal-title-templateparam-details": "The title for the
parameter information section. Parameters:\n* $1 - The parameter name",
"templatedata-modal-title-templateparams": "The title for the template
parameters table\nof a single template."
}
diff --git a/modules/ext.templateDataGenerator.data.js
b/modules/ext.templateDataGenerator.data.js
index f9bc25b..6513d70 100644
--- a/modules/ext.templateDataGenerator.data.js
+++ b/modules/ext.templateDataGenerator.data.js
@@ -16,9 +16,9 @@
this.params = {};
this.description = {};
this.paramOrder = [];
+ this.format = 'inline';
this.paramOrderChanged = false;
this.paramIdentifierCounter = 0;
-
this.originalTemplateDataObject = null;
this.sourceCodeParameters = [];
};
@@ -265,6 +265,10 @@
// Override the param order if it exists in the templatedata string
if ( tdObject.paramOrder && tdObject.paramOrder.length > 0 ) {
model.setTemplateParamOrder( tdObject.paramOrder );
+ }
+
+ if ( tdObject.format ) {
+ model.setTemplateFormat( tdObject.format );
}
return model;
@@ -538,6 +542,17 @@
};
/**
+ * Set template format.
+ * @param {string} preferred format. Defaults on 'inline'.
+ * @fires change-format
+ */
+mw.TemplateData.Model.prototype.setTemplateFormat = function ( format ) {
+ format = format || 'inline';
+ this.format = format;
+ this.emit( 'change-format', format );
+};
+
+/**
* Add a key to the end of the paramOrder
* @param {string} key New key the add into the paramOrder
* @fires add-paramOrder
@@ -582,6 +597,14 @@
*/
mw.TemplateData.Model.prototype.getTemplateParamOrder = function () {
return this.paramOrder;
+};
+
+/**
+ * Retrieve the template preffered format
+ * @return {string} preferred format
+ */
+mw.TemplateData.Model.prototype.getTemplateFormat = function () {
+ return this.format;
};
/**
@@ -800,6 +823,13 @@
delete result.paramOrder;
}
+ // Format
+ if ( original.format || this.format ) {
+ result.format = this.format;
+ } else {
+ delete result.format;
+ }
+
// Attach sets as-is for now
// TODO: Work properly with sets
if ( original.sets ) {
diff --git a/modules/ext.templateDataGenerator.ui.js
b/modules/ext.templateDataGenerator.ui.js
index d0cc9a8..03b557f 100644
--- a/modules/ext.templateDataGenerator.ui.js
+++ b/modules/ext.templateDataGenerator.ui.js
@@ -101,7 +101,7 @@
if ( data &&
data.action === 'accept' ) {
// Open
the dialog with an empty model
model =
new mw.TemplateData.Model.static.newFromObject(
-
{ params: {} },
+
{ params: {}, format: 'inline' },
sourceHandler.getTemplateSourceCodeParams()
);
openEditDialog( model );
diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js
b/modules/ext.templateDataGenerator.ui.tdDialog.js
index d751cb7..43877c2 100644
--- a/modules/ext.templateDataGenerator.ui.tdDialog.js
+++ b/modules/ext.templateDataGenerator.ui.tdDialog.js
@@ -78,7 +78,7 @@
*/
mw.TemplateData.Dialog.prototype.initialize = function () {
var templateParamsFieldset, addParamFieldlayout,
languageActionFieldLayout,
- paramOrderFieldset;
+ paramOrderFieldset, templateFormatFieldSet;
// Parent method
mw.TemplateData.Dialog.super.prototype.initialize.call( this );
@@ -120,6 +120,7 @@
this.languagePanelButton = new OO.ui.ButtonWidget( {
label: mw.msg( 'templatedata-modal-button-add-language' )
} );
+
languageActionFieldLayout = new OO.ui.ActionFieldLayout(
this.languageDropdownWidget,
this.languagePanelButton,
@@ -154,6 +155,24 @@
} );
templateParamsFieldset.$element.append( this.paramSelectWidget.$element
);
+ this.templateFormatSelectWidget = new OO.ui.ButtonSelectWidget();
+ this.templateFormatSelectWidget.addItems( [
+ // TODO: add nice icons?
+ new OO.ui.ButtonOptionWidget( {
+ data: 'inline',
+ label: mw.msg( 'templatedata-modal-format-inline' )
+ } ),
+ new OO.ui.ButtonOptionWidget( {
+ data: 'block',
+ label: mw.msg( 'templatedata-modal-format-block' )
+ } ),
+ ] );
+
+ templateFormatFieldSet = new OO.ui.FieldsetLayout( {
+ label: mw.msg( 'templatedata-modal-title-templateformat' )
+ } );
+ templateFormatFieldSet.$element.append(
this.templateFormatSelectWidget.$element );
+
// Param details panel
this.$paramDetailsContainer = $( '<div>' )
.addClass( 'tdg-TemplateDataDialog-paramDetails' );
@@ -165,7 +184,8 @@
languageActionFieldLayout.$element,
this.templateDescriptionFieldset.$element,
paramOrderFieldset.$element,
- templateParamsFieldset.$element
+ templateParamsFieldset.$element,
+ templateFormatFieldSet.$element
);
this.paramEditNoticeLabel = new OO.ui.LabelWidget();
this.paramEditNoticeLabel.$element.hide();
@@ -213,6 +233,8 @@
this.languagePanelButton.connect( this, { click:
'onLanguagePanelButton' } );
this.languageDropdownWidget.getMenu().connect( this, { select:
'onLanguageDropdownWidgetSelect' } );
this.paramSelectWidget.connect( this, { choose:
'onParamSelectWidgetChoose' } );
+ this.templateFormatSelectWidget.connect( this, { choose:
'onTemplateFormatSelectWidgetChoose' } );
+
};
/**
@@ -407,6 +429,13 @@
this.getParameterDetails( paramKey );
this.switchPanels( 'editParam' );
}
+};
+/**
+ * Respond to choose event from the template format select widget
+ * @param {OO.ui.OptionWidget} item Format item
+ */
+mw.TemplateData.Dialog.prototype.onTemplateFormatSelectWidgetChoose = function
( item ) {
+ this.model.setTemplateFormat( item.getData() );
};
mw.TemplateData.Dialog.prototype.onParamPropertyInputChange = function (
property, value ) {
@@ -843,6 +872,10 @@
mw.TemplateData.Dialog.prototype.setupDetailsFromModel = function () {
// Set up description
this.descriptionInput.setValue( this.model.getTemplateDescription(
this.language ) );
+
+ // Set up format
+ this.templateFormatSelectWidget.selectItemByData(
this.model.getTemplateFormat() );
+
// Repopulate the parameter list
this.repopulateParamSelectWidget();
};
--
To view, visit https://gerrit.wikimedia.org/r/243138
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id856c4a38890526060d0619432f06174d66f7792
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Eranroz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits