Conditionally enable Popups

Changes:
* Disable the desktop target by default
* If the user is in the experiment condition, then enable the desktop
  target
* Add PopupsExperiment config var, which, if set to true, causes: the
  experiment config to be added to the output as config vars, as well as
  the ext.popups.desktop Resource Loader module

Bug: T132604
Change-Id: Ia71ca924c3e2ec2ee0b0191ea2573fa7ff5e8a7e
This commit is contained in:
Sam Smith 2016-05-16 10:03:52 +01:00 committed by Jdlrobson
parent c4667fd133
commit 41dc6d396a
3 changed files with 47 additions and 4 deletions

View file

@ -177,7 +177,15 @@ class PopupsHooks {
return true;
}
if ( self::getConfig()->get( 'PopupsBetaFeature' ) === true ) {
$config = self::getConfig();
$isExperimentEnabled = $config->get( 'PopupsExperiment' );
if (
// If Popups are enabled as an experiment, then bypass checking whether the user has enabled
// it as a beta feature.
!$isExperimentEnabled &&
$config->get( 'PopupsBetaFeature' ) === true
) {
if ( !class_exists( 'BetaFeatures' ) ) {
$logger = LoggerFactory::getInstance( 'popups' );
$logger->error( 'PopupsMode cannot be used as a beta feature unless ' .
@ -241,5 +249,28 @@ class PopupsHooks {
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'popups' );
$vars['wgPopupsSurveyLink'] = $conf->get( 'PopupsSurveyLink' );
$vars['wgPopupsSchemaPopupsSamplingRate'] = $conf->get( 'SchemaPopupsSamplingRate' );
if ( $conf->get( 'PopupsExperiment' ) ) {
$vars['wgPopupsExperiment'] = true;
$vars['wgPopupsExperimentConfig'] = $conf->get( 'PopupsExperimentConfig' );
}
}
/**
* MakeGlobalVariablesScript hook handler.
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
*
* @param array $vars
* @param OutputPage $out
*/
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'popups' );
$user = $out->getUser();
if ( $config->get( 'PopupsExperiment' ) ) {
$vars['wgPopupsExperimentIsBetaFeatureEnabled'] =
class_exists( 'BetaFeatures' ) && BetaFeatures::isFeatureEnabled( $user, 'popups' );
}
}
}

View file

@ -32,6 +32,9 @@
],
"BeforePageDisplayMobile": [
"PopupsHooks::onBeforePageDisplayMobile"
],
"MakeGlobalVariablesScript": [
"PopupsHooks::onMakeGlobalVariablesScript"
]
},
"MessagesDirs": {
@ -49,7 +52,8 @@
"PopupsSurveyLink": false,
"EnablePopupsMobile": false,
"@SchemaPopupsSamplingRate": "@var number: Sample rate for logging events to Schema:Popups.",
"SchemaPopupsSamplingRate": 0.1
"SchemaPopupsSamplingRate": 0.1,
"PopupsExperiment": false
},
"DefaultUserOptions": {
"popupsmobile": "1"
@ -81,7 +85,8 @@
"jquery.jStorage",
"jquery.client",
"ext.popups.core",
"ext.popups.renderer.desktopRenderer"
"ext.popups.renderer.desktopRenderer",
"ext.popups.experiment"
],
"targets": [ "desktop" ]
},

View file

@ -1,5 +1,12 @@
( function ( $, mw ) {
mw.popups.enabled = $.jStorage.get( 'mwe-popups-enabled' ) !== 'false';
// If the experiment isn't running, then continue to enable Popups by default during
// initialisation.
if ( !mw.config.get( 'wgPopupsExperiment', false ) ) {
mw.popups.enabled = $.jStorage.get( 'mwe-popups-enabled' ) !== 'false';
} else {
mw.popups.enabled = mw.popups.experiment.isUserInCondition();
}
/**
* Returns valid jQuery selectors for which a popup should be triggered.