Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/191217
Change subject: Change global class variables to mw.TemplateData ...................................................................... Change global class variables to mw.TemplateData Nest all classes for the templatedata dialog in mw.TemplateData namespace. Change-Id: Ib514378c9fbc0fb993b3cbc2fa48ced920167226 --- M .jshintrc M TemplateData.php M modules/ext.templateDataGenerator.data.js A modules/ext.templateDataGenerator.js M modules/ext.templateDataGenerator.ui.js M modules/ext.templateDataGenerator.ui.tdDialog.js M modules/widgets/ext.templateDataGenerator.dragDropItemWidget.js M modules/widgets/ext.templateDataGenerator.dragDropWidget.js M modules/widgets/ext.templateDataGenerator.languageResultWidget.js M modules/widgets/ext.templateDataGenerator.languageSearchWidget.js M modules/widgets/ext.templateDataGenerator.optionImportWidget.js M modules/widgets/ext.templateDataGenerator.optionWidget.js M tests/ext.templateData.tests.js 13 files changed, 138 insertions(+), 144 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateData refs/changes/17/191217/1 diff --git a/.jshintrc b/.jshintrc index dccd4af..269c0e5 100644 --- a/.jshintrc +++ b/.jshintrc @@ -23,14 +23,6 @@ "QUnit": false, "unicodeJS": false, "jQuery": false, - "mediaWiki": false, - "TemplateDataModel": true, - "TemplateDataDialog": true, - "TemplateDataOptionWidget": true, - "TemplateDataOptionImportWidget": true, - "TemplateDataLanguageSearchWidget": true, - "TemplateDataLanguageResultWidget": true, - "TemplateDataDragDropItemWidget": true, - "TemplateDataDragDropWidget": true + "mediaWiki": false } } diff --git a/TemplateData.php b/TemplateData.php index 3f23cd3..58aeff2 100644 --- a/TemplateData.php +++ b/TemplateData.php @@ -77,6 +77,7 @@ 'localBasePath' => $dir, 'remoteExtPath' => 'TemplateData', 'scripts' => array( + 'modules/ext.templateDataGenerator.js', 'modules/ext.templateDataGenerator.data.js' ), 'dependencies' => array( diff --git a/modules/ext.templateDataGenerator.data.js b/modules/ext.templateDataGenerator.data.js index 53868f2..1f82b10 100644 --- a/modules/ext.templateDataGenerator.data.js +++ b/modules/ext.templateDataGenerator.data.js @@ -3,7 +3,7 @@ * TemplateData Dialog * @param {Object} config Dialog configuration object */ - TemplateDataModel = function TemplateDataModel( config ) { + mw.TemplateData.Model = function mwTemplateDataModel( config ) { config = config || {}; // Mixin constructors @@ -28,8 +28,8 @@ }; /* Setup */ - OO.initClass( TemplateDataModel ); - OO.mixinClass( TemplateDataModel, OO.EventEmitter ); + OO.initClass( mw.TemplateData.Model ); + OO.mixinClass( mw.TemplateData.Model, OO.EventEmitter ); /* Events */ @@ -64,7 +64,7 @@ * @param {string} page Page name * @return {jQuery.Promise} API promise */ - TemplateDataModel.static.getApi = function ( page ) { + mw.TemplateData.Model.static.getApi = function ( page ) { var api = new mediaWiki.Api(); return api.get( { action: 'query', @@ -83,7 +83,7 @@ * partial object (or a subset) of the first. * @return {boolean} Objects have equal values */ - TemplateDataModel.static.compare = function ( obj1, obj2, allowSubset ) { + mw.TemplateData.Model.static.compare = function ( obj1, obj2, allowSubset ) { if ( allowSubset && obj2 === undefined ) { return true; } @@ -107,7 +107,7 @@ * @param {string} paramType Given type * @return {string} Normalized non-obsolete type */ - TemplateDataModel.static.translateObsoleteParamTypes = function ( paramType ) { + mw.TemplateData.Model.static.translateObsoleteParamTypes = function ( paramType ) { switch ( paramType ) { case 'string/wiki-page-name': return 'wiki-page-name'; @@ -128,7 +128,7 @@ * @return {Object|string[]} Legal property names with or without their * definition data */ - TemplateDataModel.static.getAllProperties = function ( getFullData ) { + mw.TemplateData.Model.static.getAllProperties = function ( getFullData ) { var properties = { name: { type: 'string', @@ -193,7 +193,7 @@ * Retrieve the list of property names that allow for multiple languages. * @return {string[]} Property names */ - TemplateDataModel.static.getPropertiesWithLanguage = function () { + mw.TemplateData.Model.static.getPropertiesWithLanguage = function () { var prop, result = [], propDefinitions = this.getAllProperties( true ); @@ -212,7 +212,7 @@ * @param {string} [delim] Delimeter * @return {string[]} Clean array */ - TemplateDataModel.static.splitAndTrimArray = function ( str, delim ) { + mw.TemplateData.Model.static.splitAndTrimArray = function ( str, delim ) { var arr = []; delim = delim || mw.msg( 'comma-separator' ); @@ -232,7 +232,7 @@ * @param {Array...} arrays Arrays to union * @return {Array} Union of the arrays */ - TemplateDataModel.static.arrayUnionWithoutEmpty = function () { + mw.TemplateData.Model.static.arrayUnionWithoutEmpty = function () { var result = OO.simpleArrayUnion.apply( this, arguments ); // Trim and filter empty strings @@ -252,7 +252,7 @@ * * @param {string} templateDataString Current page wikitext */ - TemplateDataModel.prototype.loadModel = function ( tdString ) { + mw.TemplateData.Model.prototype.loadModel = function ( tdString ) { var original = {}, deferred = $.Deferred(); @@ -296,7 +296,7 @@ * @return {string[]} Parameters that are not yet included in * the model */ - TemplateDataModel.prototype.getMissingParams = function () { + mw.TemplateData.Model.prototype.getMissingParams = function () { var i, result = [], allParamNames = this.getAllParamNames(); @@ -314,7 +314,7 @@ * Add imported parameters into the model * @return {Object} Parameters added. -1 for failure. */ - TemplateDataModel.prototype.importSourceCodeParameters = function () { + mw.TemplateData.Model.prototype.importSourceCodeParameters = function () { var i, paramKey, allParamNames = this.getAllParamNames(), existingArray = [], @@ -356,7 +356,7 @@ * templatedata string was found. Null if the json string * failed to parse. */ - TemplateDataModel.prototype.getModelFromString = function ( templateDataString ) { + mw.TemplateData.Model.prototype.getModelFromString = function ( templateDataString ) { var parts; parts = templateDataString.match( @@ -381,7 +381,7 @@ * Retrieve all existing language codes in the current templatedata model * @return {string[]} Language codes in use */ - TemplateDataModel.prototype.getExistingLanguageCodes = function () { + mw.TemplateData.Model.prototype.getExistingLanguageCodes = function () { var param, prop, lang, result = [], languageProps = this.constructor.static.getPropertiesWithLanguage(); @@ -426,7 +426,7 @@ * @param {string} [wikitext] Optional. Source of the template. * @returns {jQuery.Promise} Promise resolving into template parameter array */ - TemplateDataModel.prototype.getParametersFromTemplateSource = function ( templateDataString ) { + mw.TemplateData.Model.prototype.getParametersFromTemplateSource = function ( templateDataString ) { var params = []; if ( !this.templateSourceCodePromise ) { @@ -485,7 +485,7 @@ * @returns {jQuery.Promise} A promise that resolves into an * array of parameters that appear in the template code */ - TemplateDataModel.prototype.extractParametersFromTemplateCode = function ( templateCode ) { + mw.TemplateData.Model.prototype.extractParametersFromTemplateCode = function ( templateCode ) { var matches, paramNames = [], paramExtractor = /{{3,}(.*?)[<|}]/mg; @@ -505,7 +505,7 @@ * @param {Object} [data] Parameter data * @return {boolean} Parameter was added successfully */ - TemplateDataModel.prototype.addParam = function ( key, paramData ) { + mw.TemplateData.Model.prototype.addParam = function ( key, paramData ) { var prop, name, lang, existingNames = this.getAllParamNames(), data = $.extend( true, {}, paramData ), @@ -565,7 +565,7 @@ * names can be different than their stored keys. * @return {string[]} Used parameter names */ - TemplateDataModel.prototype.getAllParamNames = function () { + mw.TemplateData.Model.prototype.getAllParamNames = function () { var param, result = []; for ( param in this.params ) { @@ -582,7 +582,7 @@ * will default to the wiki language. * @fires change-description */ - TemplateDataModel.prototype.setTemplateDescription = function ( desc, language ) { + mw.TemplateData.Model.prototype.setTemplateDescription = function ( desc, language ) { language = language || this.getDefaultLanguage(); if ( !this.constructor.static.compare( this.description[language], desc ) ) { @@ -603,7 +603,7 @@ * as multilanguage object and no language is set, the whole object * will be returned. */ - TemplateDataModel.prototype.getTemplateDescription = function ( language ) { + mw.TemplateData.Model.prototype.getTemplateDescription = function ( language ) { language = language || this.getDefaultLanguage(); return this.description[language]; }; @@ -614,7 +614,7 @@ * @param {string} [language] Optional language key * @return {string} Parameter description in given language. */ - TemplateDataModel.prototype.getParamDescription = function ( paramKey, language ) { + mw.TemplateData.Model.prototype.getParamDescription = function ( paramKey, language ) { language = language || this.getDefaultLanguage(); if ( this.params[paramKey] && this.params[paramKey].description ) { // Return description in this language or fall back @@ -627,7 +627,7 @@ * Get the current wiki language code. Defaults on 'en'. * @return {string} Wiki language */ - TemplateDataModel.prototype.getDefaultLanguage = function () { + mw.TemplateData.Model.prototype.getDefaultLanguage = function () { return mw.config.get( 'wgContentLanguage' ) || 'en'; }; @@ -636,7 +636,7 @@ * @param {string[]} orderArray Parameter key array in order * @fires change-paramOrder */ - TemplateDataModel.prototype.setTemplateParamOrder = function ( orderArray ) { + mw.TemplateData.Model.prototype.setTemplateParamOrder = function ( orderArray ) { orderArray = orderArray || []; // TODO: Make the compare method verify order of array? // Copy the array @@ -649,14 +649,14 @@ * @param {string} key New key the add into the paramOrder * @fires add-paramOrder */ - TemplateDataModel.prototype.addKeyTemplateParamOrder = function ( key ) { + mw.TemplateData.Model.prototype.addKeyTemplateParamOrder = function ( key ) { if ( $.inArray( key, this.paramOrder ) === -1 ) { this.paramOrder.push( key ); this.emit( 'add-paramOrder', key ); } }; - TemplateDataModel.prototype.reorderParamOrderKey = function ( key, newIndex ) { + mw.TemplateData.Model.prototype.reorderParamOrderKey = function ( key, newIndex ) { var keyIndex = this.paramOrder.indexOf( key ); // Move the parameter this.paramOrder.splice( @@ -675,7 +675,7 @@ * Add a key to the end of the paramOrder * @param {string} key New key the add into the paramOrder */ - TemplateDataModel.prototype.removeKeyTemplateParamOrder = function ( key ) { + mw.TemplateData.Model.prototype.removeKeyTemplateParamOrder = function ( key ) { var keyPos = $.inArray( key, this.paramOrder ); if ( keyPos > -1 ) { this.paramOrder.splice( keyPos, 1 ); @@ -687,7 +687,7 @@ * Retrieve the template paramOrder array * @return {string[]} orderArray Parameter keys in order */ - TemplateDataModel.prototype.getTemplateParamOrder = function () { + mw.TemplateData.Model.prototype.getTemplateParamOrder = function () { return this.paramOrder; }; @@ -700,7 +700,7 @@ * @returns {boolean} Operation was successful * @fires change-property */ - TemplateDataModel.prototype.setParamProperty = function ( paramKey, prop, value, language ) { + mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, value, language ) { var propertiesWithLanguage = this.constructor.static.getPropertiesWithLanguage(), allProps = this.constructor.static.getAllProperties( true ); @@ -746,7 +746,7 @@ * @param {string} paramKey Parameter key * @fires delete-param */ - TemplateDataModel.prototype.deleteParam = function ( paramKey ) { + mw.TemplateData.Model.prototype.deleteParam = function ( paramKey ) { this.params[paramKey].deleted = true; // Remove from paramOrder this.removeKeyTemplateParamOrder( paramKey ); @@ -758,7 +758,7 @@ * @param {string} paramKey Parameter key * @fires add-param */ - TemplateDataModel.prototype.restoreParam = function ( paramKey ) { + mw.TemplateData.Model.prototype.restoreParam = function ( paramKey ) { if ( this.params[paramKey] ) { this.params[paramKey].deleted = false; // Add back to paramOrder @@ -771,7 +771,7 @@ * Delete all data attached to a parameter * @param {string} paramKey Parameter key */ - TemplateDataModel.prototype.emptyParamData = function ( paramKey ) { + mw.TemplateData.Model.prototype.emptyParamData = function ( paramKey ) { if ( this.params[paramKey] ) { // Delete all data and readd the parameter delete this.params[paramKey]; @@ -788,7 +788,7 @@ * @return {Mixed...|null} Property value if it exists. Returns null if the * parameter key itself doesn't exist. */ - TemplateDataModel.prototype.getParamProperty = function ( paramKey, prop ) { + mw.TemplateData.Model.prototype.getParamProperty = function ( paramKey, prop ) { if ( this.params[paramKey] ) { return this.params[paramKey][prop]; } @@ -800,7 +800,7 @@ * @param {string} key Parameter key * @return {Object} Parameter data */ - TemplateDataModel.prototype.getParamData = function ( key ) { + mw.TemplateData.Model.prototype.getParamData = function ( key ) { return this.params[key]; }; @@ -808,15 +808,15 @@ * Return the complete object of all parameters. * @return {Object} All parameters and their data */ - TemplateDataModel.prototype.getParams = function () { + mw.TemplateData.Model.prototype.getParams = function () { return this.params; }; - TemplateDataModel.prototype.isParamDeleted = function ( key ) { + mw.TemplateData.Model.prototype.isParamDeleted = function ( key ) { return this.params[key].deleted === true; }; - TemplateDataModel.prototype.isParamExists = function ( key ) { + mw.TemplateData.Model.prototype.isParamExists = function ( key ) { return $.inArray( key, Object.keys( this.params ) ) > -1; }; @@ -824,7 +824,7 @@ * Set the original templatedata object * @param {Object} templatedataObj TemplateData object */ - TemplateDataModel.prototype.setOriginalTemplateDataObject = function ( templatedataObj ) { + mw.TemplateData.Model.prototype.setOriginalTemplateDataObject = function ( templatedataObj ) { this.originalTemplateDataObject = $.extend( true, {}, templatedataObj ); }; @@ -832,7 +832,7 @@ * Set is page sublevel * @param {Boolean} isSubLevel Page is sublevel */ - TemplateDataModel.prototype.setPageSubLevel = function ( isSubLevel ) { + mw.TemplateData.Model.prototype.setPageSubLevel = function ( isSubLevel ) { this.subLevel = isSubLevel; }; @@ -840,7 +840,7 @@ * Get full page name * @param {string} pageName Page name */ - TemplateDataModel.prototype.setFullPageName = function ( pageName ) { + mw.TemplateData.Model.prototype.setFullPageName = function ( pageName ) { this.fullPageName = pageName; }; @@ -848,7 +848,7 @@ * Set parent page * @param {string} Parent page */ - TemplateDataModel.prototype.setParentPage = function ( parent ) { + mw.TemplateData.Model.prototype.setParentPage = function ( parent ) { this.parentPage = parent; }; @@ -856,7 +856,7 @@ * Get is page sublevel * @return {boolean} Page is sublevel */ - TemplateDataModel.prototype.isPageSubLevel = function () { + mw.TemplateData.Model.prototype.isPageSubLevel = function () { return this.subLevel; }; @@ -864,7 +864,7 @@ * Get page full name * @return {string} Page full name */ - TemplateDataModel.prototype.getFullPageName = function () { + mw.TemplateData.Model.prototype.getFullPageName = function () { return this.fullPageName; }; @@ -872,7 +872,7 @@ * Get parent page * @return {string} Parent page */ - TemplateDataModel.prototype.getParentPage = function () { + mw.TemplateData.Model.prototype.getParentPage = function () { return this.parentPage; }; @@ -880,7 +880,7 @@ * Get original templatedata object * @return {Object} Templatedata object */ - TemplateDataModel.prototype.getOriginalTemplateDataObject = function () { + mw.TemplateData.Model.prototype.getOriginalTemplateDataObject = function () { return this.originalTemplateDataObject; }; @@ -888,7 +888,7 @@ * Process the current model and output it as a complete templatedata string * @return {string} Templatedata String */ - TemplateDataModel.prototype.outputTemplateDataString = function () { + mw.TemplateData.Model.prototype.outputTemplateDataString = function () { var param, paramKey, key, prop, oldKey, name, compareOrig, normalizedValue, allProps = this.constructor.static.getAllProperties( true ), original = this.getOriginalTemplateDataObject(), @@ -1039,7 +1039,7 @@ * @param {string} key New parameter key * @return {string} Valid new parameter key */ - TemplateDataModel.prototype.getNewValidParameterKey = function ( key ) { + mw.TemplateData.Model.prototype.getNewValidParameterKey = function ( key ) { var allParamNames = this.getAllParamNames(); if ( this.params[key] || $.inArray( key, allParamNames ) !== -1 ) { // Change the key to be something else @@ -1054,7 +1054,7 @@ * Go over a language property and remove empty language key values * @return {Object} Property data with only used language keys */ - TemplateDataModel.prototype.propRemoveUnusedLanguages = function ( propData ) { + mw.TemplateData.Model.prototype.propRemoveUnusedLanguages = function ( propData ) { var key, result = {}; if ( $.isPlainObject( propData ) ) { @@ -1074,7 +1074,7 @@ * @param {string} prop Param property * @return {boolean} Output should be a full language object */ - TemplateDataModel.prototype.isOutputInLanguageObject = function ( originalPropValue, newPropValue ) { + mw.TemplateData.Model.prototype.isOutputInLanguageObject = function ( originalPropValue, newPropValue ) { if ( ( // The original was already split to languages diff --git a/modules/ext.templateDataGenerator.js b/modules/ext.templateDataGenerator.js new file mode 100644 index 0000000..8a134c4 --- /dev/null +++ b/modules/ext.templateDataGenerator.js @@ -0,0 +1 @@ +mw.TemplateData = {}; diff --git a/modules/ext.templateDataGenerator.ui.js b/modules/ext.templateDataGenerator.ui.js index 5bb4667..ef3ad11 100644 --- a/modules/ext.templateDataGenerator.ui.js +++ b/modules/ext.templateDataGenerator.ui.js @@ -141,7 +141,7 @@ // Dialog windowManager = new OO.ui.WindowManager(); - tdgDialog = new TemplateDataDialog( config ); + tdgDialog = new mw.TemplateData.Dialog( config ); windowManager.addWindows( [ tdgDialog ] ); // Prepend to container diff --git a/modules/ext.templateDataGenerator.ui.tdDialog.js b/modules/ext.templateDataGenerator.ui.tdDialog.js index 71e07f2..03b8a0a 100644 --- a/modules/ext.templateDataGenerator.ui.tdDialog.js +++ b/modules/ext.templateDataGenerator.ui.tdDialog.js @@ -1,11 +1,11 @@ - ( function ( mw ) { +( function ( mw ) { /** * TemplateData Dialog * @param {Object} config Dialog configuration object */ - TemplateDataDialog = function TemplateDataDialog( config ) { + mw.TemplateData.Dialog = function mwTemplateDataDialog( config ) { // Parent constructor - TemplateDataDialog.super.call( this, config ); + mw.TemplateData.Dialog.super.call( this, config ); this.model = null; this.language = null; @@ -18,13 +18,13 @@ this.$element.addClass( 'tdg-TemplateDataDialog' ); }; - OO.inheritClass( TemplateDataDialog, OO.ui.ProcessDialog ); + OO.inheritClass( mw.TemplateData.Dialog, OO.ui.ProcessDialog ); /* Static properties */ - TemplateDataDialog.static.name = 'TemplateDataDialog'; - TemplateDataDialog.static.title = mw.msg( 'templatedata-modal-title' ); - TemplateDataDialog.static.size = 'large'; - TemplateDataDialog.static.actions = [ + mw.TemplateData.Dialog.static.name = 'TemplateDataDialog'; + mw.TemplateData.Dialog.static.title = mw.msg( 'templatedata-modal-title' ); + mw.TemplateData.Dialog.static.size = 'large'; + mw.TemplateData.Dialog.static.actions = [ { action: 'apply', label: mw.msg( 'templatedata-modal-button-apply' ), @@ -59,12 +59,12 @@ /** * @inheritDoc */ - TemplateDataDialog.prototype.initialize = function () { + mw.TemplateData.Dialog.prototype.initialize = function () { var templateParamsFieldset, addParamFieldlayout, languageActionFieldLayout, paramOrderFieldset; // Parent method - TemplateDataDialog.super.prototype.initialize.call( this ); + mw.TemplateData.Dialog.super.prototype.initialize.call( this ); this.$spinner = this.$( '<div>' ).addClass( 'tdg-spinner' ).text( 'working...' ); this.$body.append( this.$spinner ); @@ -89,7 +89,7 @@ } ); // Language panel - this.newLanguageSearchWidget = new TemplateDataLanguageSearchWidget( { + this.newLanguageSearchWidget = new mw.TemplateData.LanguageSearchWidget( { $: this.$ } ); @@ -125,7 +125,7 @@ ); // ParamOrder - this.paramOrderWidget = new TemplateDataDragDropWidget( { + this.paramOrderWidget = new mw.TemplateData.DragDropWidget( { $: this.$, orientation: 'horizontal' } ); @@ -220,11 +220,11 @@ * @param {jQuery.event} event Event details * @param {string} description New description */ - TemplateDataDialog.prototype.onModelChangeDescription = function ( description ) { + mw.TemplateData.Dialog.prototype.onModelChangeDescription = function ( description ) { this.descriptionInput.setValue( description ); }; - TemplateDataDialog.prototype.onAddParamInputChange = function ( value ) { + mw.TemplateData.Dialog.prototype.onAddParamInputChange = function ( value ) { if ( this.model.isParamExists( value ) && !this.model.isParamDeleted( value ) ) { // Disable the add button this.addParamButton.setDisabled( true ); @@ -237,14 +237,14 @@ * Respond to change of paramOrder from the model * @param {string[]} paramOrderArray The array of keys in order */ - TemplateDataDialog.prototype.onModelChangeParamOrder = function ( paramOrderArray ) { + mw.TemplateData.Dialog.prototype.onModelChangeParamOrder = function ( paramOrderArray ) { var i, items = []; this.paramOrderWidget.clearItems(); for ( i = 0; i < paramOrderArray.length; i++ ) { items.push( - new TemplateDataDragDropItemWidget( { + new mw.TemplateData.DragDropItemWidget( { $: this.$, data: paramOrderArray[i], label: paramOrderArray[i] @@ -261,8 +261,8 @@ * Respond to an addition of a key to the model paramOrder * @param {string} key Added key */ - TemplateDataDialog.prototype.onModelAddKeyParamOrder = function ( key ) { - var dragItem = new TemplateDataDragDropItemWidget( { + mw.TemplateData.Dialog.prototype.onModelAddKeyParamOrder = function ( key ) { + var dragItem = new mw.TemplateData.DragDropItemWidget( { $: this.$, data: key, label: key @@ -271,14 +271,14 @@ this.paramOrderWidget.addItems( [ dragItem ] ); }; - TemplateDataDialog.prototype.onParamOrderWidgetReorder = function ( item, newIndex ) { + mw.TemplateData.Dialog.prototype.onParamOrderWidgetReorder = function ( item, newIndex ) { this.model.reorderParamOrderKey( item.getData(), newIndex ); }; /** * Respond to description input change event */ - TemplateDataDialog.prototype.onDescriptionInputChange = function ( value ) { + mw.TemplateData.Dialog.prototype.onDescriptionInputChange = function ( value ) { if ( this.model.getTemplateDescription() !== value ) { this.model.setTemplateDescription( value, this.language ); } @@ -287,7 +287,7 @@ /** * Respond to add language button click */ - TemplateDataDialog.prototype.onLanguagePanelButton = function () { + mw.TemplateData.Dialog.prototype.onLanguagePanelButton = function () { this.switchPanels( 'language' ); }; @@ -295,7 +295,7 @@ * Respond to language select widget choose event * @param {OO.ui.OptionWidget} item Chosen item */ - TemplateDataDialog.prototype.onLanguageDropdownWidgetChoose = function ( item ) { + mw.TemplateData.Dialog.prototype.onLanguageDropdownWidgetChoose = function ( item ) { var language = item ? item.getData() : this.language; // Change current language @@ -322,7 +322,7 @@ * Respond to add language button * @param {Object} data Data from the selected option widget */ - TemplateDataDialog.prototype.newLanguageSearchWidgetSelect = function ( data ) { + mw.TemplateData.Dialog.prototype.newLanguageSearchWidgetSelect = function ( data ) { var languageButton, newLanguage = data.code; @@ -351,9 +351,9 @@ /** * Respond to add parameter button */ - TemplateDataDialog.prototype.onAddParamButtonClick = function () { + mw.TemplateData.Dialog.prototype.onAddParamButtonClick = function () { var newParamKey = this.newParamInput.getValue(), - allProps = TemplateDataModel.static.getAllProperties( true ); + allProps = mw.TemplateData.Model.static.getAllProperties( true ); // Validate parameter if ( @@ -382,7 +382,7 @@ * Respond to choose event from the param select widget * @param {OO.ui.OptionWidget} item Parameter item */ - TemplateDataDialog.prototype.onParamSelectWidgetChoose = function ( item ) { + mw.TemplateData.Dialog.prototype.onParamSelectWidgetChoose = function ( item ) { var paramKey = item.getData(); if ( paramKey === 'tdg-importParameters' ) { @@ -397,10 +397,10 @@ } }; - TemplateDataDialog.prototype.onParamPropertyInputChange = function ( property, value ) { + mw.TemplateData.Dialog.prototype.onParamPropertyInputChange = function ( property, value ) { var err = false, anyInputError = false, - allProps = TemplateDataModel.static.getAllProperties( true ); + allProps = mw.TemplateData.Model.static.getAllProperties( true ); if ( property === 'type' ) { value = this.propInputs[property].getMenu().getSelectedItem() ? this.propInputs[property].getMenu().getSelectedItem().getData() : 'undefined'; @@ -436,7 +436,7 @@ * Set the parameter details in the detail panel. * @param {Object} paramKey Parameter details */ - TemplateDataDialog.prototype.getParameterDetails = function ( paramKey ) { + mw.TemplateData.Dialog.prototype.getParameterDetails = function ( paramKey ) { var prop, paramData = this.model.getParamData( paramKey ); @@ -448,7 +448,7 @@ /** * Reset contents on reload */ - TemplateDataDialog.prototype.reset = function () { + mw.TemplateData.Dialog.prototype.reset = function () { this.language = null; this.availableLanguages = []; if ( this.paramSelectWidget ) { @@ -468,7 +468,7 @@ /** * Empty and repopulate the parameter select widget. */ - TemplateDataDialog.prototype.repopulateParamSelectWidget = function () { + mw.TemplateData.Dialog.prototype.repopulateParamSelectWidget = function () { var i, paramKey, missingParams = this.model.getMissingParams(), paramList = this.model.getParams(), @@ -489,7 +489,7 @@ if ( missingParams.length > 0 ) { // Add a final option this.paramSelectWidget.addItems( [ - new TemplateDataOptionImportWidget( { + new mw.TemplateData.OptionImportWidget( { data: 'tdg-importParameters', $: this.$, params: missingParams @@ -505,9 +505,9 @@ * @param {string} propVal Property value * @param {string} [lang] Language */ - TemplateDataDialog.prototype.changeParamPropertyInput = function ( paramKey, propName, value, lang ) { - var languageProps = TemplateDataModel.static.getPropertiesWithLanguage(), - allProps = TemplateDataModel.static.getAllProperties( true ), + mw.TemplateData.Dialog.prototype.changeParamPropertyInput = function ( paramKey, propName, value, lang ) { + var languageProps = mw.TemplateData.Model.static.getPropertiesWithLanguage(), + allProps = mw.TemplateData.Model.static.getAllProperties( true ), prop = allProps[propName], propInput = typeof this.propInputs[propName].getMenu === 'function' ? this.propInputs[propName].getMenu() : this.propInputs[propName]; @@ -545,11 +545,11 @@ * @param {string} paramKey Parameter key in the model * @param {Object} paramData Parameter data */ - TemplateDataDialog.prototype.addParamToSelectWidget = function ( paramKey ) { + mw.TemplateData.Dialog.prototype.addParamToSelectWidget = function ( paramKey ) { var paramItem, data = this.model.getParamData( paramKey ); - paramItem = new TemplateDataOptionWidget( { + paramItem = new mw.TemplateData.OptionWidget( { data: { key: paramKey, name: data.name, @@ -566,12 +566,12 @@ * Create the information page about individual parameters * @returns {jQuery} Editable details page for the parameter */ - TemplateDataDialog.prototype.createParamDetails = function () { + mw.TemplateData.Dialog.prototype.createParamDetails = function () { var props, type, propInput, config, paramProperties, paramFieldset, typeItemArray = []; - paramProperties = TemplateDataModel.static.getAllProperties( true ); + paramProperties = mw.TemplateData.Model.static.getAllProperties( true ); // Fieldset paramFieldset = new OO.ui.FieldsetLayout( { @@ -638,9 +638,9 @@ * @param {string} [lang] Language. If not used, will use currently defined * language. */ - TemplateDataDialog.prototype.updateParamDetailsLanguage = function ( lang ) { + mw.TemplateData.Dialog.prototype.updateParamDetailsLanguage = function ( lang ) { var i, prop, label, - languageProps = TemplateDataModel.static.getPropertiesWithLanguage(); + languageProps = mw.TemplateData.Model.static.getPropertiesWithLanguage(); lang = lang || this.language; for ( i = 0; i < languageProps.length; i++ ) { @@ -654,7 +654,7 @@ * Override getBodyHeight to create a tall dialog relative to the screen. * @return {number} Body height */ - TemplateDataDialog.prototype.getBodyHeight = function () { + mw.TemplateData.Dialog.prototype.getBodyHeight = function () { return window.innerHeight - 200; }; @@ -665,7 +665,7 @@ * @param {string} status Message status 'error' or 'success' * @param {string|string[]} noticeMessage The message to display */ - TemplateDataDialog.prototype.toggleNoticeMessage = function ( type, isShowing, status, noticeMessage ) { + mw.TemplateData.Dialog.prototype.toggleNoticeMessage = function ( type, isShowing, status, noticeMessage ) { var noticeReference, $message; @@ -706,7 +706,7 @@ /** * Import parameters from the source code. */ - TemplateDataDialog.prototype.importParametersFromTemplateCode = function () { + mw.TemplateData.Dialog.prototype.importParametersFromTemplateCode = function () { var combinedMessage = [], state = 'success', response = this.model.importSourceCodeParameters(); @@ -730,8 +730,8 @@ /** * @inheritDoc */ - TemplateDataDialog.prototype.getSetupProcess = function ( data ) { - return TemplateDataDialog.super.prototype.getSetupProcess.call( this, data ) + mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) { + return mw.TemplateData.Dialog.super.prototype.getSetupProcess.call( this, data ) .next( function () { this.reset(); // Hide the panels and display a spinner @@ -742,7 +742,7 @@ // Start with parameter list this.switchPanels( 'listParams' ); - this.model = new TemplateDataModel( data.config ); + this.model = new mw.TemplateData.Model( data.config ); // Events this.model.connect( this, { @@ -807,7 +807,7 @@ * Set up the list of parameters from the model. This should happen * after initialization of the model. */ - TemplateDataDialog.prototype.setupDetailsFromModel = function () { + mw.TemplateData.Dialog.prototype.setupDetailsFromModel = function () { // Set up description this.descriptionInput.setValue( this.model.getTemplateDescription( this.language ) ); // Repopulate the parameter list @@ -818,7 +818,7 @@ * Switch between stack layout panels * @param {string} panel Panel key to switch to */ - TemplateDataDialog.prototype.switchPanels = function ( panel ) { + mw.TemplateData.Dialog.prototype.switchPanels = function ( panel ) { switch ( panel ) { case 'listParams': this.actions.setMode( 'list' ); @@ -872,7 +872,7 @@ /** * @inheritDoc */ - TemplateDataDialog.prototype.getActionProcess = function ( action ) { + mw.TemplateData.Dialog.prototype.getActionProcess = function ( action ) { if ( action === 'back' ) { return new OO.ui.Process( function () { this.switchPanels( 'listParams' ); @@ -896,6 +896,6 @@ }, this ); } // Fallback to parent handler - return TemplateDataDialog.super.prototype.getActionProcess.call( this, action ); + return mw.TemplateData.Dialog.super.prototype.getActionProcess.call( this, action ); }; }( mediaWiki ) ); diff --git a/modules/widgets/ext.templateDataGenerator.dragDropItemWidget.js b/modules/widgets/ext.templateDataGenerator.dragDropItemWidget.js index 612e6f0..e2a4c18 100644 --- a/modules/widgets/ext.templateDataGenerator.dragDropItemWidget.js +++ b/modules/widgets/ext.templateDataGenerator.dragDropItemWidget.js @@ -9,12 +9,12 @@ * @param {Mixed} data Option data * @param {Object} [config] Configuration options */ -TemplateDataDragDropItemWidget = function TemplateDataDragDropItemWidget( config ) { +mw.TemplateData.DragDropItemWidget = function mwTemplateDataDragDropItemWidget( config ) { // Configuration initialization config = config || {}; // Parent constructor - TemplateDataDragDropItemWidget.super.call( this, $.extend( {}, { icon: 'parameter' }, config ) ); + mw.TemplateData.DragDropItemWidget.super.call( this, $.extend( {}, { icon: 'parameter' }, config ) ); // Mixin constructors OO.ui.DraggableElement.call( this, config ); @@ -26,5 +26,5 @@ /* Setup */ -OO.inheritClass( TemplateDataDragDropItemWidget, OO.ui.DecoratedOptionWidget ); -OO.mixinClass( TemplateDataDragDropItemWidget, OO.ui.DraggableElement ); +OO.inheritClass( mw.TemplateData.DragDropItemWidget, OO.ui.DecoratedOptionWidget ); +OO.mixinClass( mw.TemplateData.DragDropItemWidget, OO.ui.DraggableElement ); diff --git a/modules/widgets/ext.templateDataGenerator.dragDropWidget.js b/modules/widgets/ext.templateDataGenerator.dragDropWidget.js index c48af7f..b00bf45 100644 --- a/modules/widgets/ext.templateDataGenerator.dragDropWidget.js +++ b/modules/widgets/ext.templateDataGenerator.dragDropWidget.js @@ -11,12 +11,12 @@ * @param {Object} [config] Configuration options * @cfg {OO.ui.OptionWidget[]} [items] Options to add */ -TemplateDataDragDropWidget = function TemplateDataDragDropWidget( config ) { +mw.TemplateData.DragDropWidget = function mwTemplateDataDragDropWidget( config ) { // Configuration initialization config = config || {}; // Parent constructor - TemplateDataDragDropWidget.super.call( this, config ); + mw.TemplateData.DragDropWidget.super.call( this, config ); // Mixin constructors OO.ui.DraggableGroupElement.call( this, $.extend( {}, config, { $group: this.$element } ) ); @@ -27,14 +27,14 @@ /* Setup */ -OO.inheritClass( TemplateDataDragDropWidget, OO.ui.Widget ); -OO.mixinClass( TemplateDataDragDropWidget, OO.ui.DraggableGroupElement ); +OO.inheritClass( mw.TemplateData.DragDropWidget, OO.ui.Widget ); +OO.mixinClass( mw.TemplateData.DragDropWidget, OO.ui.DraggableGroupElement ); /** * Get an array of keys based on the current items, in order * @return {string[]} Array of keys */ -TemplateDataDragDropWidget.prototype.getKeyArray = function () { +mw.TemplateData.DragDropWidget.prototype.getKeyArray = function () { var i, len, arr = []; @@ -51,7 +51,7 @@ * @param {string} key Unique key * @param {[type]} newIndex New index */ -TemplateDataDragDropWidget.prototype.reorderKey = function ( key, newIndex ) { +mw.TemplateData.DragDropWidget.prototype.reorderKey = function ( key, newIndex ) { var i, len, item; // Get the item that belongs to this key diff --git a/modules/widgets/ext.templateDataGenerator.languageResultWidget.js b/modules/widgets/ext.templateDataGenerator.languageResultWidget.js index 9f889fa..3e0dcbf 100644 --- a/modules/widgets/ext.templateDataGenerator.languageResultWidget.js +++ b/modules/widgets/ext.templateDataGenerator.languageResultWidget.js @@ -8,7 +8,7 @@ * @constructor * @param {Object} [config] Configuration options */ -TemplateDataLanguageResultWidget = function TemplateDataLanguageResultWidget( config ) { +mw.TemplateData.LanguageResultWidget = function mwTemplateDataLanguageResultWidget( config ) { // Parent constructor OO.ui.OptionWidget.call( this, config ); @@ -21,7 +21,7 @@ /* Inheritance */ -OO.inheritClass( TemplateDataLanguageResultWidget, OO.ui.OptionWidget ); +OO.inheritClass( mw.TemplateData.LanguageResultWidget, OO.ui.OptionWidget ); /* Methods */ @@ -32,7 +32,7 @@ * @param {string} [matchedProperty] Data property which matched the query text * @chainable */ -TemplateDataLanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty ) { +mw.TemplateData.LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty ) { var $highlighted, data = this.getData(); // Reset text @@ -59,7 +59,7 @@ * @param {string} query Query to find * @returns {jQuery} Text with query substring wrapped in highlighted span */ -TemplateDataLanguageResultWidget.prototype.highlightQuery = function ( text, query ) { +mw.TemplateData.LanguageResultWidget.prototype.highlightQuery = function ( text, query ) { var $result = this.$( '<span>' ), offset = text.toLowerCase().indexOf( query.toLowerCase() ); diff --git a/modules/widgets/ext.templateDataGenerator.languageSearchWidget.js b/modules/widgets/ext.templateDataGenerator.languageSearchWidget.js index c692dae..94ab009 100644 --- a/modules/widgets/ext.templateDataGenerator.languageSearchWidget.js +++ b/modules/widgets/ext.templateDataGenerator.languageSearchWidget.js @@ -8,7 +8,7 @@ * @constructor * @param {Object} [config] Configuration options */ -TemplateDataLanguageSearchWidget = function TemplateDataLanguageSearchWidget( config ) { +mw.TemplateData.LanguageSearchWidget = function mwTemplateDataLanguageSearchWidget( config ) { // Configuration intialization config = $.extend( { placeholder: mw.msg( 'templatedata-modal-search-input-placeholder' ) @@ -26,7 +26,7 @@ for ( i = 0, l = languageCodes.length; i < l; i++ ) { languageCode = languageCodes[i]; this.languageResultWidgets.push( - new TemplateDataLanguageResultWidget( { + new mw.TemplateData.LanguageResultWidget( { data: { code: languageCode, name: $.uls.data.getAutonym( languageCode ), @@ -43,14 +43,14 @@ /* Inheritance */ -OO.inheritClass( TemplateDataLanguageSearchWidget, OO.ui.SearchWidget ); +OO.inheritClass( mw.TemplateData.LanguageSearchWidget, OO.ui.SearchWidget ); /* Methods */ /** * @inheritdoc */ -TemplateDataLanguageSearchWidget.prototype.onQueryChange = function () { +mw.TemplateData.LanguageSearchWidget.prototype.onQueryChange = function () { // Parent method OO.ui.SearchWidget.prototype.onQueryChange.call( this ); @@ -61,7 +61,7 @@ /** * Update search results from current query */ -TemplateDataLanguageSearchWidget.prototype.addResults = function () { +mw.TemplateData.LanguageSearchWidget.prototype.addResults = function () { var i, iLen, j, jLen, languageResult, data, matchedProperty, matchProperties = ['name', 'autonym', 'code'], query = this.query.getValue().trim(), @@ -107,6 +107,6 @@ * @param {string} value Text * @returns {string} Text escaped for use in regex */ -TemplateDataLanguageSearchWidget.static.escapeRegex = function ( value ) { +mw.TemplateData.LanguageSearchWidget.static.escapeRegex = function ( value ) { return value.replace( /[\-\[\]{}()*+?.,\\\^$\|#\s]/g, '\\$&' ); }; diff --git a/modules/widgets/ext.templateDataGenerator.optionImportWidget.js b/modules/widgets/ext.templateDataGenerator.optionImportWidget.js index 91939d9..246e0d0 100644 --- a/modules/widgets/ext.templateDataGenerator.optionImportWidget.js +++ b/modules/widgets/ext.templateDataGenerator.optionImportWidget.js @@ -3,11 +3,11 @@ * @extends {OO.ui.DecoratedOptionWidget} * @param {Object} config Dialog configuration object */ -TemplateDataOptionImportWidget = function TemplateDataOptionImportWidget( config ) { +mw.TemplateData.OptionImportWidget = function wgTemplateDataOptionImportWidget( config ) { config = config || {}; // Parent constructor - TemplateDataOptionImportWidget.super.call( this, $.extend( {}, config, { icon: 'parameter-set' } ) ); + mw.TemplateData.OptionImportWidget.super.call( this, $.extend( {}, config, { icon: 'parameter-set' } ) ); this.params = config.params; @@ -16,14 +16,14 @@ this.buildParamLabel(); }; -OO.inheritClass( TemplateDataOptionImportWidget, OO.ui.DecoratedOptionWidget ); +OO.inheritClass( mw.TemplateData.OptionImportWidget, OO.ui.DecoratedOptionWidget ); /** * Build the parameter label in the parameter select widget * @param {Object} paramData Parameter data * @return {jQuery} Label element */ -TemplateDataOptionImportWidget.prototype.buildParamLabel = function () { +mw.TemplateData.OptionImportWidget.prototype.buildParamLabel = function () { var paramNames = this.params.slice( 0, 9 ).join( mw.msg( 'comma-separator' ) ), $paramName = this.$( '<div>' ) .addClass( 'tdg-TemplateDataOptionWidget-param-name' ), diff --git a/modules/widgets/ext.templateDataGenerator.optionWidget.js b/modules/widgets/ext.templateDataGenerator.optionWidget.js index ab4d795..6ddfede 100644 --- a/modules/widgets/ext.templateDataGenerator.optionWidget.js +++ b/modules/widgets/ext.templateDataGenerator.optionWidget.js @@ -3,13 +3,13 @@ * @extends {OO.ui.DecoratedOptionWidget} * @param {Object} config Dialog configuration object */ -TemplateDataOptionWidget = function TemplateDataOptionWidget( config ) { +mw.TemplateData.OptionWidget = function mwTemplateDataOptionWidget( config ) { var data; config = config || {}; data = config.data || {}; // Parent constructor - TemplateDataOptionWidget.super.call( this, $.extend( {}, config, { data: data.key, icon: 'parameter' } ) ); + mw.TemplateData.OptionWidget.super.call( this, $.extend( {}, config, { data: data.key, icon: 'parameter' } ) ); this.key = data.key; this.name = data.name; @@ -21,14 +21,14 @@ this.buildParamLabel(); }; -OO.inheritClass( TemplateDataOptionWidget, OO.ui.DecoratedOptionWidget ); +OO.inheritClass( mw.TemplateData.OptionWidget, OO.ui.DecoratedOptionWidget ); /** * Build the parameter label in the parameter select widget * @param {Object} paramData Parameter data * @return {jQuery} Label element */ -TemplateDataOptionWidget.prototype.buildParamLabel = function () { +mw.TemplateData.OptionWidget.prototype.buildParamLabel = function () { var i, len, $paramName = this.$( '<div>' ) .addClass( 'tdg-TemplateDataOptionWidget-param-name' ), diff --git a/tests/ext.templateData.tests.js b/tests/ext.templateData.tests.js index ad37400..c1e09d5 100644 --- a/tests/ext.templateData.tests.js +++ b/tests/ext.templateData.tests.js @@ -12,7 +12,7 @@ resultDescMockLang = {}, resultDescBothLang = {}, currLanguage = mw.config.get( 'wgContentLanguage' ) || 'en', - model = new TemplateDataModel(), + model = new mw.TemplateData.Model(), originalWikitext = 'Some text here that is not templatedata information.' + '<templatedata>' + '{' + @@ -365,7 +365,7 @@ for ( i = 0; i < tests.compare.length; i++ ) { testVars = tests.compare[i]; assert.equal( - TemplateDataModel.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ), + mw.TemplateData.Model.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ), testVars.result, testVars.msg ); @@ -375,7 +375,7 @@ for ( i = 0; i < tests.splitAndTrimArray.length; i++ ) { testVars = tests.splitAndTrimArray[i]; assert.deepEqual( - TemplateDataModel.static.splitAndTrimArray( testVars.string, testVars.delim ), + mw.TemplateData.Model.static.splitAndTrimArray( testVars.string, testVars.delim ), testVars.result, testVars.msg ); @@ -385,7 +385,7 @@ for ( i = 0; i < tests.arrayUnionWithoutEmpty.length; i++ ) { testVars = tests.arrayUnionWithoutEmpty[i]; assert.deepEqual( - TemplateDataModel.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ), + mw.TemplateData.Model.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ), testVars.result, testVars.msg ); @@ -393,12 +393,12 @@ // Props assert.deepEqual( - TemplateDataModel.static.getAllProperties( false ), + mw.TemplateData.Model.static.getAllProperties( false ), tests.props.all, 'All properties' ); assert.deepEqual( - TemplateDataModel.static.getPropertiesWithLanguage(), + mw.TemplateData.Model.static.getPropertiesWithLanguage(), tests.props.language, 'Language properties' ); -- To view, visit https://gerrit.wikimedia.org/r/191217 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib514378c9fbc0fb993b3cbc2fa48ced920167226 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TemplateData Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits