Try to actually resolve visualeditor-editor preference setting when switching editors

Seems we need to make sure this returns before navigating to the target page.
This reverts commit 40807a0743.

Bug: T121122
Change-Id: I4edf03bc0d57b03897d9f1802eabd8f0dd9962b9
This commit is contained in:
Alex Monk 2015-12-15 01:38:05 +00:00
parent b08c8bd682
commit 76a12f2f9b
3 changed files with 18 additions and 11 deletions

View file

@ -75,7 +75,7 @@ class VisualEditorHooks {
$user->getOption( 'visualeditor-autodisable' ) ||
$user->getOption( 'visualeditor-tabs' ) === 'prefer-wt' ||
( $veConfig->get( 'VisualEditorDisableForAnons' ) && $user->isAnon() ) ||
false // TODO: Detect incompatibility - P2373
false // TODO: Detect incompatibility - T121298, P2373
) {
return true;
}
@ -102,13 +102,13 @@ class VisualEditorHooks {
$title->getContentModel() !== CONTENT_MODEL_WIKITEXT ||
// check for parameters that VE does not handle
// TODO: other params too? See identical list in ve.init.mw.DesktopArticleTarget.init.js
in_array( 'veswitched', $params ) ||
in_array( 'undo', $params ) ||
in_array( 'undoafter', $params ) ||
in_array( 'editintro', $params ) ||
in_array( 'preload', $params ) ||
in_array( 'preloadtitle', $params ) ||
in_array( 'preloadparams', $params );
// Known-good parameters: edit, veaction, section, vesection, veswitched
}
/**

View file

@ -235,8 +235,13 @@
}
$.cookie( 'VEE', editor, { path: '/', expires: 30 } );
new mw.Api().saveOption( 'visualeditor-editor', editor );
mw.user.options.set( 'visualeditor-editor', editor );
if ( mw.user.isAnon() ) {
return $.Deferred().resolve();
} else {
return new mw.Api().saveOption( 'visualeditor-editor', editor ).then( function () {
mw.user.options.set( 'visualeditor-editor', editor );
} );
}
}
function getLastEditor() {
@ -714,13 +719,13 @@
)
)
) &&
uri.query.veswitched === undefined &&
uri.query.undo === undefined &&
uri.query.undoafter === undefined &&
uri.query.editintro === undefined &&
uri.query.preload === undefined &&
uri.query.preloadtitle === undefined &&
uri.query.preloadparams === undefined
// Known-good parameters: edit, veaction, section, vesection, veswitched
// TODO: other params too? See identical list in VisualEditor.hooks.php
) {
trackActivateStart( {

View file

@ -1371,8 +1371,8 @@ ve.init.mw.DesktopArticleTarget.prototype.onUnload = function () {
* @param {boolean} [modified] Whether there were any changes at all.
*/
ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function ( discardChanges, modified ) {
var target = this;
mw.libs.ve.setEditorPreference( 'wikitext' );
var target = this,
prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
if ( discardChanges ) {
if ( modified ) {
@ -1381,10 +1381,12 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function ( di
ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate' } );
}
this.submitting = true;
location.href = this.viewUri.clone().extend( {
action: 'edit',
veswitched: 1
} ).toString();
prefPromise.done( function () {
location.href = target.viewUri.clone().extend( {
action: 'edit',
veswitched: 1
} ).toString();
} );
} else {
this.serialize(
this.docToSave || this.getSurface().getDom(),