From 7ad624f0a34243c602d4fc45ee2b13b7c8577691 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 18 Apr 2019 19:38:15 +0100 Subject: [PATCH] Remove switch confirm dialogs Bug: T220007 Change-Id: I81b39a02d573d96bcb6b4238aabbcd077e874906 --- extension.json | 5 -- i18n/ve-mw/en.json | 3 - i18n/ve-mw/qqq.json | 7 +- .../ve.init.mw.DesktopArticleTarget.init.js | 26 +++--- .../ve.init.mw.DesktopArticleTarget.js | 2 - .../init/ve.init.MWVESwitchConfirmDialog.js | 42 +--------- .../ve-mw/init/ve.init.mw.ArticleTarget.js | 7 +- .../ve.ui.MWWikitextSwitchConfirmDialog.js | 83 ------------------- 8 files changed, 18 insertions(+), 157 deletions(-) delete mode 100644 modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js diff --git a/extension.json b/extension.json index a512645921..13fa937657 100644 --- a/extension.json +++ b/extension.json @@ -1429,7 +1429,6 @@ "visualeditor-mweditmodesource-tool-current", "visualeditor-mweditmodesource-tool-unavailable", "visualeditor-mweditmodesource-warning-cancel", - "visualeditor-mweditmodesource-warning-switch", "visualeditor-mweditmodesource-warning-switch-discard", "visualeditor-mweditmodeve-popup-body", "visualeditor-mweditmodeve-popup-title", @@ -1482,7 +1481,6 @@ "modules/ve-mw/ui/dialogs/ve.ui.MWExtensionDialog.js", "modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js", "modules/ve-mw/ui/dialogs/ve.ui.MWCommandHelpDialog.js", - "modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js", "modules/ve-mw/ui/widgets/ve.ui.MWPreTextInputWidget.js", "modules/ve-mw/ui/dialogs/ve.ui.MWPreDialog.js", "modules/ve-mw/ui/dialogs/ve.ui.MWTableDialog.js", @@ -1575,10 +1573,7 @@ "visualeditor-help-link", "visualeditor-help-title", "visualeditor-mweditmodesource-progress", - "visualeditor-mweditmodesource-title", - "visualeditor-mweditmodesource-warning", "visualeditor-mweditmodesource-warning-cancel", - "visualeditor-mweditmodesource-warning-switch", "visualeditor-mweditmodesource-warning-switch-discard", "visualeditor-mweditmodeve-progress", "visualeditor-pagemenu-tooltip", diff --git a/i18n/ve-mw/en.json b/i18n/ve-mw/en.json index e5589b4bbf..e9ddd7baf1 100644 --- a/i18n/ve-mw/en.json +++ b/i18n/ve-mw/en.json @@ -250,12 +250,9 @@ "visualeditor-meta-tool": "Options", "visualeditor-mweditmode-tooltip": "Switch editor", "visualeditor-mweditmodesource-progress": "Switching to source editing…", - "visualeditor-mweditmodesource-title": "Switch to source editing?", "visualeditor-mweditmodesource-tool-current": "Source editing", "visualeditor-mweditmodesource-tool-unavailable": "Source editing is not available here", - "visualeditor-mweditmodesource-warning": "You are switching to source editing.\nDo you want to continue?", "visualeditor-mweditmodesource-warning-cancel": "Cancel", - "visualeditor-mweditmodesource-warning-switch": "Switch", "visualeditor-mweditmodesource-warning-switch-discard": "Discard my changes and switch", "visualeditor-mweditmodeve-popup-body": "You can switch back to visual editing at any time by clicking on this icon.", "visualeditor-mweditmodeve-popup-title": "You have switched to source editing", diff --git a/i18n/ve-mw/qqq.json b/i18n/ve-mw/qqq.json index a249e32b89..095026ad0f 100644 --- a/i18n/ve-mw/qqq.json +++ b/i18n/ve-mw/qqq.json @@ -266,12 +266,9 @@ "visualeditor-meta-tool": "Text of tool in the toolbar the lets users set categories, language links and other page settings.\n{{Identical|Options}}", "visualeditor-mweditmode-tooltip": "Tooltip text for editor switching menu.", "visualeditor-mweditmodesource-progress": "Title of progress bar shown while switching to source mode.", - "visualeditor-mweditmodesource-title": "Title of dialog to confirm switching to source mode.", "visualeditor-mweditmodesource-tool-current": "Label for tool that changes edit mode to source editing (or describes the mode if the user is already in that mode).", "visualeditor-mweditmodesource-tool-unavailable": "'''Please translate \"Source\" as meaning \"Source codes\", not source of references.''' Label for tool that changes edit mode to source editing when it is not available.", - "visualeditor-mweditmodesource-warning": "Warning message show before changing edit mode to source editing. It may allow the user to keep the changes using the message {{msg-mw|Visualeditor-mweditmodesource-warning-switch}} or cancel.", "visualeditor-mweditmodesource-warning-cancel": "Label for the button on the confirmation dialog for switching to source editing to cancel and return to editing.\n{{Identical|Cancel}}", - "visualeditor-mweditmodesource-warning-switch": "Label for the button on the confirmation dialog for switching to source editing to continue and switch editors.\n{{Identical|Switch}}", "visualeditor-mweditmodesource-warning-switch-discard": "Label for the button on the confirmation dialog for switching to visual editing to continue and switch editors when doing so will throw away your changes.", "visualeditor-mweditmodeve-popup-body": "Body text of popup shown after switching to source mode from visual mode", "visualeditor-mweditmodeve-popup-title": "Title of popup shown after switching to source mode from visual mode", @@ -350,7 +347,7 @@ "visualeditor-mwpredialog-convert": "Label for a button which will convert the preformatted text block into a form which can have text styles applied (e.g. bold, italic, links).", "visualeditor-mwpredialog-title": "Title for the preformatted text dialog. It appears when clicking on a
 element.",
 	"visualeditor-mwsignature-tool": "Used as name of the tool for inserting signatures.",
