Remove unnecessary context variables

Change-Id: I5e715dd77a81bd42570e87e9fae67f5687b78e12
This commit is contained in:
Ed Sanders 2024-09-16 16:04:30 +01:00
parent 7b3ee1d90b
commit c927748304
4 changed files with 30 additions and 40 deletions

View file

@ -312,15 +312,14 @@ Model.prototype.getMissingParams = function () {
* @return {Object} Parameters added. -1 for failure.
*/
Model.prototype.importSourceCodeParameters = function () {
const model = this,
allParamNames = this.getAllParamNames(),
const allParamNames = this.getAllParamNames(),
existingArray = [],
importedArray = [],
skippedArray = [];
// Check existing params
allParamNames.forEach( ( paramKey ) => {
if ( model.sourceCodeParameters.indexOf( paramKey ) !== -1 ) {
if ( this.sourceCodeParameters.indexOf( paramKey ) !== -1 ) {
existingArray.push( paramKey );
}
} );
@ -328,7 +327,7 @@ Model.prototype.importSourceCodeParameters = function () {
// Add sourceCodeParameters to the model
this.sourceCodeParameters.forEach( ( sourceCodeParameter ) => {
if ( existingArray.indexOf( sourceCodeParameter ) === -1 ) {
model.addParam( sourceCodeParameter );
this.addParam( sourceCodeParameter );
importedArray.push( sourceCodeParameter );
} else {
skippedArray.push( sourceCodeParameter );

View file

@ -114,8 +114,6 @@ SourceHandler.prototype.buildModel = function ( wikitext ) {
* @return {jQuery.Promise} Promise resolving into template parameter array
*/
SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext ) {
const sourceHandler = this;
let params = [];
if ( !this.templateSourceCodePromise ) {
// Check given page text first
@ -141,7 +139,7 @@ SourceHandler.prototype.getParametersFromTemplateSource = function ( wikitext )
) {
pageContent = resp.query.pages[ resp.query.pageids[ 0 ] ].revisions[ 0 ][ '*' ];
}
return sourceHandler.extractParametersFromTemplateCode( pageContent );
return this.extractParametersFromTemplateCode( pageContent );
},
// Resolve an empty parameters array
() => $.Deferred().resolve( [] )

View file

@ -1337,7 +1337,7 @@ Dialog.prototype.importParametersFromTemplateCode = function () {
*/
Dialog.prototype.getSetupProcess = function ( data ) {
return Dialog.super.prototype.getSetupProcess.call( this, data )
.next( function () {
.next( () => {
this.isSetup = false;
this.reset();
@ -1397,7 +1397,7 @@ Dialog.prototype.getSetupProcess = function ( data ) {
this.panels.$element.show();
this.actions.setAbilities( { apply: false } );
}, this );
} );
};
/**
@ -1494,64 +1494,63 @@ Dialog.prototype.switchPanels = function ( panel ) {
*/
Dialog.prototype.getActionProcess = function ( action ) {
if ( action === 'add' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
this.switchPanels( this.addParamPanel );
}, this );
} );
}
if ( action === 'done' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
// setMapInfo with the value and keep the done button active
this.model.setMapInfo( this.mapsCache );
this.model.originalMaps = OO.copy( this.mapsCache );
this.switchPanels();
}, this );
} );
}
if ( action === 'back' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
this.switchPanels();
}, this );
} );
}
if ( action === 'maps' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
this.switchPanels( this.editMapsPanel );
}, this );
} );
}
if ( action === 'cancel' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
this.mapsCache = OO.copy( this.model.getOriginalMapsInfo() );
this.model.restoreOriginalMaps();
this.populateMapsItems( this.mapsCache );
this.onCancelAddingMap();
this.switchPanels();
}, this );
} );
}
if ( action === 'delete' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
this.model.deleteParam( this.selectedParamKey );
this.switchPanels();
}, this );
} );
}
if ( action === 'apply' ) {
return new OO.ui.Process( function () {
return new OO.ui.Process( () => {
Metrics.logEvent( this.model.getOriginalTemplateDataObject() ?
'save-page-edit' : 'save-page-create' );
this.emit( 'apply', this.model.outputTemplateData() );
this.close( { action: action } );
}, this );
} );
}
if ( !action && this.modified ) {
return new OO.ui.Process( function () {
const dialog = this;
return OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) )
return new OO.ui.Process(
() => OO.ui.confirm( mw.msg( 'templatedata-modal-confirmcancel' ) )
.then( ( result ) => {
if ( result ) {
dialog.close();
this.close();
} else {
return $.Deferred().resolve().promise();
}
} );
}, this );
} )
);
}
// Fallback to parent handler
return Dialog.super.prototype.getActionProcess.call( this, action );

View file

@ -15,8 +15,6 @@ const Dialog = require( './Dialog.js' ),
* @param {Object} config
*/
function Target( $textarea, config ) {
const target = this;
// Parent constructor
Target.super.call( this, config );
@ -86,7 +84,7 @@ function Target( $textarea, config ) {
mw.message( 'templatedata-string-exists-hack-message' ).parse()
);
target.setEditNoticeMessage( msg, 'warning' );
this.setEditNoticeMessage( msg, 'warning' );
}
}
} );
@ -154,8 +152,6 @@ Target.prototype.openEditDialog = function ( dataModel ) {
* @method onEditOpenDialogButton
*/
Target.prototype.onEditOpenDialogButton = function () {
const target = this;
this.originalWikitext = this.$textarea.textSelection( 'getContents' );
// Build the model
@ -163,7 +159,7 @@ Target.prototype.onEditOpenDialogButton = function () {
.then(
// Success
( model ) => {
target.openEditDialog( model );
this.openEditDialog( model );
},
// Failure
() => {
@ -189,9 +185,9 @@ Target.prototype.onEditOpenDialogButton = function () {
// Open the dialog with an empty model
const model = Model.static.newFromObject(
null,
target.sourceHandler.getTemplateSourceCodeParams()
this.sourceHandler.getTemplateSourceCodeParams()
);
target.openEditDialog( model );
this.openEditDialog( model );
}
} );
}
@ -246,8 +242,6 @@ Target.prototype.replaceTemplateData = function ( newTemplateData ) {
* @param {Object} templateData New templatedata
*/
Target.prototype.onDialogApply = function ( templateData ) {
const target = this;
if (
Object.keys( templateData ).length > 1 ||
Object.keys( templateData.params ).length > 0
@ -270,7 +264,7 @@ Target.prototype.onDialogApply = function ( templateData ) {
]
} ).closed.then( ( data ) => {
if ( data && data.action === 'apply' ) {
target.replaceTemplateData( templateData );
this.replaceTemplateData( templateData );
}
} );
}