2017-01-04 16:33:40 +00:00
|
|
|
<?php
|
2017-06-20 07:19:34 +00:00
|
|
|
/** This file is part of the MediaWiki extension Popups.
|
2017-01-04 16:33:40 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2017-01-11 21:52:07 +00:00
|
|
|
use Config;
|
|
|
|
use ExtensionRegistry;
|
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
|
|
|
* Gadgets integration
|
|
|
|
*
|
|
|
|
* @package Popups
|
|
|
|
*/
|
|
|
|
class PopupsGadgetsIntegration {
|
2017-01-11 21:52:07 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CONFIG_NAVIGATION_POPUPS_NAME = 'PopupsConflictingNavPopupsGadgetName';
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
|
|
|
* @var \ExtensionRegistry
|
|
|
|
*/
|
|
|
|
private $extensionRegistry;
|
|
|
|
|
2017-01-11 21:52:07 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $navPopupsGadgetName;
|
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
|
|
|
* PopupsGadgetsIntegration constructor.
|
2017-01-11 21:52:07 +00:00
|
|
|
*
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param Config $config MediaWiki configuration
|
|
|
|
* @param ExtensionRegistry $extensionRegistry MediaWiki extension registry
|
2017-01-04 16:33:40 +00:00
|
|
|
*/
|
2017-05-16 17:59:29 +00:00
|
|
|
public function __construct( Config $config, ExtensionRegistry $extensionRegistry ) {
|
2017-08-11 04:21:26 +00:00
|
|
|
$this->extensionRegistry = $extensionRegistry;
|
2017-04-10 22:27:19 +00:00
|
|
|
$this->navPopupsGadgetName = $this->sanitizeGadgetName(
|
|
|
|
$config->get( self::CONFIG_NAVIGATION_POPUPS_NAME ) );
|
2017-01-04 16:33:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 22:27:19 +00:00
|
|
|
/**
|
|
|
|
* Sanitize gadget name
|
|
|
|
*
|
|
|
|
* @param $gadgetName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function sanitizeGadgetName( $gadgetName ) {
|
|
|
|
return str_replace( ' ', '_', trim( $gadgetName ) );
|
|
|
|
}
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isGadgetExtensionEnabled() {
|
|
|
|
return $this->extensionRegistry->isLoaded( 'Gadgets' );
|
|
|
|
}
|
2017-01-11 21:52:07 +00:00
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
2018-03-20 20:20:43 +00:00
|
|
|
* Check if Popups conflicts with Nav Popups Gadget
|
|
|
|
* If user enabled Nav Popups, Popups is unavailable
|
2017-01-04 16:33:40 +00:00
|
|
|
*
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param \User $user User whose gadget settings are checked
|
2017-01-04 16:33:40 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function conflictsWithNavPopupsGadget( \User $user ) {
|
|
|
|
if ( $this->isGadgetExtensionEnabled() ) {
|
|
|
|
$gadgetsRepo = \GadgetRepo::singleton();
|
2017-01-11 21:52:07 +00:00
|
|
|
$match = array_search( $this->navPopupsGadgetName, $gadgetsRepo->getGadgetIds() );
|
2017-01-04 16:33:40 +00:00
|
|
|
if ( $match !== false ) {
|
2017-04-10 22:27:19 +00:00
|
|
|
try {
|
|
|
|
return $gadgetsRepo->getGadget( $this->navPopupsGadgetName )
|
|
|
|
->isEnabled( $user );
|
|
|
|
} catch ( \InvalidArgumentException $e ) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-04 16:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|