Act as a beta feature if so configured

Add a configuration key, 'PopupsBetaFeature'. If true, Popups will act as a
beta-feature, and will depend on the BetaFeatures extension. Set to false by
default.

Bug: T88917
Bug: T88164
Change-Id: Ie4cc455fa6379dbc8ef700e4773bedfb49fcf813
This commit is contained in:
Andrew Garrett 2015-03-16 14:02:38 +01:00 committed by Ori Livneh
parent 01e512b9ad
commit c7e057946d
2 changed files with 43 additions and 6 deletions

View file

@ -18,11 +18,16 @@
* @file
* @ingroup extensions
*/
use MediaWiki\Logger\LoggerFactory;
class PopupsHooks {
static function getPreferences( User $user, array &$prefs ){
global $wgExtensionAssetsPath;
if ( self::getConfig()->get( 'PopupsBetaFeature' ) !== true ) {
return;
}
$prefs['popups'] = array(
'label-message' => 'popups-message',
'desc-message' => 'popups-desc',
@ -38,6 +43,17 @@ class PopupsHooks {
);
}
/**
* @return Config
*/
public static function getConfig() {
static $config;
if ( !$config ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'popups' );
}
return $config;
}
/**
* @param array $schemas
*/
@ -108,13 +124,28 @@ class PopupsHooks {
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin) {
// Enable only if the user has turned it on in Beta Preferences, or BetaFeatures is not installed.
// Will only be loaded if PageImages & TextExtracts extensions are installed.
if ( ( !class_exists( 'BetaFeatures' ) || BetaFeatures::isFeatureEnabled( $skin->getUser(), 'popups' ) )
&& defined( 'TEXT_EXTRACTS_INSTALLED' )
&& class_exists( 'ApiQueryPageImages' )
) {
$out->addModules( array( 'ext.popups' ) );
$out->addModules( array( 'schema.Popups' ) );
if ( !defined( 'TEXT_EXTRACTS_INSTALLED' ) || !class_exists( 'ApiQueryPageImages' ) ) {
$logger = LoggerFactory::getInstance( 'popups' );
$logger->error( 'Popups requires the PageImages and TextExtracts extensions.' );
return true;
}
if ( self::getConfig()->get( 'PopupsBetaFeature' ) === true ) {
if ( !class_exists( 'BetaFeatures' ) ) {
$logger = LoggerFactory::getInstance( 'popups' );
$logger->error( 'PopupsMode cannot be used as a beta feature unless ' .
'the BetaFeatures extension is present.' );
return true;
}
if ( !BetaFeatures::isFeatureEnabled( $skin->getUser(), 'popups' ) ) {
return true;
}
}
$out->addModules( array( 'ext.popups', 'schema.Popups' ) );
return true;
}
/**

View file

@ -33,6 +33,12 @@ $wgExtensionCredits['betafeatures'][] = array(
'license-name' => 'GPL-2.0+',
);
/**
* @var bool: Whether the extension should be enabled as an opt-in beta feature.
* If true, the BetaFeatures extension must be installed. False by default.
*/
$wgPopupsBetaFeature = false;
$wgPopupsSurveyLink = false;
$wgConfigRegistry['popups'] = 'GlobalVarConfig::newInstance';