Merge "Remove unnecessary context variables"

This commit is contained in:
jenkins-bot 2024-09-26 14:13:42 +00:00 committed by Gerrit Code Review
commit fa55b755bb
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. * @return {Object} Parameters added. -1 for failure.
*/ */
Model.prototype.importSourceCodeParameters = function () { Model.prototype.importSourceCodeParameters = function () {
const model = this, const allParamNames = this.getAllParamNames(),
allParamNames = this.getAllParamNames(),
existingArray = [], existingArray = [],
importedArray = [], importedArray = [],
skippedArray = []; skippedArray = [];
// Check existing params // Check existing params
allParamNames.forEach( ( paramKey ) => { allParamNames.forEach( ( paramKey ) => {
if ( model.sourceCodeParameters.indexOf( paramKey ) !== -1 ) { if ( this.sourceCodeParameters.indexOf( paramKey ) !== -1 ) {
existingArray.push( paramKey ); existingArray.push( paramKey );
} }
} ); } );
@ -328,7 +327,7 @@ Model.prototype.importSourceCodeParameters = function () {
// Add sourceCodeParameters to the model // Add sourceCodeParameters to the model
this.sourceCodeParameters.forEach( ( sourceCodeParameter ) => { this.sourceCodeParameters.forEach( ( sourceCodeParameter ) => {
if ( existingArray.indexOf( sourceCodeParameter ) === -1 ) { if ( existingArray.indexOf( sourceCodeParameter ) === -1 ) {
model.addParam( sourceCodeParameter ); this.addParam( sourceCodeParameter );
importedArray.push( sourceCodeParameter ); importedArray.push( sourceCodeParameter );
} else { } else {
skippedArray.push( sourceCodeParameter ); skippedArray.push( sourceCodeParameter );

View file

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

View file

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

View file

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