Mooeypoo has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194748
Change subject: Add optional text to deprecated property
......................................................................
Add optional text to deprecated property
The deprecated property allows for either a boolean or text, so we
should allow the user to insert guidance text in case that property
is true. To achieve that, the model also defines 'textValue'
for boolean properties with text representation so an internal
property can be set to hold that value and inputs can be
automatically built from the property structure.
Bug: T90734
Change-Id: Iadc6abdcc0cf2721a311cf43847b306cb269b5e8
---
M TemplateData.php
M i18n/en.json
M i18n/qqq.json
M modules/ext.templateDataGenerator.data.js
M modules/ext.templateDataGenerator.ui.tdDialog.js
5 files changed, 84 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData
refs/changes/48/194748/1
diff --git a/TemplateData.php b/TemplateData.php
index 8b361c2..66cebbc 100644
--- a/TemplateData.php
+++ b/TemplateData.php
@@ -129,6 +129,7 @@
'templatedata-modal-table-param-autovalue',
'templatedata-modal-table-param-default',
'templatedata-modal-table-param-deprecated',
+ 'templatedata-modal-table-param-deprecatedValue',
'templatedata-modal-table-param-description',
'templatedata-modal-table-param-importoption',
'templatedata-modal-table-param-importoption-subtitle',
diff --git a/i18n/en.json b/i18n/en.json
index 2cd1741..042cbb3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -62,6 +62,7 @@
"templatedata-modal-table-param-autovalue": "Auto value",
"templatedata-modal-table-param-default": "Default",
"templatedata-modal-table-param-deprecated": "Deprecated",
+ "templatedata-modal-table-param-deprecatedValue": "Deprecated guidance",
"templatedata-modal-table-param-description": "Description ($1)",
"templatedata-modal-table-param-importoption": "Add $1 suggested
{{PLURAL:$1|parameter|parameters}}",
"templatedata-modal-table-param-importoption-subtitle": "Including: $1",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index b57367b..0b75c73 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -69,6 +69,7 @@
"templatedata-modal-table-param-autovalue": "Label for a parameter
property input: Parameter auto value in the table",
"templatedata-modal-table-param-default": "Label for a parameter
property input: Default value of the parameter.\n{{Identical|Default}}",
"templatedata-modal-table-param-deprecated": "Label for a parameter
property input: Deprecated status of the parameter.\n{{Identical|Deprecated}}",
+ "templatedata-modal-table-param-deprecatedValue": "Label for a
parameter property input: Deprecated guidance of the parameter.",
"templatedata-modal-table-param-description": "Label for a parameter
property input: Description of the parameter. $1 - currently showing
language.\n{{Identical|Description}}",
"templatedata-modal-table-param-importoption": "Label for the import
option in the parameter list in the edit dialog. $1 - number of suggested
parameters that can be imported.",
"templatedata-modal-table-param-importoption-subtitle": "A list of
suggested parameter names in the import option in the parameter list in the
edit dialog. $1 - list (or partial list) of suggested parameter names to
import.\n{{Identical|Including}}",
diff --git a/modules/ext.templateDataGenerator.data.js
b/modules/ext.templateDataGenerator.data.js
index 68c2277..9c6be11 100644
--- a/modules/ext.templateDataGenerator.data.js
+++ b/modules/ext.templateDataGenerator.data.js
@@ -182,7 +182,13 @@
type: 'string'
},
deprecated: {
- type: 'boolean'
+ type: 'boolean',
+ // This should only be defined for boolean properties.
+ // Define the property that represents the text value.
+ textValue: 'deprecatedValue'
+ },
+ deprecatedValue: {
+ type: 'string'
},
required: {
type: 'boolean'
@@ -516,11 +522,12 @@
* @return {boolean} Parameter was added successfully
*/
mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) {
- var prop, name, lang,
+ var prop, name, lang, propToSet,
existingNames = this.getAllParamNames(),
data = $.extend( true, {}, paramData ),
language = this.getDefaultLanguage(),
- propertiesWithLanguage =
this.constructor.static.getPropertiesWithLanguage();
+ propertiesWithLanguage =
this.constructor.static.getPropertiesWithLanguage(),
+ allProps = this.constructor.static.getAllProperties( true );
name = key;
// Check that the parameter is not already in the model
@@ -541,23 +548,43 @@
}
// Translate types
- if ( this.params[key].type !== undefined ) {
+ if ( paramData.type !== undefined ) {
this.params[key].normalizedType =
this.constructor.static.translateObsoleteParamTypes( this.params[key].type );
+ }
+
+ // Get the deprecated value
+ if ( $.type( data.deprecated ) === 'string' ) {
+ this.params[key].deprecatedValue = data.deprecated;
}
// Go over the rest of the data
if ( data ) {
for ( prop in data ) {
+ propToSet = prop;
if (
- $.inArray( prop, propertiesWithLanguage ) !==
-1 &&
+ // This is to make sure that forwards
compatibility is achieved
+ // and the code doesn't die on properties that
aren't valid
+ allProps[ prop ] &&
+ // Check if property should have its text
represented in another internal property
+ // (for example, deprecated and deprecatedValue)
+ allProps[ prop ].textValue
+ ) {
+ // Set the textValue property
+ propToSet = allProps[ prop ].textValue;
+ // Set the boolean value in the current property
+ this.setParamProperty( key, prop, !!data[prop],
language );
+ }
+
+ if (
+ $.inArray( propToSet, propertiesWithLanguage )
!== -1 &&
$.isPlainObject( data[prop] )
) {
// Add all language properties
for ( lang in data[prop] ) {
- this.setParamProperty( key, prop,
data[prop], lang );
+ this.setParamProperty( key, propToSet,
data[prop], lang );
}
} else {
- this.setParamProperty( key, prop, data[prop],
language );
+ this.setParamProperty( key, propToSet,
data[prop], language );
}
}
}
@@ -981,6 +1008,7 @@
// Go over all properties
for ( prop in allProps ) {
switch ( prop ) {
+ case 'deprecatedValue':
case 'name':
continue;
case 'type':
@@ -1006,7 +1034,13 @@
delete
result.params[name][prop];
}
} else {
- result.params[name][prop] =
this.params[key][prop];
+ if ( prop === 'deprecated' ) {
+
result.params[name][prop] = this.params[key].deprecatedValue || true;
+ // Remove
deprecatedValue
+ delete
result.params[name].deprecatedValue;
+ } else {
+
result.params[name][prop] = this.params[key].deprecatedValue;
+ }
}
break;
case 'aliases':
@@ -1024,7 +1058,7 @@
break;
default:
// Check if there's a value in the model
- if ( this.params[key][prop] !==
undefined ) {
+ if ( this.params[key][prop] ) {
if (
allProps[prop].allowLanguages ) {
normalizedValue =
this.propRemoveUnusedLanguages( this.params[key][prop] );
// Check if this should
be displayed with language object or directly as string
@@ -1038,6 +1072,11 @@
} else {
result.params[name][prop] = this.params[key][prop];
}
+ } else {
+ // Check if the original didn't
have this value as empty/false as well
+ if (
original.params[oldKey][prop] !== false && original.params[oldKey][prop] !== ''
) {
+ delete
result.params[name][prop];
+ }
}
break;
}
diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js
b/modules/ext.templateDataGenerator.ui.tdDialog.js
index 564a074..c752ad6 100644
--- a/modules/ext.templateDataGenerator.ui.tdDialog.js
+++ b/modules/ext.templateDataGenerator.ui.tdDialog.js
@@ -241,6 +241,30 @@
};
/**
+ * Respond to model change property
+ * @param {string} paramKey Parameter key
+ * @param {string} property Property name
+ * @param {string} value Property value
+ * @param {string} [language] Language
+ */
+mw.TemplateData.Dialog.prototype.onModelChangeProperty = function ( paramKey,
property, value, language ) {
+ var allProps = mw.TemplateData.Model.static.getAllProperties( true );
+ // Only update the input if it is the visible parameter key
+ // and we are in the edit parameters panel
+ if (
+ this.selectedParamKey === paramKey &&
+ this.panels.getCurrentItem() === this.editParamPanel
+ ) {
+ if ( allProps[ property ].textValue ) {
+ // The textValue property depends on this property
+ // toggle its view
+ this.propFieldLayout[ allProps[ property ].textValue
].toggle( !!value );
+ }
+ this.changeParamPropertyInput( paramKey, property, value,
language );
+ }
+};
+
+/**
* Respond to change of paramOrder from the model
* @param {string[]} paramOrderArray The array of keys in order
*/
@@ -442,11 +466,17 @@
*/
mw.TemplateData.Dialog.prototype.getParameterDetails = function ( paramKey ) {
var prop,
- paramData = this.model.getParamData( paramKey );
+ paramData = this.model.getParamData( paramKey ),
+ allProps = mw.TemplateData.Model.static.getAllProperties( true
);
for ( prop in this.propInputs ) {
this.changeParamPropertyInput( paramKey, prop, paramData[prop],
this.language );
+ // Show/hide dependents
+ if ( allProps[ prop ].textValue ) {
+ this.propFieldLayout[ allProps[ prop ].textValue
].toggle( !!paramData[prop] );
+ }
}
+
};
/**
@@ -622,6 +652,7 @@
align: 'left',
label: mw.msg( 'templatedata-modal-table-param-' +
props )
} );
+
// Event
if ( props === 'type' ) {
propInput.getMenu().connect( this, { choose: [
'onParamPropertyInputChange', props ] } );
@@ -751,6 +782,7 @@
// Events
this.model.connect( this, {
'change-description':
'onModelChangeDescription',
+ 'change-property': 'onModelChangeProperty',
'change-paramOrder': 'onModelChangeParamOrder',
'add-paramOrder': 'onModelAddKeyParamOrder'
} );
--
To view, visit https://gerrit.wikimedia.org/r/194748
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iadc6abdcc0cf2721a311cf43847b306cb269b5e8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateData
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits