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-10-11 18:19:12 +00:00
|
|
|
/**
|
|
|
|
* @param ResourceLoader $rl
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader $rl ) {
|
|
|
|
$moduleDependencies = array(
|
|
|
|
'mediawiki.jqueryMsg',
|
2016-06-24 16:25:20 +00:00
|
|
|
'mediawiki.ui.button',
|
|
|
|
'mediawiki.ui.icon',
|
2014-10-11 18:19:12 +00:00
|
|
|
'moment',
|
2015-05-03 12:28:59 +00:00
|
|
|
'jquery.hidpi',
|
2016-01-29 16:48:24 +00:00
|
|
|
'ext.popups.targets.desktopTarget',
|
2016-06-24 16:25:20 +00:00
|
|
|
'ext.popups.images',
|
2014-10-11 18:19:12 +00:00
|
|
|
);
|
|
|
|
|
2016-05-12 22:37:19 +00:00
|
|
|
// Create a schema module and add it as a dependency of `ext.popups.desktop`.
|
|
|
|
$schemaPopups = [
|
|
|
|
'remoteExtPath' => 'Popups',
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
'targets' => [ 'desktop' ],
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( class_exists( 'EventLogging' ) ) {
|
|
|
|
$schemaPopups += [
|
|
|
|
'dependencies' => [
|
|
|
|
'schema.Popups',
|
2016-05-16 20:32:11 +00:00
|
|
|
'ext.popups.schemaPopups.utils',
|
2016-05-12 22:37:19 +00:00
|
|
|
],
|
|
|
|
'scripts' => [
|
2016-10-17 18:54:49 +00:00
|
|
|
'resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js',
|
2016-05-12 22:37:19 +00:00
|
|
|
]
|
|
|
|
];
|
2014-10-11 18:19:12 +00:00
|
|
|
}
|
2016-05-12 22:37:19 +00:00
|
|
|
$rl->register('ext.popups.schemaPopups', $schemaPopups );
|
|
|
|
$moduleDependencies[] = 'ext.popups.schemaPopups';
|
2014-10-11 18:19:12 +00:00
|
|
|
|
2016-01-29 16:48:24 +00:00
|
|
|
$rl->register( "ext.popups.desktop", array(
|
2014-10-11 18:19:12 +00:00
|
|
|
'scripts' => array(
|
2016-10-17 18:54:49 +00:00
|
|
|
'resources/ext.popups.desktop/ext.popups.renderer.article.js',
|
|
|
|
'resources/ext.popups.desktop/ext.popups.settings.js',
|
2014-10-11 18:19:12 +00:00
|
|
|
),
|
2016-05-12 22:58:53 +00:00
|
|
|
'templates' => array(
|
2016-10-17 18:54:49 +00:00
|
|
|
'popup.mustache' => 'resources/ext.popups.desktop/popup.mustache',
|
|
|
|
'settings.mustache' => 'resources/ext.popups.desktop/settings.mustache',
|
2016-05-12 22:58:53 +00:00
|
|
|
),
|
2014-10-11 18:19:12 +00:00
|
|
|
'styles' => array(
|
2016-10-17 18:54:49 +00:00
|
|
|
'resources/ext.popups.desktop/ext.popups.animation.less',
|
|
|
|
'resources/ext.popups.desktop/ext.popups.settings.less',
|
2014-10-11 18:19:12 +00:00
|
|
|
),
|
|
|
|
'dependencies' => $moduleDependencies,
|
|
|
|
'messages' => array(
|
|
|
|
'popups-last-edited',
|
|
|
|
"popups-settings-title",
|
|
|
|
"popups-settings-description",
|
|
|
|
"popups-settings-option-simple",
|
|
|
|
"popups-settings-option-simple-description",
|
|
|
|
"popups-settings-option-advanced",
|
|
|
|
"popups-settings-option-advanced-description",
|
|
|
|
"popups-settings-option-off",
|
|
|
|
"popups-settings-save",
|
|
|
|
"popups-settings-cancel",
|
|
|
|
"popups-settings-enable",
|
2014-08-29 04:22:55 +00:00
|
|
|
"popups-settings-help",
|
|
|
|
"popups-settings-help-ok",
|
2014-11-11 05:49:07 +00:00
|
|
|
"popups-send-feedback",
|
2014-10-11 18:19:12 +00:00
|
|
|
),
|
|
|
|
'remoteExtPath' => 'Popups',
|
|
|
|
'localBasePath' => __DIR__,
|
|
|
|
) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-01-29 16:48:24 +00:00
|
|
|
$out->addModules( array( 'ext.popups.desktop' ) );
|
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 08:03:20 +00:00
|
|
|
//$testModules['qunit']['ext.popups.tests'] = [
|
|
|
|
// 'scripts' => [],
|
|
|
|
// 'dependencies' => [],
|
|
|
|
// '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' );
|
|
|
|
$vars['wgPopupsSurveyLink'] = $conf->get( 'PopupsSurveyLink' );
|
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
|
|
|
}
|