2014-02-06 10:49:28 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension Popups.
|
|
|
|
*
|
|
|
|
* Popups is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Popups is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Popups. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup extensions
|
|
|
|
*/
|
2015-03-16 13:02:38 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2014-02-06 10:49:28 +00:00
|
|
|
|
|
|
|
class PopupsHooks {
|
2014-02-07 11:52:40 +00:00
|
|
|
static function getPreferences( User $user, array &$prefs ){
|
|
|
|
global $wgExtensionAssetsPath;
|
2015-03-16 13:02:38 +00:00
|
|
|
if ( self::getConfig()->get( 'PopupsBetaFeature' ) !== true ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-07 11:52:40 +00:00
|
|
|
$prefs['popups'] = array(
|
|
|
|
'label-message' => 'popups-message',
|
|
|
|
'desc-message' => 'popups-desc',
|
2014-03-21 22:43:21 +00:00
|
|
|
'screenshot' => array(
|
2016-10-17 18:54:49 +00:00
|
|
|
'ltr' => "$wgExtensionAssetsPath/Popups/images/popups-ltr.svg",
|
|
|
|
'rtl' => "$wgExtensionAssetsPath/Popups/images/popups-rtl.svg",
|
2014-03-21 22:43:21 +00:00
|
|
|
),
|
2014-04-13 02:35:55 +00:00
|
|
|
'info-link' => 'https://www.mediawiki.org/wiki/Beta_Features/Hovercards',
|
2014-02-07 11:52:40 +00:00
|
|
|
'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Beta_Features/Hovercards',
|
2014-08-21 00:46:59 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'javascript' => true,
|
|
|
|
),
|
2014-02-07 11:52:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:02:38 +00:00
|
|
|
/**
|
|
|
|
* @return Config
|
|
|
|
*/
|
|
|
|
public static function getConfig() {
|
|
|
|
static $config;
|
|
|
|
if ( !$config ) {
|
|
|
|
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'popups' );
|
|
|
|
}
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2014-02-06 10:49:28 +00:00
|
|
|
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin) {
|
2014-03-29 06:20:06 +00:00
|
|
|
// 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.
|
2015-03-16 13:02:38 +00:00
|
|
|
|
2015-12-18 22:05:11 +00:00
|
|
|
$registry = ExtensionRegistry::getInstance();
|
|
|
|
if ( !$registry->isLoaded( 'TextExtracts' ) || !class_exists( 'ApiQueryPageImages' ) ) {
|
2015-03-16 13:02:38 +00:00
|
|
|
$logger = LoggerFactory::getInstance( 'popups' );
|
|
|
|
$logger->error( 'Popups requires the PageImages and TextExtracts extensions.' );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 09:03:52 +00:00
|
|
|
$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
|
|
|
|
) {
|
2015-03-16 13:02:38 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-02-06 10:49:28 +00:00
|
|
|
}
|
2015-03-16 13:02:38 +00:00
|
|
|
|
2016-11-08 07:57:30 +00:00
|
|
|
$out->addModules( array( 'ext.popups' ) );
|
2015-03-16 13:02:38 +00:00
|
|
|
|
|
|
|
return true;
|
2014-02-06 10:49:28 +00:00
|
|
|
}
|
2014-06-11 04:34:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array &$testModules
|
|
|
|
* @param ResourceLoader $resourceLoader
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules, ResourceLoader &$resourceLoader ) {
|
2016-11-08 15:59:22 +00:00
|
|
|
$testModules['qunit']['ext.popups.tests'] = [
|
|
|
|
'scripts' => [
|
2016-11-08 19:42:21 +00:00
|
|
|
'tests/qunit/ext.popups/userSettings.test.js',
|
|
|
|
'tests/qunit/ext.popups/experiment.test.js',
|
2016-11-09 11:57:24 +00:00
|
|
|
'tests/qunit/ext.popups/processLinks.test.js',
|
2016-11-08 19:42:21 +00:00
|
|
|
],
|
|
|
|
'dependencies' => [
|
|
|
|
'ext.popups',
|
2016-11-08 15:59:22 +00:00
|
|
|
],
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
'remoteExtPath' => 'Popups',
|
|
|
|
];
|
2014-06-11 04:34:49 +00:00
|
|
|
}
|
2014-11-11 05:49:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $vars
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
|
|
|
$conf = ConfigFactory::getDefaultInstance()->makeConfig( 'popups' );
|
2016-05-12 22:37:19 +00:00
|
|
|
$vars['wgPopupsSchemaPopupsSamplingRate'] = $conf->get( 'SchemaPopupsSamplingRate' );
|
2016-05-16 09:03:52 +00:00
|
|
|
|
|
|
|
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' );
|
|
|
|
}
|
2014-11-11 05:49:07 +00:00
|
|
|
}
|
2014-02-06 10:49:28 +00:00
|
|
|
}
|