-	"visualeditor-pagemenu-tooltip": "Tooltip text for the page menu which has the following items:\n* {{msg-mw|visualeditor-meta-tool}}\n* {{msg-mw|visualeditor-settings-tool}}\n* {{msg-mw|visualeditor-advancedsettings-tool}}\n* {{msg-mw|visualeditor-categories-tool}}\n* {{msg-mw|visualeditor-languages-tool}}\n* {{msg-mw|visualeditor-mweditmodesource-title}}\n* {{msg-mw|visualeditor-dialog-command-help-title}}",
+	"visualeditor-pagemenu-tooltip": "Tooltip text for the page menu which has the following items:\n* {{msg-mw|visualeditor-meta-tool}}\n* {{msg-mw|visualeditor-settings-tool}}\n* {{msg-mw|visualeditor-advancedsettings-tool}}\n* {{msg-mw|visualeditor-categories-tool}}\n* {{msg-mw|visualeditor-languages-tool}}\n* {{msg-mw|visualeditor-dialog-command-help-title}}",
 	"visualeditor-pagetranslationwarning": "Edit notice shown when VisualEditor loads, warning users editing a translated page that it is not officially supported.",
 	"visualeditor-parameter-input-placeholder": "Placeholder text label for an input for adding a parameter to a template.\n{{Identical|Field name}}",
 	"visualeditor-parameter-search-more": "Label for item in parameter list that, when clicked, reveals additional parameters that had been truncated to save space.\n\nParameters:\n* $1 - number of fields (parameters)",
@@ -423,7 +420,7 @@
 	"visualeditor-usernamespacepagelink": "Name of a page describing the user namespace (NS2) in this project.\n{{doc-important|Do not translate \"Project\"; it is automatically converted to the wiki's project namespace.}}",
 	"visualeditor-version-label": "Label text for version number\n{{Identical|Version}}",
 	"visualeditor-wikitext-progress": "Label for progress bar shown while converting pasted wikitext.",
