targets: Fix silly indirection via a global variable

Since we're inside the Target instance, `ve.init.target` refers to
this object. Some of the code I'm changing even uses `this` instead
of `ve.init.target` on the next or previous line.

Most of the mistakes are a result of mass search-and-replace changes
(478b0bcb, e1a887cc), or moving the code from other classes (d294006d).
But I can't explain the "ve.init.target.getSurface().getDom()" line,
it would be good to figure out why it was this way before we change it.

Change-Id: I0d7c6a48369242d4c99620fcd775ab537420d84a
This commit is contained in:
Bartosz Dziewoński 2019-07-22 21:41:36 +02:00
parent 2b6857d89a
commit cc1cb63aca
2 changed files with 9 additions and 9 deletions

View file

@ -345,7 +345,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadSuccess = function () {
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } ); $.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
} }
} else { } else {
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' ); this.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' );
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' ); mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
} }
this.suppressNormalStartupDialogs = true; this.suppressNormalStartupDialogs = true;
@ -461,7 +461,7 @@ ve.init.mw.DesktopArticleTarget.prototype.afterActivate = function () {
} }
// Transfer and initial source range to the surface (e.g. from tempWikitextEditor) // Transfer and initial source range to the surface (e.g. from tempWikitextEditor)
if ( this.initialSourceRange && this.getSurface().getMode() === 'source' ) { if ( this.initialSourceRange && this.getSurface().getMode() === 'source' ) {
surfaceModel = ve.init.target.getSurface().getModel(); surfaceModel = this.getSurface().getModel();
range = surfaceModel.getRangeFromSourceOffsets( this.initialSourceRange.from, this.initialSourceRange.to ); range = surfaceModel.getRangeFromSourceOffsets( this.initialSourceRange.from, this.initialSourceRange.to );
surfaceModel.setLinearSelection( range ); surfaceModel.setLinearSelection( range );
} }
@ -720,7 +720,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetai
OO.ui.confirm( confirmPromptMessage ).done( function ( confirmed ) { OO.ui.confirm( confirmPromptMessage ).done( function ( confirmed ) {
if ( confirmed ) { if ( confirmed ) {
target.load(); target.load();
} else if ( $( '#wpTextbox1' ).length && !ve.init.target.isModeAvailable( 'source' ) ) { } else if ( $( '#wpTextbox1' ).length && !target.isModeAvailable( 'source' ) ) {
// If we're switching from the wikitext editor, just deactivate // If we're switching from the wikitext editor, just deactivate
// don't try to switch back to it fully, that'd discard changes. // don't try to switch back to it fully, that'd discard changes.
target.tryTeardown( true ); target.tryTeardown( true );
@ -1344,7 +1344,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
this.currentUri = new mw.Uri( location.href ); this.currentUri = new mw.Uri( location.href );
veaction = this.currentUri.query.veaction; veaction = this.currentUri.query.veaction;
if ( ve.init.target.isModeAvailable( 'source' ) && this.active ) { if ( this.isModeAvailable( 'source' ) && this.active ) {
if ( veaction === 'editsource' && this.getDefaultMode() === 'visual' ) { if ( veaction === 'editsource' && this.getDefaultMode() === 'visual' ) {
this.actFromPopState = true; this.actFromPopState = true;
this.switchToWikitextEditor(); this.switchToWikitextEditor();
@ -1526,7 +1526,7 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToVisualEditor = function () {
// Parent method // Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.switchToVisualEditor.apply( this, arguments ); ve.init.mw.DesktopArticleTarget.super.prototype.switchToVisualEditor.apply( this, arguments );
if ( ve.init.target.isModeAvailable( 'visual' ) ) { if ( this.isModeAvailable( 'visual' ) ) {
ve.track( 'activity.editor-switch', { action: 'visual-desktop' } ); ve.track( 'activity.editor-switch', { action: 'visual-desktop' } );
} }
}; };
@ -1538,7 +1538,7 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function () {
// Parent method // Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextEditor.apply( this, arguments ); ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextEditor.apply( this, arguments );
if ( ve.init.target.isModeAvailable( 'source' ) ) { if ( this.isModeAvailable( 'source' ) ) {
ve.track( 'activity.editor-switch', { action: 'source-nwe-desktop' } ); ve.track( 'activity.editor-switch', { action: 'source-nwe-desktop' } );
} }
}; };

View file

@ -1076,7 +1076,7 @@ ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () {
action: 'visualeditor', action: 'visualeditor',
paction: 'parsedoc', paction: 'parsedoc',
page: target.getPageName(), page: target.getPageName(),
wikitext: ve.init.target.getSurface().getDom(), wikitext: target.getSurface().getDom(),
pst: true pst: true
} ).then( function ( response ) { } ).then( function ( response ) {
// Use anonymous function to avoid passing through API promise argument // Use anonymous function to avoid passing through API promise argument
@ -2266,7 +2266,7 @@ ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () {
} }
if ( prefSaysShow ) { if ( prefSaysShow ) {
ve.init.target.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' ); this.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' );
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' ); mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
// No need to set a cookie every time for logged-in users that have already // No need to set a cookie every time for logged-in users that have already
@ -2297,7 +2297,7 @@ ve.init.mw.ArticleTarget.prototype.switchToWikitextEditor = function ( modified
this.section = null; this.section = null;
} }
if ( ve.init.target.isModeAvailable( 'source' ) ) { if ( this.isModeAvailable( 'source' ) ) {
if ( !modified ) { if ( !modified ) {
dataPromise = mw.libs.ve.targetLoader.requestPageData( 'source', this.getPageName(), { dataPromise = mw.libs.ve.targetLoader.requestPageData( 'source', this.getPageName(), {
sessionStore: true, sessionStore: true,