Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 29
PopupHandler
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
156
0.00% covered (danger)
0.00%
0 / 29
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 6
 onBeforePageDisplay
0.00% covered (danger)
0.00%
0 / 1
132
0.00% covered (danger)
0.00%
0 / 23
<?php
namespace MediaWiki\IPInfo\HookHandler;
use ExtensionRegistry;
use MediaWiki\Hook\BeforePageDisplayHook;
use Mediawiki\Permissions\PermissionManager;
use MediaWiki\User\UserOptionsLookup;
class PopupHandler implements BeforePageDisplayHook {
    /** @var PermissionManager */
    private $permissionManager;
    /** @var UserOptionsLookup */
    private $userOptionsLookup;
    /**
     * @param PermissionManager $permissionManager
     * @param UserOptionsLookup $userOptionsLookup
     */
    public function __construct(
        PermissionManager $permissionManager,
        UserOptionsLookup $userOptionsLookup
    ) {
        $this->permissionManager = $permissionManager;
        $this->userOptionsLookup = $userOptionsLookup;
    }
    /**
     * @inheritDoc
     */
    public function onBeforePageDisplay( $out, $skin ): void {
        if (
            $out->getRequest()->getVal( 'action' ) !== 'history' &&
            !( $out->getTitle() &&
                ( $out->getTitle()->isSpecial( 'Log' ) ||
                     $out->getTitle()->isSpecial( 'Recentchanges' ) ||
                     $out->getTitle()->isSpecial( 'Watchlist' ) ) )
        ) {
            return;
        }
        $user = $out->getUser();
        $isBetaFeaturesLoaded = ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' );
        if (
            !$this->permissionManager->userHasRight( $user, 'ipinfo' ) ||
            !$this->userOptionsLookup->getOption( $user, 'ipinfo-enable' ) ||
            !$this->userOptionsLookup->getOption( $user, 'ipinfo-use-agreement' ) ||
            $isBetaFeaturesLoaded &&
            !$this->userOptionsLookup->getOption( $user, 'ipinfo-beta-feature-enable' )
        ) {
            return;
        }
        $out->addModules( 'ext.ipInfo' );
        $out->addModuleStyles( 'ext.ipInfo.styles' );
    }
}