2016-12-16 02:47:52 +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
|
|
|
|
*/
|
|
|
|
namespace Popups;
|
|
|
|
|
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2016-12-20 21:54:47 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use ExtensionRegistry;
|
2017-01-11 21:52:07 +00:00
|
|
|
use Config;
|
2016-12-16 02:47:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Popups Module
|
|
|
|
*
|
|
|
|
* @package Popups
|
|
|
|
*/
|
|
|
|
class PopupsContext {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extension name
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const EXTENSION_NAME = 'popups';
|
|
|
|
/**
|
|
|
|
* Logger channel (name)
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const LOGGER_CHANNEL = 'popups';
|
|
|
|
/**
|
|
|
|
* User preference value for enabled Page Previews
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const PREVIEWS_ENABLED = \HTMLFeatureField::OPTION_ENABLED;
|
|
|
|
/**
|
|
|
|
* User preference value for disabled Page Previews
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const PREVIEWS_DISABLED = \HTMLFeatureField::OPTION_DISABLED;
|
|
|
|
/**
|
|
|
|
* User preference to enable/disable Page Previews
|
|
|
|
* Currently for BETA and regular opt in we use same preference name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
|
|
|
/**
|
|
|
|
* User preference to enable/disable Page Preivews as a beta feature
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const PREVIEWS_BETA_PREFERENCE_NAME = 'popups';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Config
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2016-12-20 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* @var PopupsContext
|
|
|
|
*/
|
|
|
|
protected static $instance;
|
2016-12-16 02:47:52 +00:00
|
|
|
/**
|
|
|
|
* Module constructor.
|
2017-01-11 21:52:07 +00:00
|
|
|
* @param Config $config
|
2016-12-20 21:54:47 +00:00
|
|
|
* @param ExtensionRegistry $extensionRegistry
|
2017-01-11 21:52:07 +00:00
|
|
|
* @param PopupsGadgetsIntegration $gadgetsIntegration
|
2016-12-16 02:47:52 +00:00
|
|
|
*/
|
2017-01-11 21:52:07 +00:00
|
|
|
protected function __construct( Config $config, ExtensionRegistry $extensionRegistry,
|
2017-01-04 16:33:40 +00:00
|
|
|
PopupsGadgetsIntegration $gadgetsIntegration ) {
|
2016-12-20 21:54:47 +00:00
|
|
|
/** @todo Use MediaWikiServices Service Locator when it's ready */
|
|
|
|
$this->extensionRegistry = $extensionRegistry;
|
2017-01-04 16:33:40 +00:00
|
|
|
$this->gadgetsIntegration = $gadgetsIntegration;
|
|
|
|
|
2017-01-11 21:52:07 +00:00
|
|
|
$this->config = $config;
|
2016-12-16 02:47:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Get a PopupsContext instance
|
|
|
|
*
|
|
|
|
* @return PopupsContext
|
|
|
|
*/
|
|
|
|
public static function getInstance() {
|
|
|
|
if ( !self::$instance ) {
|
2017-01-11 21:52:07 +00:00
|
|
|
/** @todo Use MediaWikiServices Service Locator when it's ready */
|
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
$registry = ExtensionRegistry::getInstance();
|
2017-01-11 21:52:07 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()
|
|
|
|
->makeConfig( PopupsContext::EXTENSION_NAME );
|
|
|
|
$gadgetsIntegration = new PopupsGadgetsIntegration( $config, $registry );
|
|
|
|
self::$instance = new PopupsContext( $config, $registry, $gadgetsIntegration );
|
2016-12-20 21:54:47 +00:00
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
2017-01-04 16:33:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function conflictsWithNavPopupsGadget( \User $user ) {
|
|
|
|
return $this->gadgetsIntegration->conflictsWithNavPopupsGadget( $user );
|
|
|
|
}
|
2016-12-20 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* Is Beta Feature mode enabled
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isBetaFeatureEnabled() {
|
|
|
|
return $this->config->get( 'PopupsBetaFeature' ) === true;
|
|
|
|
}
|
2017-01-10 01:28:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default Page previews state
|
|
|
|
*
|
|
|
|
* @see PopupsContext::PREVIEWS_ENABLED
|
|
|
|
* @see PopupsContext::PREVIEWS_DISABLED
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDefaultIsEnabledState() {
|
|
|
|
return $this->config->get( 'PopupsOptInDefaultState' );
|
|
|
|
}
|
2016-12-16 02:47:52 +00:00
|
|
|
/**
|
|
|
|
* Are Page previews visible on User Preferences Page
|
|
|
|
*
|
|
|
|
* return @bool
|
|
|
|
*/
|
|
|
|
public function showPreviewsOptInOnPreferencesPage() {
|
2016-12-20 21:54:47 +00:00
|
|
|
return !$this->isBetaFeatureEnabled()
|
2016-12-16 02:47:52 +00:00
|
|
|
&& $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-02-10 00:27:05 +00:00
|
|
|
public function shouldSendModuleToUser( \User $user ) {
|
2016-12-20 21:54:47 +00:00
|
|
|
if ( $this->isBetaFeatureEnabled() ) {
|
2017-02-08 22:08:12 +00:00
|
|
|
return $user->isAnon() ? false :
|
|
|
|
\BetaFeatures::isFeatureEnabled( $user, self::PREVIEWS_BETA_PREFERENCE_NAME );
|
|
|
|
}
|
|
|
|
return $user->isAnon() ? true :
|
|
|
|
$user->getOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME ) === self::PREVIEWS_ENABLED;
|
2016-12-16 02:47:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:54:47 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function areDependenciesMet() {
|
|
|
|
$areMet = $this->extensionRegistry->isLoaded( 'TextExtracts' )
|
|
|
|
&& $this->extensionRegistry->isLoaded( 'PageImages' );
|
|
|
|
|
|
|
|
if ( $this->isBetaFeatureEnabled() ) {
|
|
|
|
$areMet = $areMet && $this->extensionRegistry->isLoaded( 'BetaFeatures' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $areMet;
|
|
|
|
}
|
2016-12-16 02:47:52 +00:00
|
|
|
/**
|
|
|
|
* Get module logger
|
|
|
|
*
|
|
|
|
* @return \Psr\Log\LoggerInterface
|
|
|
|
*/
|
|
|
|
public function getLogger() {
|
|
|
|
return LoggerFactory::getInstance( self::LOGGER_CHANNEL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Module config
|
|
|
|
*
|
|
|
|
* @return \Config
|
|
|
|
*/
|
|
|
|
public function getConfig() {
|
|
|
|
return $this->config;
|
|
|
|
}
|
2016-12-20 21:54:47 +00:00
|
|
|
|
2016-12-16 02:47:52 +00:00
|
|
|
}
|