From 96aa5c91453cd577fc25009ee48735fe3f09ecdd Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Fri, 17 Apr 2015 14:01:11 -0700 Subject: [PATCH] Re-add A/B testing framework for new accounts Change-Id: I987bdee636a4659783bd492ac149e1d1c55f4df3 --- VisualEditor.hooks.php | 18 ++++++++++++++++++ VisualEditor.php | 6 ++++++ extension.json | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 13f59dcc58..cb79fbe98a 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -652,4 +652,22 @@ class VisualEditorHooks { } return true; } + + /** + * Sets user preference to enable the VisualEditor account if their new + * account's userID is even, if $wgVisualEditorEnableSplitTest is true. + * + * To be removed once no longer needed. + */ + public static function onAddNewAccount( $user, $byEmail ) { + if ( + RequestContext::getMain()->getConfig()->get( 'VisualEditorEnableSplitTest' ) && + $user->isLoggedin() && + ( ( $user->getId() % 2 ) === 0 ) + ) { + $user->setOption( 'visualeditor-enable', 1 ); + $user->saveSettings(); + } + return true; + } } diff --git a/VisualEditor.php b/VisualEditor.php index a87745c346..6cea257abf 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -87,6 +87,9 @@ $wgHooks['PageContentSaveComplete'][] = 'VisualEditorHooks::onPageContentSaveCom $wgHooks['BeforeInitialize'][] = 'VisualEditorHooks::onBeforeInitialize'; $wgExtensionFunctions[] = 'VisualEditorHooks::onSetup'; +// Run split test in production if $wgVisualEditorEnableSplitTest is true. +$wgHooks['AddNewAccount'][] = 'VisualEditorHooks::onAddNewAccount'; + // Register resource modules $wgVisualEditorResourceTemplate = array( @@ -1712,4 +1715,7 @@ $wgVisualEditorTabMessages = array( 'editsectionsourceappendix' => null, ); +// Whether to enable VisualEditor for half of all new accounts (userID even). +$wgVisualEditorEnableSplitTest = false; + unset( $wgVisualEditorResourceTemplate ); diff --git a/extension.json b/extension.json index 9e480eee4d..dfcfee1b93 100644 --- a/extension.json +++ b/extension.json @@ -93,6 +93,7 @@ }, "VisualEditorTabPosition": "before", "VisualEditorParsoidURL": "http://localhost:8000", + "VisualEditorEnableSplitTest": false, "VisualEditorEnableTocWidget": false, "VisualEditorNamespaces": [], "VisualEditorParsoidTimeout": 100 @@ -165,6 +166,9 @@ ], "BeforeInitialize": [ "VisualEditorHooks::onBeforeInitialize" + ], + "AddNewAccount": [ + "VisualEditorHooks::onAddNewAccount" ] }, "ResourceModules": {