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.
|
2020-01-26 19:22:03 +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
|
|
|
|
*/
|
2017-01-04 16:33:40 +00:00
|
|
|
namespace Popups;
|
|
|
|
|
2024-01-05 21:41:45 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2022-03-06 01:33:08 +00:00
|
|
|
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
2024-01-05 21:41:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2017-01-11 21:52:07 +00:00
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
2019-02-01 08:40:34 +00:00
|
|
|
* Gadgets integration
|
|
|
|
*
|
|
|
|
* @package Popups
|
|
|
|
*/
|
2017-01-04 16:33:40 +00:00
|
|
|
class PopupsGadgetsIntegration {
|
2019-02-26 08:56:07 +00:00
|
|
|
|
2020-05-19 23:29:34 +00:00
|
|
|
public const CONFIG_NAVIGATION_POPUPS_NAME = 'PopupsConflictingNavPopupsGadgetName';
|
2019-02-26 08:56:07 +00:00
|
|
|
|
2017-01-11 21:52:07 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $navPopupsGadgetName;
|
|
|
|
|
2024-06-29 19:29:31 +00:00
|
|
|
private ?GadgetRepo $gadgetRepo;
|
|
|
|
|
2017-01-04 16:33:40 +00:00
|
|
|
/**
|
2017-07-12 20:16:55 +00:00
|
|
|
* @param Config $config MediaWiki configuration
|
2024-06-29 19:29:31 +00:00
|
|
|
* @param GadgetRepo|null $gadgetRepo
|
2017-01-04 16:33:40 +00:00
|
|
|
*/
|
2024-06-29 19:29:31 +00:00
|
|
|
public function __construct(
|
|
|
|
Config $config,
|
|
|
|
?GadgetRepo $gadgetRepo
|
|
|
|
) {
|
2017-04-10 22:27:19 +00:00
|
|
|
$this->navPopupsGadgetName = $this->sanitizeGadgetName(
|
|
|
|
$config->get( self::CONFIG_NAVIGATION_POPUPS_NAME ) );
|
2024-06-29 19:29:31 +00:00
|
|
|
$this->gadgetRepo = $gadgetRepo;
|
2017-01-04 16:33:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 22:27:19 +00:00
|
|
|
/**
|
2019-02-01 08:40:34 +00:00
|
|
|
* @param string $gadgetName
|
2017-04-10 22:27:19 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function sanitizeGadgetName( $gadgetName ) {
|
|
|
|
return str_replace( ' ', '_', trim( $gadgetName ) );
|
|
|
|
}
|
2019-01-16 14:25:27 +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
|
|
|
*
|
2024-01-05 21:41:45 +00:00
|
|
|
* @param User $user User whose gadget settings are checked
|
2017-01-04 16:33:40 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2024-01-05 21:41:45 +00:00
|
|
|
public function conflictsWithNavPopupsGadget( User $user ) {
|
2024-06-29 19:29:31 +00:00
|
|
|
if ( $this->gadgetRepo ) {
|
|
|
|
$match = array_search( $this->navPopupsGadgetName, $this->gadgetRepo->getGadgetIds() );
|
2017-01-04 16:33:40 +00:00
|
|
|
if ( $match !== false ) {
|
2017-04-10 22:27:19 +00:00
|
|
|
try {
|
2024-06-29 19:29:31 +00:00
|
|
|
return $this->gadgetRepo->getGadget( $this->navPopupsGadgetName )
|
2017-04-10 22:27:19 +00:00
|
|
|
->isEnabled( $user );
|
|
|
|
} catch ( \InvalidArgumentException $e ) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-04 16:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|