| 1 |
<?php |
| 2 |
|
| 3 |
namespace Cite\ReferencePreviews; |
| 4 |
|
| 5 |
use MediaWiki\Config\Config; |
| 6 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 7 |
use MediaWiki\User\User; |
| 8 |
use Skin; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ReferencePreviewsContext { |
| 14 |
|
| 15 |
private Config $config; |
| 16 |
private ReferencePreviewsGadgetsIntegration $gadgetsIntegration; |
| 17 |
private UserOptionsLookup $userOptionsLookup; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
Config $config, |
| 21 |
ReferencePreviewsGadgetsIntegration $gadgetsIntegration, |
| 22 |
UserOptionsLookup $userOptionsLookup |
| 23 |
) { |
| 24 |
$this->config = $config; |
| 25 |
$this->gadgetsIntegration = $gadgetsIntegration; |
| 26 |
$this->userOptionsLookup = $userOptionsLookup; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popups-reference-previews'; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public function isReferencePreviewsEnabled( User $user, Skin $skin ): bool { |
| 41 |
if ( |
| 42 |
|
| 43 |
$skin->getSkinName() === 'minerva' || |
| 44 |
|
| 45 |
|
| 46 |
!$this->config->get( 'CiteReferencePreviews' ) || |
| 47 |
$this->gadgetsIntegration->isRefToolTipsGadgetEnabled( $user ) || |
| 48 |
$this->gadgetsIntegration->isNavPopupsGadgetEnabled( $user ) |
| 49 |
) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
return !$user->isNamed() || $this->userOptionsLookup->getBoolOption( |
| 55 |
$user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME |
| 56 |
); |
| 57 |
} |
| 58 |
} |