-	"visualeditor-wikitext-warning": "Contents of notification displayed when Wikitext has been detected.\n\nRefers to:\n* {{msg-mw|Visualeditor-wikitext-warning-link}}\n* {{msg-mw|Visualeditor-toolbar-cancel}}\n* {{msg-mw|Visualeditor-mweditmodesource-title}}\nSee also:\n* {{msg-mw|Visualeditor-beta-warning}}",
+	"visualeditor-wikitext-warning": "Contents of notification displayed when Wikitext has been detected.\n\nRefers to:\n* {{msg-mw|Visualeditor-wikitext-warning-link}}\n* {{msg-mw|Visualeditor-toolbar-cancel}}\nSee also:\n* {{msg-mw|Visualeditor-beta-warning}}",
 	"visualeditor-wikitext-warning-link": "Link to page describing what Wikitext is.\n\nUsed in:\n* {{msg-mw|Visualeditor-wikitext-warning}}.\n\nTranslate to a title where most wikis in the language you're translating to have one such help page; if they don't have one, you can use [[mw:Special:MyLanguage/Help:Formatting]] as target.",
 	"visualeditor-wikitext-warning-title": "Title of notification displayed when Wikitext has been detected",
 	"visualeditor-wikitextconvert-title": "Title of prompt displayed when rich markup is pasted into a source mode editor.",
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 8ffd509eb0..610ab7b615 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -868,7 +868,14 @@
 		activateVe: function ( mode ) {
 			var wikitext = $( '#wpTextbox1' ).textSelection( 'getContents' ),
 				sectionVal = $( 'input[name=wpSection]' ).val(),
-				section = sectionVal !== '' && sectionVal !== undefined ? +sectionVal : null;
+				section = sectionVal !== '' && sectionVal !== undefined ? +sectionVal : null,
+				config = mw.config.get( 'wgVisualEditorConfig' ),
+				canSwitch = config.fullRestbaseUrl || config.allowLossySwitching,
+				modified = mw.config.get( 'wgAction' ) === 'submit' ||
+					(
+						mw.config.get( 'wgAction' ) === 'edit' &&
+						wikitext !== initialWikitext
+					);
 
 			// Close any open jQuery.UI dialogs (e.g. WikiEditor's find and replace)
 			if ( $.fn.dialog ) {
@@ -880,18 +887,10 @@
 				$( window ).off( 'beforeunload.editwarning' );
 			}
 
-			if (
-				mw.config.get( 'wgAction' ) === 'submit' ||
-				(
-					mw.config.get( 'wgAction' ) === 'edit' &&
-					wikitext !== initialWikitext
-				)
-			) {
+			if ( modified && !canSwitch ) {
 				mw.loader.using( 'ext.visualEditor.switching' ).done( function () {
 					var windowManager = new OO.ui.WindowManager(),
 						switchWindow = new mw.libs.ve.SwitchConfirmDialog();
-					// Prompt if either we're on action=submit (the user has previewed) or
-					// the wikitext hash is different to the value observed upon page load.
 
 					$( document.body ).append( windowManager.$element );
 					windowManager.addWindows( [ switchWindow ] );
@@ -899,10 +898,7 @@
 						.closed.then( function ( data ) {
 							var oldUri;
 							// TODO: windowManager.destroy()?
-							if ( data && data.action === 'keep' ) {
-								releaseOldEditWarning();
-								activatePageTarget( mode, section, true );
-							} else if ( data && data.action === 'discard' ) {
+							if ( data && data.action === 'discard' ) {
 								releaseOldEditWarning();
 								setEditorPreference( 'visualeditor' );
 								oldUri = veEditUri.clone();
@@ -913,7 +909,7 @@
 				} );
 			} else {
 				releaseOldEditWarning();
-				activatePageTarget( mode, section, false );
+				activatePageTarget( mode, section, modified );
 			}
 		},
 
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
index 4431550604..c75984759e 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -1033,8 +1033,6 @@ ve.init.mw.DesktopArticleTarget.prototype.serializeFail = function ( jqXHR, stat
 
 	OO.ui.alert( ve.msg( 'visualeditor-serializeerror', status ) );
 
-	this.getSurface().getDialogs().closeWindow( 'wikitextswitchconfirm' );
-
 	// It's possible to get here while the save dialog has never been opened (if the user uses
 	// the switch to source mode option)
 	if ( this.saveDialog ) {
diff --git a/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js b/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
index 3a9790b7fd..fde9f6b275 100644
--- a/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
+++ b/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
@@ -38,59 +38,25 @@ mw.libs.ve.SwitchConfirmDialog.static.actions = [
 	{
 		action: 'cancel',
 		label: mw.msg( 'visualeditor-mweditmodesource-warning-cancel' ),
-		flags: [ 'safe', 'back' ],
-		modes: [ 'restbase', 'simple' ]
+		flags: [ 'safe', 'back' ]
 	},
 	{
 		action: 'discard',
 		label: mw.msg( 'visualeditor-mweditmodesource-warning-switch-discard' ),
-		flags: 'destructive',
-		modes: [ 'simple' ]
-	},
-	{
-		action: 'keep',
-		label: mw.msg( 'visualeditor-mweditmodesource-warning-switch' ),
-		flags: [ 'progressive', 'primary' ],
-		modes: [ 'restbase' ]
+		flags: 'destructive'
 	}
 ];
 
 /* Methods */
 
-/**
- * @inheritdoc
- */
-mw.libs.ve.SwitchConfirmDialog.prototype.getSetupProcess = function ( data ) {
-	return mw.libs.ve.SwitchConfirmDialog.super.prototype.getSetupProcess.apply( this, arguments )
-		.next( function () {
-			var
-				config = mw.config.get( 'wgVisualEditorConfig' ),
-				canSwitch = config.fullRestbaseUrl || config.allowLossySwitching;
-			if ( data && data.mode ) {
-				this.actions.setMode( data.mode );
-			} else if ( canSwitch ) {
-				this.actions.setMode( 'restbase' );
-			} else {
-				this.actions.setMode( 'simple' );
-			}
-		}, this );
-};
-
 /**
  * @inheritdoc
  */
 mw.libs.ve.SwitchConfirmDialog.prototype.getActionProcess = function ( action ) {
-	if ( action === 'keep' ) {
+	if ( action === 'discard' ) {
 		return new OO.ui.Process( function () {
 			this.getActions()
-				.setAbilities( { cancel: false, discard: false } )
-				.get( { actions: 'keep' } )[ 0 ].pushPending();
-			this.close( { action: 'keep' } );
-		}, this );
-	} else if ( action === 'discard' ) {
-		return new OO.ui.Process( function () {
-			this.getActions()
-				.setAbilities( { cancel: false, keep: false } )
+				.setAbilities( { cancel: false } )
 				.get( { actions: 'discard' } )[ 0 ].pushPending();
 			this.close( { action: 'discard' } );
 		}, this );
diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
index b858b0a530..cd8957d11b 100644
--- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
+++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
@@ -1201,12 +1201,7 @@ ve.init.mw.ArticleTarget.prototype.clearState = function () {
 ve.init.mw.ArticleTarget.prototype.editSource = function () {
 	var modified = this.fromEditedState || this.getSurface().getModel().hasBeenModified();
 
-	if ( ve.init.target.isModeAvailable( 'source' ) || !modified ) {
-		this.switchToWikitextEditor( modified );
-	} else {
-		ve.ui.actionFactory.create( 'window', this.getSurface() )
-			.open( 'wikitextswitchconfirm', { target: this } );
-	}
+	this.switchToWikitextEditor( modified );
 };
 
 /**
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
deleted file mode 100644
index 9f05e2348e..0000000000
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/*!
- * VisualEditor user interface MWWikitextSwitchConfirmDialog class.
- *
- * @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
- * @license The MIT License (MIT); see LICENSE.txt
- */
-
-/**
- * Dialog for letting the user choose how to switch to wikitext mode.
- *
- * @class
- * @extends OO.ui.MessageDialog
- *
- * @constructor
- * @param {Object} [config] Configuration options
- */
-ve.ui.MWWikitextSwitchConfirmDialog = function VeUiMWWikitextSwitchConfirmDialog( config ) {
-	// Parent constructor
-	ve.ui.MWWikitextSwitchConfirmDialog.super.call( this, config );
-};
-
-/* Inheritance */
-
-OO.inheritClass( ve.ui.MWWikitextSwitchConfirmDialog, OO.ui.MessageDialog );
-
-/* Static Properties */
-
-ve.ui.MWWikitextSwitchConfirmDialog.static.name = 'wikitextswitchconfirm';
-
-ve.ui.MWWikitextSwitchConfirmDialog.static.title =
-	OO.ui.deferMsg( 'visualeditor-mweditmodesource-title' );
-
-ve.ui.MWWikitextSwitchConfirmDialog.static.message =
-	OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning' );
-
-ve.ui.MWWikitextSwitchConfirmDialog.static.actions = [
-	{
-		action: 'cancel',
-		label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-cancel' ),
-		flags: [ 'safe', 'back' ]
-	},
-	{
-		action: 'switch',
-		label: OO.ui.deferMsg( 'visualeditor-mweditmodesource-warning-switch' ),
-		flags: [ 'progressive', 'primary' ]
-	}
-];
-
-/* Methods */
-
-/**
- * @inheritdoc
- */
-ve.ui.MWWikitextSwitchConfirmDialog.prototype.getActionProcess = function ( action ) {
-	if ( action === 'switch' ) {
-		return new OO.ui.Process( function () {
-			this.getActions().setAbilities( { cancel: false } );
-			this.getActions().get()[ 1 ].pushPending();
-			this.target.switchToWikitextEditor( true );
-		}, this );
-	} else if ( action === 'cancel' ) {
-		return new OO.ui.Process( function () {
-			this.close( { action: action } );
-		}, this );
-	}
-
-	// Parent method
-	return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.getActionProcess.call( this, action );
-};
-
-/**
- * @inheritdoc
- **/
-ve.ui.MWWikitextSwitchConfirmDialog.prototype.setup = function ( data ) {
-	this.target = data.target;
-
-	// Parent method
-	return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.setup.call( this, data );
-};
-
-/* Registration */
-
-ve.ui.windowFactory.register( ve.ui.MWWikitextSwitchConfirmDialog );