From a76d3daf54a7eebb549f5729a1abd5cdee348e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 9 May 2019 22:37:28 +0200 Subject: [PATCH] DesktopArticleTarget.init: Allow veaction=edit to override namespace settings Prior to 80bfbfc54b67d59f510a3e2e8705b06944ee5afe this worked by accident, and with a number of bugs depending on your settings (see T219457). It turns out that Wikipedia users have invented various workflows that depended on this bug (mostly involving sandbox pages in namespaces where VE is not enabled). Restore it as a supported feature, and in a way that avoids the problems it previously caused. Bug: T221892 Change-Id: I62714b6f2905efd1d1b34c7a13b9917cb6c609fc --- includes/VisualEditorHooks.php | 18 ++++++++++++------ .../ve.init.mw.DesktopArticleTarget.init.js | 8 ++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/includes/VisualEditorHooks.php b/includes/VisualEditorHooks.php index bd61579ba8..4c2ce17dd1 100644 --- a/includes/VisualEditorHooks.php +++ b/includes/VisualEditorHooks.php @@ -213,22 +213,28 @@ class VisualEditorHooks { } if ( $req->getVal( 'wteswitched' ) ) { - return self::isVisualAvailable( $title ); + return self::isVisualAvailable( $title, $req ); } switch ( self::getPreferredEditor( $user, $req ) ) { case 'visualeditor': - return self::isVisualAvailable( $title ) || self::isWikitextAvailable( $title, $user ); + return self::isVisualAvailable( $title, $req ) || self::isWikitextAvailable( $title, $user ); case 'wikitext': return self::isWikitextAvailable( $title, $user ); } return false; } - private static function isVisualAvailable( $title ) { + private static function isVisualAvailable( $title, $req ) { $veConfig = MediaWikiServices::getInstance()->getConfigFactory() ->makeConfig( 'visualeditor' ); - return ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) && + return ( + // Only in enabled namespaces + ApiVisualEditor::isAllowedNamespace( $veConfig, $title->getNamespace() ) || + // Or if forced by the URL parameter (T221892) + $req->getVal( 'veaction' ) === 'edit' + ) && + // Only for pages with a supported content model ApiVisualEditor::isAllowedContentType( $veConfig, $title->getContentModel() ); } @@ -415,7 +421,7 @@ class VisualEditorHooks { $title = $skin->getRelevantTitle(); // Don't exit if this page isn't VE-enabled, since we should still // change "Edit" to "Edit source". - $isAvailable = self::isVisualAvailable( $title ); + $isAvailable = self::isVisualAvailable( $title, $skin->getRequest() ); $tabMessages = $config->get( 'VisualEditorTabMessages' ); // Rebuild the $links['views'] array and inject the VisualEditor tab before or after @@ -608,7 +614,7 @@ class VisualEditorHooks { } // add VE edit section in VE available namespaces - if ( self::isVisualAvailable( $title ) ) { + if ( self::isVisualAvailable( $title, $skin->getRequest() ) ) { $veEditSection = $tabMessages['editsection']; $veLink = [ 'text' => $skin->msg( $veEditSection )->inLanguage( $lang )->text(), 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 f5a378050c..a7f86eccf6 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 @@ -998,8 +998,12 @@ init.isVisualAvailable = ( init.isAvailable && - // Only in enabled namespaces - conf.namespaces.indexOf( new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 && + ( + // Only in enabled namespaces + conf.namespaces.indexOf( new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 || + // Or if forced by the URL parameter (T221892) + uri.query.veaction === 'edit' + ) && // Only for pages with a supported content model Object.prototype.hasOwnProperty.call( conf.contentModels, mw.config.get( 'wgPageContentModel' ) )