From 4a692e762d62ebb31dcc4528e2e66c2dfdc80237 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sun, 19 May 2019 14:54:32 +0200 Subject: [PATCH] Special-case redlink URLs to load preferred editor In general action=edit could be bound to a wikitext-specific edit link, but in the case of redlinks we can use the preferred editor instead. Bug: T223793 Change-Id: Ib0851e9e2ce441ae93311153801e2c3de0a2063d --- includes/VisualEditorHooks.php | 10 +++++++--- .../ve.init.mw.DesktopArticleTarget.init.js | 16 +++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/includes/VisualEditorHooks.php b/includes/VisualEditorHooks.php index f77613e804..40a1af035d 100644 --- a/includes/VisualEditorHooks.php +++ b/includes/VisualEditorHooks.php @@ -315,8 +315,10 @@ class VisualEditorHooks { private static function getPreferredEditor( User $user, WebRequest $req ) { $config = MediaWikiServices::getInstance()->getConfigFactory() ->makeConfig( 'visualeditor' ); - // On dual-edit-tab wikis, the edit page must mean the user wants wikitext - if ( !$config->get( 'VisualEditorUseSingleEditTab' ) ) { + $isRedLink = $req->getBool( 'redlink' ); + // On dual-edit-tab wikis, the edit page must mean the user wants wikitext, + // unless following a redlink + if ( !$config->get( 'VisualEditorUseSingleEditTab' ) && !$isRedLink ) { return 'wikitext'; } switch ( $user->getOption( 'visualeditor-tabs' ) ) { @@ -330,7 +332,9 @@ class VisualEditorHooks { // May have got here by switching from VE // TODO: Make such an action explicitly request wikitext // so we can use getLastEditor here instead. - return 'wikitext'; + return $isRedLink ? + self::getLastEditor( $user, $req ) : + 'wikitext'; } return null; } 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 c77f9c1eeb..8ffd509eb0 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 @@ -452,22 +452,28 @@ } function getPreferredEditor() { - // On dual-edit-tab wikis, the edit page must mean the user wants wikitext - if ( !mw.config.get( 'wgVisualEditorConfig' ).singleEditTab ) { + // This logic matches VisualEditorHooks::getPreferredEditor + // !!+ casts '0' to false + var isRedLink = !!+uri.query.redlink; + // On dual-edit-tab wikis, the edit page must mean the user wants wikitext, + // unless following a redlink + if ( !mw.config.get( 'wgVisualEditorConfig' ).singleEditTab && !isRedLink ) { return 'wikitext'; } switch ( tabPreference ) { - case 'remember-last': - return getLastEditor(); case 'prefer-ve': return 'visualeditor'; case 'prefer-wt': return 'wikitext'; + case 'remember-last': + return getLastEditor(); case 'multi-tab': // 'multi-tab' // TODO: See VisualEditor.hooks.php - return 'wikitext'; + return isRedLink ? + getLastEditor() : + 'wikitext'; } return null; }