Try to make client and server code to get last editor work the same

On the client: getLastEditor in ve.init.mw.DesktopArticleTarget.init.js
On the server: VisualEditorHooks::getUserEditor in VisualEditorHooks.php

Change-Id: I9cc0f367aee2dda43cffc6918bfb042ac8ae3bb2
This commit is contained in:
Alex Monk 2016-04-11 23:56:33 +01:00
parent 5508609124
commit 9170bd8acd
2 changed files with 15 additions and 8 deletions

View file

@ -180,15 +180,21 @@ class VisualEditorHooks {
}
private static function getUserEditor( User $user, WebRequest $req ) {
if ( $user->isAnon() ) {
return $req->getCookie(
'VEE',
'',
User::getDefaultOption( 'visualeditor-editor' )
);
} else {
return $user->getOption( 'visualeditor-editor' );
// This logic matches getLastEditor in:
// modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
$editor = $req->getCookie( 'VEE', '' );
// Set editor to user's preference or site's default if 
if (
// … user is logged in,
!$user->isAnon() ||
// … no cookie is set, or
!$editor ||
// value is invalid.
!( $editor === 'visualeditor' || $editor === 'wikitext' )
) {
$editor = $user->getOption( 'visualeditor-editor' );
}
return $editor;
}
/**

View file

@ -268,6 +268,7 @@
}
function getLastEditor() {
// This logic matches VisualEditorHooks::getUserEditor
var editor = $.cookie( 'VEE' );
// Set editor to user's preference or site's default if 
if (