Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/303432
Change subject: Add new 'ownLine' property to control newlines around templates
......................................................................
Add new 'ownLine' property to control newlines around templates
Bug: T135667
Change-Id: I7e364be295140fbc982e44903e03c7f151ddb5f1
---
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.tdDialog.js
M resources/ext.templateData.css
8 files changed, 128 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/32/303432/1
diff --git a/Specification.md b/Specification.md
index c525778..6acddf0 100644
--- a/Specification.md
+++ b/Specification.md
@@ -111,6 +111,17 @@
In the absence of the parameter being set, the system will supply `null` as a
fallback value.
+### 3.1.7 `ownLine`
+* Value: `string` of either `'prefer'` or `'avoid'`
+* Default: `"avoid"`
+
+Whether the template SHOULD occur on a line of its own.
+
+If the parameter is set to `prefer`, a newly-added template SHOULD appear
+on its own line in wikitext. If the parameter is set to `avoid`, a
newly-added template SHOULD appear inline (with no surrounding newlines) in
wikitext. For both `prefer` and `avoid`, edited templates should maintain
their existing formatting, whether that is on its own line or not.
+
+In the absence of the parameter being set, the system will supply `"avoid"` as
a fallback value.
+
### 3.2 Param
* Value: `Object`
diff --git a/TemplateDataBlob.php b/TemplateDataBlob.php
index 25d1245..ad0603c 100644
--- a/TemplateDataBlob.php
+++ b/TemplateDataBlob.php
@@ -62,6 +62,7 @@
$tdb->data->params = new stdClass();
$tdb->data->paramOrder = [];
$tdb->data->format = null;
+ $tdb->data->ownLine = 'avoid';
$tdb->data->sets = [];
$tdb->data->maps = new stdClass();
}
@@ -99,6 +100,7 @@
'sets',
'maps',
'format',
+ 'ownLine',
];
static $paramKeys = [
@@ -134,6 +136,11 @@
static $formats = [
'block' => "| _ = _\n",
'inline' => '|_=_',
+ ];
+
+ static $ownLine = [
+ 'prefer',
+ 'avoid',
];
static $typeCompatMap = [
@@ -178,6 +185,18 @@
}
} else {
$data->format = null;
+ }
+
+ // Root.ownLine
+ if ( isset( $data->ownLine ) ) {
+ if ( !in_array( $data->ownLine, $ownLine ) ) {
+ return Status::newFatal(
+ 'templatedata-invalid-ownline',
+ 'ownLine'
+ );
+ }
+ } else {
+ $data->ownLine = 'avoid';
}
// Root.params
@@ -732,11 +751,24 @@
. Html::element(
'span',
[ 'class' =>
'mw-templatedata-format' ],
- // Messages:
templatedata-modal-format-inline, templatedata-modal-format-block
+ // Messages:
templatedata-doc-format-inline, templatedata-doc-format-block
wfMessage(
'templatedata-doc-format-' . $data->format )->inLanguage( $lang )->text()
)
) :
'' )
+ . ( $data->ownLine !== null ?
+ Html::rawElement(
+ 'p',
+ [],
+ new OOUI\IconWidget( [ 'icon'
=> 'template-ownline-' . $data->ownLine ] )
+ . Html::element(
+ 'span',
+ [ 'class' =>
'mw-templatedata-ownline' ],
+ // Messages:
templatedata-doc-ownline-avoid, templatedata-doc-ownline-prefer
+ wfMessage(
'templatedata-doc-ownline-' . $data->ownLine )->inLanguage( $lang )->text()
+ )
+ ) :
+ '' )
)
. '<thead><tr>'
. Html::element(
diff --git a/extension.json b/extension.json
index 652b15d..81ae8e0 100644
--- a/extension.json
+++ b/extension.json
@@ -124,6 +124,8 @@
"templatedata-modal-format-inline",
"templatedata-modal-format-block",
"templatedata-modal-format-null",
+ "templatedata-modal-ownline-avoid",
+ "templatedata-modal-ownline-prefer",
"templatedata-modal-json-error-replace",
"templatedata-modal-notice-import-numparams",
"templatedata-modal-placeholder-paramkey",
diff --git a/i18n/en.json b/i18n/en.json
index db975bc..16e6aa8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -54,6 +54,7 @@
"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-ownline": "Property \"$1\" is expected to be
\"avoid\", or \"prefer\".",
"templatedata-invalid-param": "Invalid parameter \"$1\" for property
\"$2\".",
"templatedata-invalid-parse": "Syntax error in JSON.",
"templatedata-invalid-type": "Property \"$1\" is expected to be of type
\"$2\".",
@@ -79,6 +80,8 @@
"templatedata-modal-format-null": "Unspecified",
"templatedata-modal-json-error-replace": "Replace",
"templatedata-modal-notice-import-numparams": "$1 new
{{PLURAL:$1|parameter was|parameters were}} imported: $2",
+ "templatedata-modal-ownline-avoid": "Avoid",
+ "templatedata-modal-ownline-prefer": "Prefer",
"templatedata-modal-placeholder-paramkey": "Parameter name",
"templatedata-modal-search-input-placeholder": "Search by language name
or code",
"templatedata-modal-table-param-actions": "Actions",
@@ -104,6 +107,7 @@
"templatedata-modal-title-paramorder": "Parameter order",
"templatedata-modal-title-templatedesc": "Template description ($1)",
"templatedata-modal-title-templateformat": "Template preferred format",
+ "templatedata-modal-title-templateownline": "Template on its own line",
"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 8efd35d..335a47c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -64,6 +64,7 @@
"templatedata-invalid-format": "{{Doc-important|Don't translate
\"inline\" and \"block\".}}\n\nError message when format property gets an
unexpected value.",
"templatedata-invalid-length": "Error message when generated JSON's
length exceed database limits.\n* $1 - length of generated JSON\n* $2 - maximal
allowed length",
"templatedata-invalid-missing": "Error message when a required property
is not found.\n* $1 - name of property. e.g. \"params\"\n* $2 - type of
property (Unused)",
+ "templatedata-invalid-ownline": "{{Doc-important|Don't translate
\"avoid\" and \"prefer\".}}\n\nError message when ownLine property gets an
unexpected value.",
"templatedata-invalid-param": "Error message for when the supplied
parameter is invalid.\n* $1 - name of parameter. e.g. \"username\"\n* $2 - name
of property. e.g. maps property \"applicationUser\"",
"templatedata-invalid-parse": "Error message when there is a syntax
error in JSON.",
"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\"",
@@ -89,6 +90,8 @@
"templatedata-modal-format-null": "Label for null
format\n{{Identical|Unspecified}}",
"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-ownline-avoid": "Label for \"avoid\" value for
\"own line\" property\n{{Identical|Avoid}}",
+ "templatedata-modal-ownline-prefer": "Label for \"prefer\" value for
\"own line\" property\n{{Identical|Prefer}}",
"templatedata-modal-placeholder-paramkey": "Placeholder for the input
that contains new parameter name in the add parameter panel in the edit
dialog.",
"templatedata-modal-search-input-placeholder": "Placeholder text for
language search panel.",
"templatedata-modal-table-param-actions": "Label for a parameter
property input: Parameter actions in the table\n{{Identical|Action}}",
@@ -114,6 +117,7 @@
"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-templateownline": "The title for the template
preferred \"own line\" property",
"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 ffe0cfc..dc068d3 100644
--- a/modules/ext.templateDataGenerator.data.js
+++ b/modules/ext.templateDataGenerator.data.js
@@ -18,6 +18,7 @@
this.description = {};
this.paramOrder = [];
this.format = null;
+ this.ownLine = "avoid";
this.paramOrderChanged = false;
this.paramIdentifierCounter = 0;
this.originalTemplateDataObject = null;
@@ -280,6 +281,10 @@
if ( tdObject.format !== undefined ) {
model.setTemplateFormat( tdObject.format );
+ }
+
+ if ( tdObject.ownLine !== undefined ) {
+ model.setTemplateOwnLine( tdObject.ownLine );
}
return model;
@@ -588,6 +593,22 @@
};
/**
+ * Set template "own line" property.
+ *
+ * @param {string} [ownLine="avoid"] Preferred "own line" property
+ * @fires change-format
+ * @fires change
+ */
+mw.TemplateData.Model.prototype.setTemplateOwnLine = function ( ownLine ) {
+ ownLine = ownLine !== undefined ? ownLine : "avoid";
+ if ( this.ownLine !== ownLine ) {
+ this.ownLine = ownLine;
+ this.emit( 'change-ownLine', ownLine );
+ this.emit( 'change' );
+ }
+};
+
+/**
* Add a key to the end of the paramOrder
*
* @param {string} key New key the add into the paramOrder
@@ -659,6 +680,15 @@
};
/**
+ * Retrieve the template preferred "own line" property
+ *
+ * @return {string} Preferred "own line" property
+ */
+mw.TemplateData.Model.prototype.getTemplateOwnLine = function () {
+ return this.ownLine;
+};
+
+/**
* Set a specific parameter's property
*
* @param {string} paramKey Parameter key
diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js
b/modules/ext.templateDataGenerator.ui.tdDialog.js
index 5db076e..8f719dd 100644
--- a/modules/ext.templateDataGenerator.ui.tdDialog.js
+++ b/modules/ext.templateDataGenerator.ui.tdDialog.js
@@ -81,7 +81,7 @@
* @chainable
*/
mw.TemplateData.Dialog.prototype.initialize = function () {
- var templateParamsFieldset, addParamFieldlayout,
languageActionFieldLayout, templateFormatFieldSet;
+ var templateParamsFieldset, addParamFieldlayout,
languageActionFieldLayout, templateFormatFieldSet, templateOwnLineFieldSet;
// Parent method
mw.TemplateData.Dialog.super.prototype.initialize.call( this );
@@ -174,6 +174,25 @@
} );
templateFormatFieldSet.$element.append(
this.templateFormatSelectWidget.$element );
+ this.templateOwnLineSelectWidget = new OO.ui.ButtonSelectWidget();
+ this.templateOwnLineSelectWidget.addItems( [
+ new OO.ui.ButtonOptionWidget( {
+ data: 'avoid',
+ icon: 'template-ownline-avoid',
+ label: mw.msg( 'templatedata-modal-ownline-avoid' )
+ } ),
+ new OO.ui.ButtonOptionWidget( {
+ data: 'prefer',
+ icon: 'template-ownline-prefer',
+ label: mw.msg( 'templatedata-modal-ownline-prefer' )
+ } )
+ ] );
+
+ templateOwnLineFieldSet = new OO.ui.FieldsetLayout( {
+ label: mw.msg( 'templatedata-modal-title-templateownline' )
+ } );
+ templateOwnLineFieldSet.$element.append(
this.templateOwnLineSelectWidget.$element );
+
// Param details panel
this.$paramDetailsContainer = $( '<div>' )
.addClass( 'tdg-templateDataDialog-paramDetails' );
@@ -185,6 +204,7 @@
languageActionFieldLayout.$element,
this.templateDescriptionFieldset.$element,
templateFormatFieldSet.$element,
+ templateOwnLineFieldSet.$element,
templateParamsFieldset.$element
);
this.paramEditNoticeLabel = new OO.ui.LabelWidget();
@@ -237,6 +257,7 @@
} );
this.paramImport.connect( this, { click:
'importParametersFromTemplateCode' } );
this.templateFormatSelectWidget.connect( this, { choose:
'onTemplateFormatSelectWidgetChoose' } );
+ this.templateOwnLineSelectWidget.connect( this, { choose:
'onTemplateOwnLineSelectWidgetChoose' } );
};
@@ -421,6 +442,15 @@
*/
mw.TemplateData.Dialog.prototype.onTemplateFormatSelectWidgetChoose = function
( item ) {
this.model.setTemplateFormat( item.getData() );
+};
+
+/**
+ * Respond to choose event from the template own line select widget
+ *
+ * @param {OO.ui.OptionWidget} item "Own line" item
+ */
+mw.TemplateData.Dialog.prototype.onTemplateOwnLineSelectWidgetChoose =
function ( item ) {
+ this.model.setTemplateOwnLine( item.getData() );
};
mw.TemplateData.Dialog.prototype.onParamPropertyInputChange = function (
property, value ) {
@@ -866,6 +896,9 @@
// XXX needs to reflect new widget type
this.templateFormatSelectWidget.selectItemByData(
this.model.getTemplateFormat() );
+ // Set up "own line"
+ this.templateOwnLineSelectWidget.selectItemByData(
this.model.getTemplateOwnLine() );
+
// Repopulate the parameter list
this.repopulateParamSelectWidget();
};
diff --git a/resources/ext.templateData.css b/resources/ext.templateData.css
index 2e06095..e8f46c6 100644
--- a/resources/ext.templateData.css
+++ b/resources/ext.templateData.css
@@ -41,3 +41,13 @@
/* @embed */
background-image: url( ../modules/images/inline.svg );
}
+
+.oo-ui-icon-template-ownline-avoid {
+ /* @embed */
+ background-image: url( ../modules/images/inline.svg );
+}
+
+.oo-ui-icon-template-ownline-prefer {
+ /* @embed */
+ background-image: url( ../modules/images/block-ltr.svg );
+}
--
To view, visit https://gerrit.wikimedia.org/r/303432
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7e364be295140fbc982e44903e03c7f151ddb5f1
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