From c2e792e3341c7c041047995384824c0a9a4142f3 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Thu, 17 Dec 2015 18:18:32 +0000 Subject: [PATCH] SET: Set user's editor to wikitext if the browser doesn't do JS Bug: T121257 Change-Id: I8c734934a76ac73ff943db1712e679a7e73aa1e1 --- VisualEditor.hooks.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 7885946717..cbdbb0cbb5 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -109,7 +109,7 @@ class VisualEditorHooks { * @return bool Whether to show the wikitext editor or not. */ public static function onCustomEditor( Article $article, User $user ) { - $req = RequestContext::getMain()->getRequest(); + $req = $article->getContext()->getRequest(); $veConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'visualeditor' ); if ( @@ -128,23 +128,40 @@ class VisualEditorHooks { $availableNamespaces = $veConfig->get( 'VisualEditorAvailableNamespaces' ); - $params = $req->getValueNames(); + $params = $req->getValues(); - return $req->getVal( 'action' ) !== 'edit' || + if ( isset( $params['venoscript'] ) ) { + $req->response()->setCookie( 'VEE', 'wikitext', 0, array( 'prefix' => '' ) ); + $user->setOption( 'visualeditor-editor', 'wikitext' ); + $user->saveSettings(); + return true; + } + + $ret = $req->getVal( 'action' ) !== 'edit' || !$veConfig->get( 'VisualEditorUseSingleEditTab' ) || self::getUserEditor( $user, $req ) === 'wikitext' || !$title->userCan( 'edit' ) || !$title->inNamespaces( array_keys( array_filter( $availableNamespaces ) ) ) || $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( 'undo', $params ) || - in_array( 'undoafter', $params ) || - in_array( 'editintro', $params ) || - in_array( 'preload', $params ) || - in_array( 'preloadtitle', $params ) || - in_array( 'preloadparams', $params ); + // Known parameters that VE does not handle + // TODO: Other params too? See identical list in ve.init.mw.DesktopArticleTarget.init.js + isset( $params['undo'] ) || + isset( $params['undoafter'] ) || + isset( $params['editintro'] ) || + isset( $params['preload'] ) || + isset( $params['preloadtitle'] ) || + isset( $params['preloadparams'] ); // Known-good parameters: edit, veaction, section, vesection, veswitched + + if ( !$ret ) { + $params['venoscript'] = '1'; + $url = htmlspecialchars( wfScript() . '?' . wfArrayToCgi( $params ) ); + $article->getContext()->getOutput()->addHeadItem( + 've-noscript-fallback', + "" + ); + } + return $ret; } private static function getUserEditor( User $user, WebRequest $req ) {