Merge "eslint: Enforce no-var"

This commit is contained in:
jenkins-bot 2024-09-26 14:13:41 +00:00 committed by Gerrit Code Review
commit feb90ed0a1
13 changed files with 376 additions and 386 deletions

View file

@ -9,7 +9,6 @@
"wikimedia/mediawiki"
],
"rules": {
"max-len": "off",
"no-var": "off"
"max-len": "off"
}
}

View file

@ -106,7 +106,7 @@ Model.static.translateObsoleteParamTypes = function ( paramType ) {
* definition data
*/
Model.static.getAllProperties = function ( getFullData ) {
var properties = {
const properties = {
name: {
type: 'string',
// Validation regex
@ -197,10 +197,10 @@ Model.static.getAllProperties = function ( getFullData ) {
* @return {string[]} Property names
*/
Model.static.getPropertiesWithLanguage = function () {
var result = [],
const result = [],
propDefinitions = this.getAllProperties( true );
for ( var prop in propDefinitions ) {
for ( const prop in propDefinitions ) {
if ( propDefinitions[ prop ].allowLanguages ) {
result.push( prop );
}
@ -218,9 +218,9 @@ Model.static.getPropertiesWithLanguage = function () {
Model.static.splitAndTrimArray = function ( str, delim ) {
delim = delim || mw.msg( 'comma-separator' );
var arr = [];
const arr = [];
str.split( delim ).forEach( ( part ) => {
var trimmed = part.trim();
const trimmed = part.trim();
if ( trimmed ) {
arr.push( trimmed );
}
@ -237,7 +237,7 @@ Model.static.splitAndTrimArray = function ( str, delim ) {
* @return {Array} Union of the arrays
*/
Model.static.arrayUnionWithoutEmpty = function () {
var result = OO.simpleArrayUnion.apply( this, arguments );
const result = OO.simpleArrayUnion.apply( this, arguments );
// Trim and filter empty strings
return result.filter( ( i ) => i.trim() );
@ -251,7 +251,7 @@ Model.static.arrayUnionWithoutEmpty = function () {
* @return {Model} New model
*/
Model.static.newFromObject = function ( tdObject, paramsInSource ) {
var model = new Model();
const model = new Model();
model.setSourceCodeParameters( paramsInSource || [] );
@ -265,7 +265,7 @@ Model.static.newFromObject = function ( tdObject, paramsInSource ) {
// Add params
if ( tdObject.params ) {
for ( var param in tdObject.params ) {
for ( const param in tdObject.params ) {
model.addParam( param, tdObject.params[ param ] );
}
}
@ -300,7 +300,7 @@ Model.static.newFromObject = function ( tdObject, paramsInSource ) {
* the model
*/
Model.prototype.getMissingParams = function () {
var allParamNames = this.getAllParamNames(),
const allParamNames = this.getAllParamNames(),
sourceCodeParameters = this.sourceCodeParameters;
return sourceCodeParameters.filter( ( sourceCodeParameter ) => allParamNames.indexOf( sourceCodeParameter ) === -1 );
@ -312,7 +312,7 @@ Model.prototype.getMissingParams = function () {
* @return {Object} Parameters added. -1 for failure.
*/
Model.prototype.importSourceCodeParameters = function () {
var model = this,
const model = this,
allParamNames = this.getAllParamNames(),
existingArray = [],
importedArray = [],
@ -348,18 +348,18 @@ Model.prototype.importSourceCodeParameters = function () {
* @return {string[]} Language codes in use
*/
Model.prototype.getExistingLanguageCodes = function () {
var result = [];
let result = [];
// Take languages from the template description
if ( $.isPlainObject( this.description ) ) {
result = Object.keys( this.description );
}
var languageProps = this.constructor.static.getPropertiesWithLanguage();
const languageProps = this.constructor.static.getPropertiesWithLanguage();
// Go over the parameters
for ( var param in this.params ) {
for ( const param in this.params ) {
// Go over the properties
for ( var prop in this.params[ param ] ) {
for ( const prop in this.params[ param ] ) {
if ( languageProps.indexOf( prop ) !== -1 ) {
result = this.constructor.static.arrayUnionWithoutEmpty( result, Object.keys( this.params[ param ][ prop ] ) );
}
@ -378,8 +378,8 @@ Model.prototype.getExistingLanguageCodes = function () {
* @fires change
*/
Model.prototype.addParam = function ( name, paramData ) {
var data = $.extend( true, {}, paramData );
var key = this.getNewValidParameterKey( name );
const data = $.extend( true, {}, paramData );
const key = this.getNewValidParameterKey( name );
// Initialize
this.params[ key ] = { name: name };
@ -402,11 +402,11 @@ Model.prototype.addParam = function ( name, paramData ) {
// Go over the rest of the data
if ( data ) {
var language = this.getDefaultLanguage();
var propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage();
var allProps = this.constructor.static.getAllProperties( true );
for ( var prop in data ) {
var propToSet = prop;
const language = this.getDefaultLanguage();
const propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage();
const allProps = this.constructor.static.getAllProperties( true );
for ( const prop in data ) {
let propToSet = prop;
if (
// This is to make sure that forwards compatibility is achieved
// and the code doesn't die on properties that aren't valid
@ -432,7 +432,7 @@ Model.prototype.addParam = function ( name, paramData ) {
$.isPlainObject( data[ prop ] )
) {
// Add all language properties
for ( var lang in data[ prop ] ) {
for ( const lang in data[ prop ] ) {
this.setParamProperty( key, propToSet, data[ prop ], lang );
}
} else {
@ -456,9 +456,9 @@ Model.prototype.addParam = function ( name, paramData ) {
* @return {string[]} Used parameter names
*/
Model.prototype.getAllParamNames = function () {
var result = [];
for ( var key in this.params ) {
var param = this.params[ key ];
let result = [];
for ( const key in this.params ) {
const param = this.params[ key ];
result.push( param.name );
if ( param.aliases ) {
result = result.concat( param.aliases );
@ -618,7 +618,7 @@ Model.prototype.addKeyTemplateParamOrder = function ( key ) {
* @fires change
*/
Model.prototype.reorderParamOrderKey = function ( key, newIndex ) {
var keyIndex = this.paramOrder.indexOf( key );
const keyIndex = this.paramOrder.indexOf( key );
// Move the parameter, account for left shift if moving forwards
this.paramOrder.splice(
newIndex - ( newIndex > keyIndex ? 1 : 0 ),
@ -641,7 +641,7 @@ Model.prototype.reorderParamOrderKey = function ( key, newIndex ) {
* @fires change
*/
Model.prototype.removeKeyTemplateParamOrder = function ( key ) {
var keyPos = this.paramOrder.indexOf( key );
const keyPos = this.paramOrder.indexOf( key );
if ( keyPos > -1 ) {
this.paramOrder.splice( keyPos, 1 );
this.emit( 'change-paramOrder', this.paramOrder );
@ -679,8 +679,8 @@ Model.prototype.getTemplateFormat = function () {
* @fires change
*/
Model.prototype.setParamProperty = function ( paramKey, prop, value, language ) {
var allProps = this.constructor.static.getAllProperties( true ),
status = false;
const allProps = this.constructor.static.getAllProperties( true );
let status = false;
language = language || this.getDefaultLanguage();
if ( !allProps[ prop ] ) {
@ -688,7 +688,7 @@ Model.prototype.setParamProperty = function ( paramKey, prop, value, language )
return status;
}
var propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage();
const propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage();
// Check if the property is split by language code
if ( propertiesWithLanguage.indexOf( prop ) !== -1 ) {
// Initialize property if necessary
@ -706,10 +706,10 @@ Model.prototype.setParamProperty = function ( paramKey, prop, value, language )
} else {
// Compare without language
if ( !this.constructor.static.compare( this.params[ paramKey ][ prop ], value ) ) {
var oldValue = this.params[ paramKey ][ prop ];
const oldValue = this.params[ paramKey ][ prop ];
this.params[ paramKey ][ prop ] = value;
var newKey = value;
let newKey = value;
if ( prop === 'name' && oldValue !== value ) {
// See if the parameters already has something with this new key
if ( this.params[ newKey ] && !this.params[ newKey ].deleted ) {
@ -886,13 +886,13 @@ Model.prototype.getOriginalTemplateDataObject = function () {
* @return {Object} Templatedata object
*/
Model.prototype.outputTemplateData = function () {
var allProps = this.constructor.static.getAllProperties( true ),
const allProps = this.constructor.static.getAllProperties( true ),
original = this.getOriginalTemplateDataObject() || {};
original.params = original.params || {};
var result = $.extend( true, {}, original ),
const result = $.extend( true, {}, original ),
defaultLang = this.getDefaultLanguage();
var normalizedValue;
let normalizedValue;
// Template description
if ( this.description[ defaultLang ] !== undefined ) {
normalizedValue = this.propRemoveUnusedLanguages( this.description );
@ -935,8 +935,8 @@ Model.prototype.outputTemplateData = function () {
}
// Go over parameters in data
for ( var paramKey in this.params ) {
var key = paramKey;
for ( const paramKey in this.params ) {
const key = paramKey;
if ( this.params[ key ].deleted ) {
delete result.params[ key ];
continue;
@ -949,8 +949,8 @@ Model.prototype.outputTemplateData = function () {
}
// Check if name was changed and change the key accordingly
var name = this.params[ key ].name;
var oldKey = key;
const name = this.params[ key ].name;
const oldKey = key;
// Notice for clarity:
// Whether the parameter name was changed or not the following
@ -966,7 +966,7 @@ Model.prototype.outputTemplateData = function () {
}
// Go over all properties
for ( var prop in allProps ) {
for ( const prop in allProps ) {
if ( prop === 'status' || prop === 'deprecatedValue' || prop === 'name' ) {
continue;
}
@ -1021,7 +1021,7 @@ Model.prototype.outputTemplateData = function () {
default:
// Check if there's a value in the model
if ( this.params[ key ][ prop ] !== undefined ) {
var compareOrig = original.params[ oldKey ] && original.params[ oldKey ][ prop ];
const compareOrig = original.params[ oldKey ] && original.params[ oldKey ][ 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
@ -1073,9 +1073,9 @@ Model.prototype.getNewValidParameterKey = function ( key ) {
* @return {Object} Property data with only used language keys
*/
Model.prototype.propRemoveUnusedLanguages = function ( propData ) {
var result = {};
const result = {};
if ( $.isPlainObject( propData ) ) {
for ( var key in propData ) {
for ( const key in propData ) {
if ( propData[ key ] ) {
result[ key ] = propData[ key ];
}

View file

@ -1,4 +1,4 @@
var Model = require( './Model.js' );
const Model = require( './Model.js' );
/**
* TemplateData Source Handler
@ -43,7 +43,7 @@ OO.mixinClass( SourceHandler, OO.EventEmitter );
* @return {jQuery.Promise} API promise
*/
SourceHandler.prototype.getApi = function ( page, getTemplateData ) {
var type = getTemplateData ? 'templatedata' : 'query',
const type = getTemplateData ? 'templatedata' : 'query',
api = new mw.Api(),
baseConfig = {
action: type,
@ -51,7 +51,7 @@ SourceHandler.prototype.getApi = function ( page, getTemplateData ) {
redirects: getTemplateData ? 1 : 0
};
var config;
let config;
if ( type === 'query' ) {
config = Object.assign( baseConfig, {
prop: 'revisions',
@ -76,9 +76,9 @@ SourceHandler.prototype.getApi = function ( page, getTemplateData ) {
* or is rejected if the model was impossible to create.
*/
SourceHandler.prototype.buildModel = function ( wikitext ) {
var tdObject = null,
templateDataString = this.findModelInString( wikitext );
const templateDataString = this.findModelInString( wikitext );
let tdObject = null;
if ( templateDataString !== null ) {
try {
tdObject = JSON.parse( templateDataString );
@ -114,9 +114,9 @@ SourceHandler.prototype.buildModel = function ( wikitext ) {
* @return {jQuery.Promise} Promise resolving into template parameter array
*/
SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext ) {
var params = [],
sourceHandler = this;
const sourceHandler = this;
let params = [];
if ( !this.templateSourceCodePromise ) {
// Check given page text first
if ( wikitext ) {
@ -130,7 +130,7 @@ SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext )
// Get the content of the parent
this.templateSourceCodePromise = this.getApi( this.getParentPage() ).then(
( resp ) => {
var pageContent = '';
let pageContent = '';
// Verify that we have a sane response from the API.
// This is particularly important for unit tests, since the
@ -165,7 +165,7 @@ SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext )
* @return {string[]} An array of parameters that appear in the template code
*/
SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateCode ) {
var paramNames = [],
const paramNames = [],
normalizedParamNames = [],
// This regex matches the one in TemplateDataBlob.php
paramExtractor = /{{{+([^\n#={|}]*?)([<|]|}}})/mg;
@ -175,10 +175,10 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC
.replace( /<nowiki\s*>[\s\S]*?<\/nowiki\s*>/g, '' )
.replace( /<pre\s*>[\s\S]*?<\/pre\s*>/g, '' );
var matches;
let matches;
while ( ( matches = paramExtractor.exec( templateCode ) ) !== null ) {
// This normalization process is repeated in PHP in TemplateDataBlob.php
var normalizedParamName = matches[ 1 ].replace( /[-_ ]+/, ' ' ).trim().toLowerCase();
const normalizedParamName = matches[ 1 ].replace( /[-_ ]+/, ' ' ).trim().toLowerCase();
if ( !normalizedParamName || normalizedParamNames.indexOf( normalizedParamName ) !== -1 ) {
continue;
}
@ -199,7 +199,7 @@ SourceHandler.prototype.extractParametersFromTemplateCode = function ( templateC
* templatedata string was found.
*/
SourceHandler.prototype.findModelInString = function ( templateDataString ) {
var parts = templateDataString.match(
const parts = templateDataString.match(
/<templatedata>([\s\S]*?)<\/templatedata>/i
);

View file

@ -1,4 +1,4 @@
var Model = require( './Model.js' ),
const Model = require( './Model.js' ),
SourceHandler = require( './SourceHandler.js' );
module.exports = {

View file

@ -1,4 +1,4 @@
var
const
LanguageSearchWidget = require( './widgets/LanguageSearchWidget.js' ),
Metrics = require( './Metrics.js' ),
Model = require( 'ext.templateDataGenerator.data' ).Model,
@ -131,7 +131,7 @@ Dialog.prototype.initialize = function () {
flags: [ 'progressive', 'primary' ],
disabled: true
} );
var addParamFieldlayout = new OO.ui.ActionFieldLayout(
const addParamFieldlayout = new OO.ui.ActionFieldLayout(
this.newParamInput,
this.addParamButton,
{
@ -180,27 +180,27 @@ Dialog.prototype.initialize = function () {
this.mapsGroup = new OO.ui.OutlineSelectWidget( {
classes: [ 'mw-templateData-template-map-group' ]
} );
var addNewMapButtonPanel = new OO.ui.PanelLayout( {
const addNewMapButtonPanel = new OO.ui.PanelLayout( {
classes: [ 'mw-templateData-template-add-map-button-panel' ],
padded: true,
expanded: true
} );
var mapsListPanel = new OO.ui.PanelLayout( {
const mapsListPanel = new OO.ui.PanelLayout( {
expanded: true,
scrollable: true
} );
var mapsListMenuLayout = new OO.ui.MenuLayout( {
const mapsListMenuLayout = new OO.ui.MenuLayout( {
classes: [ 'mw-templateData-template-map-list-menu-panel' ],
menuPosition: 'top',
expanded: true,
contentPanel: mapsListPanel,
menuPanel: addNewMapButtonPanel
} );
var mapsContentPanel = new OO.ui.PanelLayout( {
const mapsContentPanel = new OO.ui.PanelLayout( {
padded: true,
expanded: true
} );
var templateMapsMenuLayout = new OO.ui.MenuLayout( {
const templateMapsMenuLayout = new OO.ui.MenuLayout( {
contentPanel: mapsContentPanel,
menuPanel: mapsListMenuLayout
} );
@ -212,7 +212,7 @@ Dialog.prototype.initialize = function () {
flags: [ 'progressive' ]
} );
var languageActionFieldLayout = new OO.ui.ActionFieldLayout(
const languageActionFieldLayout = new OO.ui.ActionFieldLayout(
this.languageDropdownWidget,
this.languagePanelButton,
{
@ -237,7 +237,7 @@ Dialog.prototype.initialize = function () {
this.paramSelect = new ParamSelectWidget();
this.paramImport = new ParamImportWidget();
var templateParamsFieldset = new OO.ui.FieldsetLayout( {
const templateParamsFieldset = new OO.ui.FieldsetLayout( {
label: mw.msg( 'templatedata-modal-title-templateparams' ),
items: [ this.paramSelect, this.paramImport ]
} );
@ -268,7 +268,7 @@ Dialog.prototype.initialize = function () {
placeholder: mw.msg( 'templatedata-modal-format-placeholder' )
} );
var templateFormatFieldSet = new OO.ui.FieldsetLayout( {
const templateFormatFieldSet = new OO.ui.FieldsetLayout( {
label: mw.msg( 'templatedata-modal-title-templateformat' ),
items: [
new OO.ui.FieldLayout( this.templateFormatSelectWidget ),
@ -397,7 +397,7 @@ Dialog.prototype.onModelChangeDescription = function ( description ) {
* @param {Object|undefined} map
*/
Dialog.prototype.onModelChangeMapInfo = function ( map ) {
var selectedItem = this.mapsGroup.findSelectedItem();
const selectedItem = this.mapsGroup.findSelectedItem();
map = map || {};
this.mapsCache = OO.copy( map );
if ( selectedItem ) {
@ -411,11 +411,11 @@ Dialog.prototype.onModelChangeMapInfo = function ( map ) {
* @param {string} value New parameter name
*/
Dialog.prototype.onAddParamInputChange = function ( value ) {
var allProps = Model.static.getAllProperties( true );
const allProps = Model.static.getAllProperties( true );
value = value.trim();
var invalid = !value || allProps.name.restrict.test( value );
var used = this.model.isParamExists( value ) && !this.model.isParamDeleted( value );
const invalid = !value || allProps.name.restrict.test( value );
const used = this.model.isParamExists( value ) && !this.model.isParamDeleted( value );
this.addParamButton.setDisabled( invalid || used );
};
@ -497,9 +497,9 @@ Dialog.prototype.onDescriptionInputChange = function ( value ) {
*/
Dialog.prototype.populateMapsItems = function ( mapsObject ) {
mapsObject = mapsObject || {};
var mapKeysList = Object.keys( mapsObject );
const mapKeysList = Object.keys( mapsObject );
var items = mapKeysList.map( ( mapKey ) => new OO.ui.OutlineOptionWidget( {
const items = mapKeysList.map( ( mapKey ) => new OO.ui.OutlineOptionWidget( {
label: mapKey
} ) );
@ -516,7 +516,7 @@ Dialog.prototype.populateMapsItems = function ( mapsObject ) {
* @param {string} value map info value
*/
Dialog.prototype.onMapInfoChange = function ( value ) {
var selectedItem = this.mapsGroup.findSelectedItem();
const selectedItem = this.mapsGroup.findSelectedItem();
// Update map Info
this.model.maps = this.model.getMapInfo() || {};
if ( selectedItem ) {
@ -587,11 +587,11 @@ Dialog.prototype.onCancelAddingMap = function ( highlightNext ) {
* @param {jQuery.Event} response response from Enter action on promptMapName
*/
Dialog.prototype.onEmbedNewMap = function ( response ) {
var mapNameValue = response ? response.target.value : this.newMapNameInput.getValue();
const mapNameValue = response ? response.target.value : this.newMapNameInput.getValue();
this.mapsCache = this.mapsCache || {};
// Create a new empty map in maps object
this.mapsCache[ mapNameValue ] = {};
var newlyAddedMap = new OO.ui.OutlineOptionWidget( {
const newlyAddedMap = new OO.ui.OutlineOptionWidget( {
label: mapNameValue
} );
// Add the new map item and select it
@ -607,7 +607,7 @@ Dialog.prototype.onEmbedNewMap = function ( response ) {
* Handle click event for the remove button
*/
Dialog.prototype.onMapItemRemove = function () {
var item = this.mapsGroup.findSelectedItem();
const item = this.mapsGroup.findSelectedItem();
if ( item ) {
this.mapsGroup.removeItems( [ item ] );
// Remove the highlighted map from maps object
@ -623,7 +623,7 @@ Dialog.prototype.onMapItemRemove = function () {
*/
Dialog.prototype.onMapsGroupSelect = function () {
// Highlight new item
var item = this.mapsGroup.findSelectedItem();
const item = this.mapsGroup.findSelectedItem();
if ( !item ) {
this.templateMapsInput.setDisabled( true );
@ -648,7 +648,7 @@ Dialog.prototype.onMapsGroupSelect = function () {
// Populate the mapsContentPanel
this.mapsCache = this.mapsCache || {};
var currentMapInfo = this.mapsCache[ item.label ];
const currentMapInfo = this.mapsCache[ item.label ];
this.templateMapsInput.setValue( this.stringifyObject( currentMapInfo ) );
}
};
@ -676,7 +676,7 @@ Dialog.prototype.onLanguagePanelButton = function () {
* @param {OO.ui.OptionWidget} item Selected item
*/
Dialog.prototype.onLanguageDropdownWidgetSelect = function ( item ) {
var language = item ? item.getData() : this.language;
const language = item ? item.getData() : this.language;
// Change current language
if ( language !== this.language ) {
@ -705,13 +705,13 @@ Dialog.prototype.onLanguageDropdownWidgetSelect = function ( item ) {
* @param {OO.ui.OptionWidget} item Chosen item
*/
Dialog.prototype.onNewLanguageSearchResultsChoose = function ( item ) {
var newLanguage = item.getData().code;
const newLanguage = item.getData().code;
if ( newLanguage ) {
if ( this.availableLanguages.indexOf( newLanguage ) === -1 ) {
// Add new language
this.availableLanguages.push( newLanguage );
var languageButton = new OO.ui.MenuOptionWidget( {
const languageButton = new OO.ui.MenuOptionWidget( {
data: newLanguage,
label: $.uls.data.getAutonym( newLanguage )
} );
@ -730,7 +730,7 @@ Dialog.prototype.onNewLanguageSearchResultsChoose = function ( item ) {
* Respond to edit maps button click
*/
Dialog.prototype.onMapsPanelButton = function () {
var item = this.mapsGroup.findSelectedItem() || this.mapsGroup.findFirstSelectableItem();
const item = this.mapsGroup.findSelectedItem() || this.mapsGroup.findFirstSelectableItem();
this.switchPanels( this.editMapsPanel );
// Select first item
this.mapsGroup.selectItem( item );
@ -744,7 +744,7 @@ Dialog.prototype.onAddParamButtonClick = function () {
return;
}
var newParamKey = this.newParamInput.getValue().trim();
const newParamKey = this.newParamInput.getValue().trim();
if ( this.model.isParamDeleted( newParamKey ) ) {
this.model.emptyParamData( newParamKey );
} else if ( !this.model.isParamExists( newParamKey ) ) {
@ -764,7 +764,7 @@ Dialog.prototype.onAddParamButtonClick = function () {
* @param {OO.ui.OptionWidget} item Parameter item
*/
Dialog.prototype.onParamSelectChoose = function ( item ) {
var paramKey = item.getData();
const paramKey = item.getData();
this.selectedParamKey = paramKey;
@ -781,7 +781,7 @@ Dialog.prototype.onParamSelectChoose = function ( item ) {
* @param {OO.ui.OptionWidget} item Format item
*/
Dialog.prototype.onTemplateFormatSelectWidgetChoose = function ( item ) {
var format = item.getData(),
const format = item.getData(),
shortcuts = {
inline: '{{_|_=_}}',
block: '{{_\n| _ = _\n}}'
@ -817,11 +817,11 @@ Dialog.prototype.displayToFormat = function ( s ) {
* @param {string} value Input widget value
*/
Dialog.prototype.onTemplateFormatInputWidgetChange = function ( value ) {
var item = this.templateFormatSelectWidget.findSelectedItem();
const item = this.templateFormatSelectWidget.findSelectedItem();
if ( item.getData() === 'custom' ) {
// Convert literal newlines or backslash-n to our fancy character
// replacement.
var normalized = this.formatToDisplay( this.displayToFormat( value ) );
const normalized = this.formatToDisplay( this.displayToFormat( value ) );
if ( normalized !== value ) {
this.templateFormatInputWidget.setValue( normalized );
// Will recurse to actually set value in model.
@ -840,12 +840,12 @@ Dialog.prototype.onTemplateFormatInputWidgetEnter = function () {
};
Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) {
var $errors = $( [] ),
prop = Model.static.getAllProperties( true )[ propName ],
let $errors = $( [] );
const prop = Model.static.getAllProperties( true )[ propName ],
propInput = this.propInputs[ propName ];
if ( propName === 'type' ) {
var selected = propInput.getMenu().findSelectedItem();
const selected = propInput.getMenu().findSelectedItem();
value = selected ? selected.getData() : prop.default;
} else if ( prop.type === 'array' ) {
value = propInput.getValue();
@ -856,8 +856,8 @@ Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) {
}
if ( propName === 'name' ) {
var invalid = !value || prop.restrict.test( value );
var changed = value !== this.selectedParamKey;
const invalid = !value || prop.restrict.test( value );
const changed = value !== this.selectedParamKey;
if ( invalid ) {
$errors = $errors.add( $( '<p>' ).text( mw.msg( 'templatedata-modal-errormsg', '|', '=', '}}' ) ) );
} else if ( changed && this.model.getAllParamNames().indexOf( value ) !== -1 ) {
@ -869,7 +869,7 @@ Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) {
propInput.$element.toggleClass( 'tdg-editscreen-input-error', !!$errors.length );
// Check if there is a dependent input to activate
var dependentField = prop.textValue;
const dependentField = prop.textValue;
if ( dependentField && this.propFieldLayout[ dependentField ] ) {
// The textValue property depends on this property
// toggle its view
@ -880,7 +880,7 @@ Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) {
// Validate
// FIXME: Don't read model information from the DOM
// eslint-disable-next-line no-jquery/no-global-selector
var anyInputError = !!$( '.tdg-templateDataDialog-paramInput.tdg-editscreen-input-error' ).length;
const anyInputError = !!$( '.tdg-templateDataDialog-paramInput.tdg-editscreen-input-error' ).length;
// Disable the 'done' button if there are any errors in the inputs
this.actions.setAbilities( { done: !anyInputError } );
@ -904,7 +904,7 @@ Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) {
};
Dialog.prototype.toggleSuggestedValues = function ( type ) {
var suggestedValuesAllowedTypes = [
const suggestedValuesAllowedTypes = [
'content',
'line',
'number',
@ -926,12 +926,12 @@ Dialog.prototype.toggleSuggestedValues = function ( type ) {
* @param {string} paramKey
*/
Dialog.prototype.getParameterDetails = function ( paramKey ) {
var paramData = this.model.getParamData( paramKey );
var allProps = Model.static.getAllProperties( true );
const paramData = this.model.getParamData( paramKey );
const allProps = Model.static.getAllProperties( true );
this.stopParameterInputTracking();
for ( var prop in this.propInputs ) {
for ( const prop in this.propInputs ) {
this.changeParamPropertyInput( paramKey, prop, paramData[ prop ], this.language );
// Show/hide dependents
if ( allProps[ prop ].textValue ) {
@ -941,7 +941,7 @@ Dialog.prototype.getParameterDetails = function ( paramKey ) {
// Update suggested values field visibility
this.toggleSuggestedValues( paramData.type || allProps.type.default );
var status;
let status;
// This accepts one of the three booleans only if the other two are false
if ( paramData.deprecated ) {
status = !paramData.required && !paramData.suggested && 'deprecated';
@ -964,7 +964,7 @@ Dialog.prototype.getParameterDetails = function ( paramKey ) {
this.changeParamPropertyInput( paramKey, 'status', status );
this.propInputs.status.getMenu().connect( this, {
choose: function ( item ) {
var selected = item.getData();
const selected = item.getData();
// Forward selection from the dropdown to the hidden checkboxes, these get saved
this.propInputs.deprecated.setSelected( selected === 'deprecated' );
this.propInputs.required.setSelected( selected === 'required' );
@ -987,7 +987,7 @@ Dialog.prototype.stopParameterInputTracking = function () {
*/
Dialog.prototype.startParameterInputTracking = function ( paramValues ) {
this.paramPropertyChangeTracking = {};
for ( var prop in this.propInputs ) {
for ( const prop in this.propInputs ) {
// Set to true, unless one of the exceptions applies.
this.paramPropertyChangeTracking[ prop ] = !(
// Setting type when we already have a specific type.
@ -1004,7 +1004,7 @@ Dialog.prototype.startParameterInputTracking = function ( paramValues ) {
};
Dialog.prototype.trackPropertyChange = function ( property ) {
var eventKey = ( property === 'required' || property === 'suggested' || property === 'deprecated' ) ?
const eventKey = ( property === 'required' || property === 'suggested' || property === 'deprecated' ) ?
'parameter-priority-change' : 'parameter-' + property + '-change';
if ( this.paramPropertyChangeTracking[ property ] ) {
@ -1044,14 +1044,14 @@ Dialog.prototype.repopulateParamSelectWidget = function () {
return;
}
var paramList = this.model.getParams(),
const paramList = this.model.getParams(),
paramOrder = this.model.getTemplateParamOrder();
this.paramSelect.clearItems();
// Update all param descriptions in the param select widget
for ( var i in paramOrder ) {
var paramKey = paramList[ paramOrder[ i ] ];
for ( const i in paramOrder ) {
const paramKey = paramList[ paramOrder[ i ] ];
if ( paramKey && !paramKey.deleted ) {
this.addParamToSelectWidget( paramOrder[ i ] );
}
@ -1059,7 +1059,7 @@ Dialog.prototype.repopulateParamSelectWidget = function () {
// Check if there are potential parameters to add
// from the template source code
var missingParams = this.model.getMissingParams();
const missingParams = this.model.getMissingParams();
this.paramImport
.toggle( !!missingParams.length )
.buildParamLabel( missingParams );
@ -1074,8 +1074,8 @@ Dialog.prototype.repopulateParamSelectWidget = function () {
* @param {string} [lang] Language
*/
Dialog.prototype.changeParamPropertyInput = function ( paramKey, propName, value, lang ) {
var prop = Model.static.getAllProperties( true )[ propName ],
propInput = this.propInputs[ propName ];
const prop = Model.static.getAllProperties( true )[ propName ];
let propInput = this.propInputs[ propName ];
switch ( prop.type ) {
case 'select':
@ -1106,7 +1106,7 @@ Dialog.prototype.changeParamPropertyInput = function ( paramKey, propName, value
* @param {string} paramKey Parameter key in the model
*/
Dialog.prototype.addParamToSelectWidget = function ( paramKey ) {
var data = this.model.getParamData( paramKey );
const data = this.model.getParamData( paramKey );
this.paramSelect.addItems( [ new ParamWidget( {
key: paramKey,
label: this.model.getParamValue( paramKey, 'label', this.language ),
@ -1124,21 +1124,21 @@ Dialog.prototype.addParamToSelectWidget = function ( paramKey ) {
* @return {jQuery} Editable details page for the parameter
*/
Dialog.prototype.createParamDetails = function () {
var paramProperties = Model.static.getAllProperties( true );
const paramProperties = Model.static.getAllProperties( true );
// Fieldset
var paramFieldset = new OO.ui.FieldsetLayout();
const paramFieldset = new OO.ui.FieldsetLayout();
for ( var propName in paramProperties ) {
var prop = paramProperties[ propName ];
var propInput;
var config = {};
for ( const propName in paramProperties ) {
const prop = paramProperties[ propName ];
const config = {};
let propInput;
// Create the property inputs
switch ( prop.type ) {
case 'select':
case 'select': {
propInput = new OO.ui.DropdownWidget( config );
var items = [];
for ( var i in prop.children ) {
const items = [];
for ( const i in prop.children ) {
items.push( new OO.ui.MenuOptionWidget( {
data: prop.children[ i ],
@ -1159,6 +1159,7 @@ Dialog.prototype.createParamDetails = function () {
}
propInput.getMenu().addItems( items );
break;
}
case 'boolean':
propInput = new OO.ui.CheckboxInputWidget( config );
break;
@ -1232,10 +1233,10 @@ Dialog.prototype.createParamDetails = function () {
* they show the currently used language.
*/
Dialog.prototype.updateParamDetailsLanguage = function () {
var languageProps = Model.static.getPropertiesWithLanguage();
const languageProps = Model.static.getPropertiesWithLanguage();
for ( var i = 0; i < languageProps.length; i++ ) {
var prop = languageProps[ i ];
for ( let i = 0; i < languageProps.length; i++ ) {
const prop = languageProps[ i ];
// The following messages are used here:
// * templatedata-modal-table-param-aliases
// * templatedata-modal-table-param-autovalue
@ -1250,7 +1251,7 @@ Dialog.prototype.updateParamDetailsLanguage = function () {
// * templatedata-modal-table-param-suggested
// * templatedata-modal-table-param-suggestedvalues
// * templatedata-modal-table-param-type
var label = mw.msg( 'templatedata-modal-table-param-' + prop, this.language );
const label = mw.msg( 'templatedata-modal-table-param-' + prop, this.language );
this.propFieldLayout[ prop ].setLabel( label );
this.propInputs[ prop ]
.$input.attr( { lang: mw.language.bcp47( this.language ), dir: 'auto' } );
@ -1284,7 +1285,7 @@ Dialog.prototype.toggleNoticeMessage = function ( type, isShowing, noticeMessage
if ( noticeMessageLabel ) {
// See which error to display
var noticeReference;
let noticeReference;
if ( type === 'global' ) {
noticeReference = this.noticeMessage;
} else if ( type === 'edit' ) {
@ -1306,12 +1307,12 @@ Dialog.prototype.toggleNoticeMessage = function ( type, isShowing, noticeMessage
* Import parameters from the source code.
*/
Dialog.prototype.importParametersFromTemplateCode = function () {
var $message = $( [] ),
state = 'success',
response = this.model.importSourceCodeParameters();
const response = this.model.importSourceCodeParameters();
// Repopulate the list
this.repopulateParamSelectWidget();
let $message = $( [] ),
state = 'success';
if ( response.imported.length === 0 ) {
$message = $( '<p>' ).text( mw.msg( 'templatedata-modal-errormsg-import-noparams' ) );
state = 'error';
@ -1374,11 +1375,11 @@ Dialog.prototype.getSetupProcess = function ( data ) {
);
this.availableLanguages = this.model.getExistingLanguageCodes().slice();
var defaultLanguage = this.model.getDefaultLanguage();
const defaultLanguage = this.model.getDefaultLanguage();
if ( this.availableLanguages.indexOf( defaultLanguage ) === -1 ) {
this.availableLanguages.unshift( defaultLanguage );
}
var items = this.availableLanguages.map( ( lang ) => new OO.ui.MenuOptionWidget( {
const items = this.availableLanguages.map( ( lang ) => new OO.ui.MenuOptionWidget( {
data: lang,
label: $.uls.data.getAutonym( lang )
} ) );
@ -1412,7 +1413,7 @@ Dialog.prototype.setupDetailsFromModel = function () {
this.mapsCache = OO.copy( this.model.getMapInfo() );
this.onMapsGroupSelect();
if ( this.model.getMapInfo() !== undefined ) {
var firstMapItem = Object.keys( this.model.getMapInfo() )[ 0 ];
const firstMapItem = Object.keys( this.model.getMapInfo() )[ 0 ];
this.templateMapsInput.setValue( this.stringifyObject( this.model.getMapInfo()[ firstMapItem ] ) );
} else {
this.templateMapsInput.setValue( '' );
@ -1420,7 +1421,7 @@ Dialog.prototype.setupDetailsFromModel = function () {
}
// Set up format
var format = this.model.getTemplateFormat();
const format = this.model.getTemplateFormat();
if ( format === 'inline' || format === 'block' || format === null ) {
this.templateFormatSelectWidget.selectItemByData( format );
this.templateFormatInputWidget.setDisabled( true );
@ -1541,7 +1542,7 @@ Dialog.prototype.getActionProcess = function ( action ) {
}
if ( !action && this.modified ) {
return new OO.ui.Process( function () {
var dialog = this;
const dialog = this;
return OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) )
.then( ( result ) => {
if ( result ) {

View file

@ -1,6 +1,6 @@
function logEvent( eventName ) {
/* eslint-disable camelcase */
var event = {
const event = {
action: eventName,
page_id: mw.config.get( 'wgArticleId' ),
page_title: mw.config.get( 'wgTitle' ),
@ -10,7 +10,7 @@ function logEvent( eventName ) {
user_id: mw.user.isNamed() ? mw.user.getId() : 0
};
var editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
const editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
if ( editCountBucket !== null ) {
event.user_edit_count_bucket = editCountBucket;
}

View file

@ -1,4 +1,4 @@
var Dialog = require( './Dialog.js' ),
const Dialog = require( './Dialog.js' ),
DataModule = require( 'ext.templateDataGenerator.data' ),
Model = DataModule.Model,
SourceHandler = DataModule.SourceHandler;
@ -15,7 +15,7 @@ var Dialog = require( './Dialog.js' ),
* @param {Object} config
*/
function Target( $textarea, config ) {
var target = this;
const target = this;
// Parent constructor
Target.super.call( this, config );
@ -39,7 +39,7 @@ function Target( $textarea, config ) {
} )
.toggle( false );
var $helpLink = $( '<a>' )
const $helpLink = $( '<a>' )
.attr( {
href: mw.msg( 'templatedata-helplink-target' ),
target: '_blank'
@ -63,24 +63,24 @@ function Target( $textarea, config ) {
} );
// Check if there's already a templatedata in a related page
var relatedPage = this.isDocPage ? this.parentPage : this.pageName + '/' + this.docSubpage;
const relatedPage = this.isDocPage ? this.parentPage : this.pageName + '/' + this.docSubpage;
this.sourceHandler.getApi( relatedPage )
.then( ( result ) => {
var response = result.query.pages[ result.query.pageids[ 0 ] ];
const response = result.query.pages[ result.query.pageids[ 0 ] ];
// HACK: When checking whether a related page (parent for /doc page or
// vice versa) already has a templatedata string, we shouldn't
// ask for the 'templatedata' action but rather the actual content
// of the related page, otherwise we get embedded templatedata and
// wrong information is presented.
if ( response.missing === undefined ) {
var content = response.revisions[ 0 ][ '*' ];
const content = response.revisions[ 0 ][ '*' ];
// There's a templatedata string
if ( /<templatedata>/i.test( content ) ) {
// HACK: Setting a link in the messages doesn't work. The bug report offers
// a somewhat hacky work around that includes setting a separate message
// to be parsed.
// https://phabricator.wikimedia.org/T49395#490610
var msg = mw.message( 'templatedata-exists-on-related-page', relatedPage ).plain();
let msg = mw.message( 'templatedata-exists-on-related-page', relatedPage ).plain();
mw.messages.set( { 'templatedata-string-exists-hack-message': msg } );
msg = new OO.ui.HtmlSnippet(
mw.message( 'templatedata-string-exists-hack-message' ).parse()
@ -154,7 +154,7 @@ Target.prototype.openEditDialog = function ( dataModel ) {
* @method onEditOpenDialogButton
*/
Target.prototype.onEditOpenDialogButton = function () {
var target = this;
const target = this;
this.originalWikitext = this.$textarea.textSelection( 'getContents' );
@ -187,7 +187,7 @@ Target.prototype.onEditOpenDialogButton = function () {
} ).closed.then( ( data ) => {
if ( data && data.action === 'accept' ) {
// Open the dialog with an empty model
var model = Model.static.newFromObject(
const model = Model.static.newFromObject(
null,
target.sourceHandler.getTemplateSourceCodeParams()
);
@ -206,10 +206,10 @@ Target.prototype.onEditOpenDialogButton = function () {
* @param {Object} newTemplateData New templatedata
*/
Target.prototype.replaceTemplateData = function ( newTemplateData ) {
var templateDataJSON = JSON.stringify( newTemplateData, null, '\t' ),
const templateDataJSON = JSON.stringify( newTemplateData, null, '\t' ),
templatedataPattern = /(<templatedata>\s*)([\s\S]*?)\s*<\/templatedata>/i;
var matches, templateDataOutput;
let matches, templateDataOutput;
if ( ( matches = this.originalWikitext.match( templatedataPattern ) ) ) {
// Move cursor to select withing existing <templatedata> and whitespace
this.$textarea.textSelection( 'setSelection', {
@ -246,7 +246,7 @@ Target.prototype.replaceTemplateData = function ( newTemplateData ) {
* @param {Object} templateData New templatedata
*/
Target.prototype.onDialogApply = function ( templateData ) {
var target = this;
const target = this;
if (
Object.keys( templateData ).length > 1 ||

View file

@ -11,20 +11,16 @@
'use strict';
new mw.Api().loadMessages( 'templatedata-doc-subpage', { amlang: mw.config.get( 'wgContentLanguage' ) } ).then( () => {
var Target = require( './Target.js' ),
const Target = require( './Target.js' ),
pageName = mw.config.get( 'wgPageName' ),
docSubpage = mw.msg( 'templatedata-doc-subpage' ),
config = {
pageName: pageName,
isPageSubLevel: false
},
$textbox = $( '#wpTextbox1' );
docSubpage = mw.msg( 'templatedata-doc-subpage' );
let $textbox = $( '#wpTextbox1' );
var pieces = pageName.split( '/' );
var isDocPage = pieces.length > 1 && pieces[ pieces.length - 1 ] === docSubpage;
var openTDG = new URL( location.href ).searchParams.get( 'templatedata' ) === 'edit';
const pieces = pageName.split( '/' );
const isDocPage = pieces.length > 1 && pieces[ pieces.length - 1 ] === docSubpage;
const openTDG = new URL( location.href ).searchParams.get( 'templatedata' ) === 'edit';
config = {
const config = {
pageName: pageName,
isPageSubLevel: pieces.length > 1,
parentPage: pageName,
@ -42,16 +38,16 @@ new mw.Api().loadMessages( 'templatedata-doc-subpage', { amlang: mw.config.get(
// Textbox wikitext editor
if ( $textbox.length ) {
// Prepare the editor
var wtTarget = new Target( $textbox, config );
const wtTarget = new Target( $textbox, config );
$( '.tdg-editscreen-placeholder' ).replaceWith( wtTarget.$element );
if ( openTDG ) {
wtTarget.onEditOpenDialogButton();
}
}
var veTarget;
let veTarget;
// Visual editor source mode
mw.hook( 've.activationComplete' ).add( () => {
var surface = ve.init.target.getSurface();
const surface = ve.init.target.getSurface();
if ( surface.getMode() === 'source' ) {
// Source mode will have created a dummy textbox
$textbox = $( '#wpTextbox1' );

View file

@ -52,7 +52,7 @@ LanguageResultWidget.prototype.onKeyDown = function ( e ) {
* @chainable
*/
LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty ) {
var data = this.getData();
const data = this.getData();
// Reset text
this.$name.text( data.name );
@ -60,7 +60,7 @@ LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty )
// Highlight where applicable
if ( matchedProperty ) {
var $highlighted = this.constructor.static.highlightQuery( data[ matchedProperty ], query );
const $highlighted = this.constructor.static.highlightQuery( data[ matchedProperty ], query );
if ( matchedProperty === 'name' ) {
this.$name.empty().append( $highlighted );
} else {
@ -81,7 +81,7 @@ LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty )
* @return {jQuery} Text with query substring wrapped in highlighted span
*/
LanguageResultWidget.static.highlightQuery = function ( text, query ) {
var $result = $( '<span>' ),
const $result = $( '<span>' ),
offset = text.toLowerCase().indexOf( query.toLowerCase() );
if ( !query.length || offset === -1 ) {

View file

@ -1,4 +1,4 @@
var LanguageResultWidget = require( './LanguageResultWidget.js' );
const LanguageResultWidget = require( './LanguageResultWidget.js' );
/**
* Creates a TemplateDataLanguageSearchWidget object.
@ -21,7 +21,7 @@ function LanguageSearchWidget( config ) {
// Properties
this.filteredLanguageResultWidgets = [];
var languageCodes = Object.keys( $.uls.data.getAutonyms() ).sort();
const languageCodes = Object.keys( $.uls.data.getAutonyms() ).sort();
this.languageResultWidgets = languageCodes.map( ( languageCode ) => new LanguageResultWidget( {
data: {
code: languageCode,
@ -64,7 +64,7 @@ LanguageSearchWidget.prototype.setAvailableLanguages = function ( availableLangu
}
this.filteredLanguageResultWidgets = this.languageResultWidgets.map( ( languageResult ) => {
var data = languageResult.getData();
const data = languageResult.getData();
if ( availableLanguages.indexOf( data.code ) !== -1 ) {
return languageResult;
}
@ -76,7 +76,7 @@ LanguageSearchWidget.prototype.setAvailableLanguages = function ( availableLangu
* Update search results from current query
*/
LanguageSearchWidget.prototype.addResults = function () {
var matchProperties = [ 'name', 'autonym', 'code' ],
const matchProperties = [ 'name', 'autonym', 'code' ],
query = this.query.getValue().trim(),
compare = window.Intl && Intl.Collator ?
new Intl.Collator( this.lang, { sensitivity: 'base' } ).compare :
@ -86,12 +86,12 @@ LanguageSearchWidget.prototype.addResults = function () {
hasQuery = !!query.length,
items = [];
var results = this.getResults();
const results = this.getResults();
results.clearItems();
this.filteredLanguageResultWidgets.forEach( ( languageResult ) => {
var data = languageResult.getData();
var matchedProperty = null;
const data = languageResult.getData();
let matchedProperty = null;
matchProperties.some( ( prop ) => {
if ( data[ prop ] && compare( data[ prop ].slice( 0, query.length ), query ) === 0 ) {

View file

@ -27,7 +27,7 @@ OO.inheritClass( ParamImportWidget, OO.ui.ButtonWidget );
* @param {string[]} params Param names
*/
ParamImportWidget.prototype.buildParamLabel = function ( params ) {
var paramNames = params.slice( 0, 9 ).join( mw.msg( 'comma-separator' ) );
const paramNames = params.slice( 0, 9 ).join( mw.msg( 'comma-separator' ) );
this.setLabel( $( '<div>' )
.addClass( 'tdg-templateDataParamWidget-param-name' )
.text( mw.msg( 'templatedata-modal-table-param-importoption', params.length ) )

View file

@ -52,7 +52,7 @@ ParamWidget.prototype.onKeyDown = function ( e ) {
* Build the parameter label in the parameter select widget
*/
ParamWidget.prototype.buildParamLabel = function () {
var keys = this.aliases.slice(),
const keys = this.aliases.slice(),
$paramLabel = $( '<div>' )
.addClass( 'tdg-templateDataParamWidget-param-name' ),
$aliases = $( '<div>' )

View file

@ -3,19 +3,16 @@
*/
'use strict';
var finalJsonParams, finalJson,
resultDescCurrLang, resultDescMockLang, resultDescBothLang, currLanguage, originalWikitext,
DataModule = require( 'ext.templateDataGenerator.data' ),
const DataModule = require( 'ext.templateDataGenerator.data' ),
Model = DataModule.Model,
SourceHandler = DataModule.SourceHandler;
QUnit.module( 'ext.templateData', QUnit.newMwEnvironment() );
resultDescCurrLang = {};
resultDescMockLang = {};
resultDescBothLang = {};
currLanguage = mw.config.get( 'wgContentLanguage' ) || 'en';
originalWikitext = 'Some text here that is not templatedata information.' +
const resultDescCurrLang = {};
const resultDescMockLang = {};
const currLanguage = mw.config.get( 'wgContentLanguage' ) || 'en';
const originalWikitext = 'Some text here that is not templatedata information.' +
'<templatedata>' +
'{' +
'"description": {\n' +
@ -68,8 +65,8 @@ originalWikitext = 'Some text here that is not templatedata information.' +
// Prepare description language objects
resultDescCurrLang[ currLanguage ] = 'Some string here in ' + currLanguage + ' language.';
resultDescMockLang.blah = 'Some string here in blah language.';
resultDescBothLang = Object.assign( {}, resultDescCurrLang, resultDescMockLang );
finalJsonParams = {
const resultDescBothLang = Object.assign( {}, resultDescCurrLang, resultDescMockLang );
const finalJsonParams = {
user: {
label: 'Username',
type: 'wiki-user-name',
@ -131,7 +128,7 @@ finalJsonParams.date.description[ currLanguage ] = 'Timestamp of when the commen
finalJsonParams.newParam1.description[ currLanguage ] = 'Some string here in ' + currLanguage + ' language.';
finalJsonParams.newParam4.description[ currLanguage ] = resultDescBothLang[ currLanguage ];
finalJson = {
const finalJson = {
description: {
blah: 'Template description in some blah language.'
},
@ -152,200 +149,199 @@ finalJson.description[ currLanguage ] = 'Label unsigned comments in a conversati
// Test validation tools
QUnit.test( 'Validation tools', ( assert ) => {
var i, testVars,
tests = {
compare: [
{
obj1: null,
obj2: undefined,
result: false,
msg: 'Compare: null vs undefined'
},
{
obj1: 'string',
obj2: undefined,
result: false,
msg: 'Compare: string vs undefined'
},
{
obj1: undefined,
obj2: undefined,
result: true,
msg: 'Compare: undefined vs undefined'
},
{
obj1: null,
obj2: null,
result: true,
msg: 'Compare: null vs null'
},
{
obj1: 'A proper string.',
obj2: 'A proper string.',
result: true,
msg: 'Compare: strings'
},
{
obj1: true,
obj2: true,
result: true,
msg: 'Compare: booleans'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 1: 'string', 2: 'another', 4: 'and another' },
result: true,
allowSubset: true,
msg: 'Compare: plain object full equality'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 1: 'another', 2: 'and another', 4: 'string' },
result: false,
allowSubset: true,
msg: 'Compare: plain object full inequality'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 4: 'and another' },
result: true,
allowSubset: true,
msg: 'Compare: plain object subset equality'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1', 'val2', 'val3' ],
result: true,
msg: 'Compare: arrays'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1' ],
result: true,
allowSubset: true,
msg: 'Compare: array subset: true'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1' ],
result: false,
allowSubset: false,
msg: 'Compare: array subset: false'
},
{
obj1: {
param1: {
type: 'unknown',
aliases: [ 'alias2', 'alias1', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
param2: {
required: true
}
const tests = {
compare: [
{
obj1: null,
obj2: undefined,
result: false,
msg: 'Compare: null vs undefined'
},
{
obj1: 'string',
obj2: undefined,
result: false,
msg: 'Compare: string vs undefined'
},
{
obj1: undefined,
obj2: undefined,
result: true,
msg: 'Compare: undefined vs undefined'
},
{
obj1: null,
obj2: null,
result: true,
msg: 'Compare: null vs null'
},
{
obj1: 'A proper string.',
obj2: 'A proper string.',
result: true,
msg: 'Compare: strings'
},
{
obj1: true,
obj2: true,
result: true,
msg: 'Compare: booleans'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 1: 'string', 2: 'another', 4: 'and another' },
result: true,
allowSubset: true,
msg: 'Compare: plain object full equality'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 1: 'another', 2: 'and another', 4: 'string' },
result: false,
allowSubset: true,
msg: 'Compare: plain object full inequality'
},
{
obj1: { 1: 'string', 2: 'another', 4: 'and another' },
obj2: { 4: 'and another' },
result: true,
allowSubset: true,
msg: 'Compare: plain object subset equality'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1', 'val2', 'val3' ],
result: true,
msg: 'Compare: arrays'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1' ],
result: true,
allowSubset: true,
msg: 'Compare: array subset: true'
},
{
obj1: [ 'val1', 'val2', 'val3' ],
obj2: [ 'val1' ],
result: false,
allowSubset: false,
msg: 'Compare: array subset: false'
},
{
obj1: {
param1: {
type: 'unknown',
aliases: [ 'alias2', 'alias1', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
obj2: {
param1: {
type: 'unknown',
aliases: [ 'alias2', 'alias1', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
param2: {
required: true
}
param2: {
required: true
}
},
obj2: {
param1: {
type: 'unknown',
aliases: [ 'alias2', 'alias1', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
result: true,
allowSubset: true,
msg: 'Compare: complex objects'
param2: {
required: true
}
},
{
obj1: {
param1: {
type: 'unknown',
aliases: [ 'alias1', 'alias2', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
param2: {
required: true
}
result: true,
allowSubset: true,
msg: 'Compare: complex objects'
},
{
obj1: {
param1: {
type: 'unknown',
aliases: [ 'alias1', 'alias2', 'alias3' ],
description: 'Some description',
required: true,
suggested: false
},
obj2: {
param1: {
aliases: [ 'alias1', 'alias2', 'alias3' ],
suggested: false
}
},
result: true,
allowSubset: true,
msg: 'Compare: complex objects subset'
}
],
splitAndTrimArray: [
{
string: 'str1 , str2 ',
delim: ',',
result: [ 'str1', 'str2' ],
msg: 'splitAndTrimArray: split and trim'
param2: {
required: true
}
},
{
string: 'str1, str2, , , , str3',
delim: ',',
result: [ 'str1', 'str2', 'str3' ],
msg: 'splitAndTrimArray: remove empty values'
obj2: {
param1: {
aliases: [ 'alias1', 'alias2', 'alias3' ],
suggested: false
}
},
{
string: 'str1|str2|str3',
delim: '|',
result: [ 'str1', 'str2', 'str3' ],
msg: 'splitAndTrimArray: different delimeter'
}
],
arrayUnionWithoutEmpty: [
{
arrays: [ [ 'en', 'he', '' ], [ 'he', 'de', '' ], [ 'en', 'de' ] ],
result: [ 'en', 'he', 'de' ],
msg: 'arrayUnionWithoutEmpty: Remove duplications'
},
{
arrays: [ [ 'en', '', '' ], [ 'he', '', '' ], [ 'de', '' ] ],
result: [ 'en', 'he', 'de' ],
msg: 'arrayUnionWithoutEmpty: Remove empty values'
}
],
props: {
all: [
'name',
'aliases',
'label',
'description',
'example',
'type',
'suggestedvalues',
'default',
'autovalue',
'status',
'deprecated',
'deprecatedValue',
'required',
'suggested'
],
language: [
'label',
'description',
'example',
'default'
]
result: true,
allowSubset: true,
msg: 'Compare: complex objects subset'
}
};
],
splitAndTrimArray: [
{
string: 'str1 , str2 ',
delim: ',',
result: [ 'str1', 'str2' ],
msg: 'splitAndTrimArray: split and trim'
},
{
string: 'str1, str2, , , , str3',
delim: ',',
result: [ 'str1', 'str2', 'str3' ],
msg: 'splitAndTrimArray: remove empty values'
},
{
string: 'str1|str2|str3',
delim: '|',
result: [ 'str1', 'str2', 'str3' ],
msg: 'splitAndTrimArray: different delimeter'
}
],
arrayUnionWithoutEmpty: [
{
arrays: [ [ 'en', 'he', '' ], [ 'he', 'de', '' ], [ 'en', 'de' ] ],
result: [ 'en', 'he', 'de' ],
msg: 'arrayUnionWithoutEmpty: Remove duplications'
},
{
arrays: [ [ 'en', '', '' ], [ 'he', '', '' ], [ 'de', '' ] ],
result: [ 'en', 'he', 'de' ],
msg: 'arrayUnionWithoutEmpty: Remove empty values'
}
],
props: {
all: [
'name',
'aliases',
'label',
'description',
'example',
'type',
'suggestedvalues',
'default',
'autovalue',
'status',
'deprecated',
'deprecatedValue',
'required',
'suggested'
],
language: [
'label',
'description',
'example',
'default'
]
}
};
// Compare
for ( i = 0; i < tests.compare.length; i++ ) {
testVars = tests.compare[ i ];
for ( let i = 0; i < tests.compare.length; i++ ) {
const testVars = tests.compare[ i ];
assert.strictEqual(
Model.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ),
testVars.result,
@ -354,8 +350,8 @@ QUnit.test( 'Validation tools', ( assert ) => {
}
// Split and trim
for ( i = 0; i < tests.splitAndTrimArray.length; i++ ) {
testVars = tests.splitAndTrimArray[ i ];
for ( let i = 0; i < tests.splitAndTrimArray.length; i++ ) {
const testVars = tests.splitAndTrimArray[ i ];
assert.deepEqual(
Model.static.splitAndTrimArray( testVars.string, testVars.delim ),
testVars.result,
@ -364,8 +360,8 @@ QUnit.test( 'Validation tools', ( assert ) => {
}
// arrayUnionWithoutEmpty
for ( i = 0; i < tests.arrayUnionWithoutEmpty.length; i++ ) {
testVars = tests.arrayUnionWithoutEmpty[ i ];
for ( let i = 0; i < tests.arrayUnionWithoutEmpty.length; i++ ) {
const testVars = tests.arrayUnionWithoutEmpty[ i ];
assert.deepEqual(
Model.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ),
testVars.result,
@ -388,8 +384,7 @@ QUnit.test( 'Validation tools', ( assert ) => {
// Test model load
QUnit.test( 'TemplateData model', ( assert ) => {
var i, testVars,
sourceHandler = new SourceHandler(),
const sourceHandler = new SourceHandler(),
paramAddTest = [
{
key: 'newParam1',
@ -513,7 +508,7 @@ QUnit.test( 'TemplateData model', ( assert ) => {
'Parameters retention.'
);
for ( i = 0; i < paramAddTest.length; i++ ) {
for ( let i = 0; i < paramAddTest.length; i++ ) {
// Add parameter
model.addParam( paramAddTest[ i ].key, paramAddTest[ i ].data );
@ -533,8 +528,8 @@ QUnit.test( 'TemplateData model', ( assert ) => {
}
// Change parameter properties
for ( i = 0; i < paramChangeTest.length; i++ ) {
testVars = paramChangeTest[ i ];
for ( let i = 0; i < paramChangeTest.length; i++ ) {
const testVars = paramChangeTest[ i ];
model.setParamProperty( testVars.key, testVars.property, testVars.value, testVars.language );
assert.deepEqual(
model.getParamData( testVars.key ),
@ -596,7 +591,7 @@ QUnit.test( 'TemplateData model', ( assert ) => {
// Test model with maps in wikitext
QUnit.test( 'TemplateData sourceHandler with maps', ( assert ) => {
var sourceHandler = new SourceHandler(),
const sourceHandler = new SourceHandler(),
wikitextWithMaps = 'Some text here that is not templatedata information.' +
'<templatedata>' +
'{' +
@ -719,7 +714,7 @@ QUnit.test( 'TemplateData sourceHandler with maps', ( assert ) => {
// Test model fail
QUnit.test( 'TemplateData sourceHandler failure', ( assert ) => {
var sourceHandler = new SourceHandler(),
const sourceHandler = new SourceHandler(),
erronousString = '<templatedata>{\n' +
'"params": {\n' +
// Open quote
@ -742,10 +737,9 @@ QUnit.test( 'TemplateData sourceHandler failure', ( assert ) => {
'}\n' +
'}\n' +
'}</templatedata>',
done = assert.async(),
promise;
done = assert.async();
promise = sourceHandler.buildModel( erronousString );
const promise = sourceHandler.buildModel( erronousString );
promise.always( () => {
assert.strictEqual( promise.state(), 'rejected', 'Promise rejected on erronous json string.' );
done();
@ -754,7 +748,7 @@ QUnit.test( 'TemplateData sourceHandler failure', ( assert ) => {
// Test model gets default format
QUnit.test( 'TemplateData sourceHandler adding default format', ( assert ) => {
var sourceHandler = new SourceHandler(),
const sourceHandler = new SourceHandler(),
simpleTemplateDataNoFormat = '<templatedata>{\n' +
'"params": {}\n' +
'}</templatedata>',
@ -773,7 +767,7 @@ QUnit.test( 'TemplateData sourceHandler adding default format', ( assert ) => {
} );
QUnit.test( 'Duplicate parameter names', ( assert ) => {
var model = new Model();
const model = new Model();
model.addParam( 'color' );
assert.deepEqual( model.getParams(), {
color: { name: 'color' }
@ -804,7 +798,7 @@ QUnit.test( 'Duplicate parameter names', ( assert ) => {
} );
QUnit.test( 'safesubst: hack with an unnamed parameter', ( assert ) => {
var handler = new SourceHandler(),
const handler = new SourceHandler(),
wikitext = '{{ {{{|safesubst:}}}#invoke:…|{{{1}}}|{{{ 1 }}}}}';
assert.deepEqual(