Avoid using User::getBoolOption()

User::getBoolOption() is deprecated and should be replaced with UserOptionsLookup::getBoolOption()

Bug: T277600
Change-Id: I562b19ca41a7ef18be940ec398d58d6873b2555b
This commit is contained in:
ZabeMath 2021-03-30 20:24:32 +02:00 committed by Zabe
parent 72c69e644a
commit 7e23848ac9
3 changed files with 19 additions and 5 deletions

View file

@ -5,6 +5,7 @@ namespace CookieWarning;
use Config;
use ConfigException;
use IContextSource;
use MediaWiki\User\UserOptionsLookup;
use MWException;
use WANObjectCache;
@ -12,6 +13,7 @@ class Decisions {
private $config;
private $geoLocation;
private $cache;
private $userOptionsLookup;
private const CACHE_KEY = 'cookieWarningIpLookupCache:';
@ -19,11 +21,18 @@ class Decisions {
* @param Config $config
* @param GeoLocation $geoLocation
* @param WANObjectCache $cache
* @param UserOptionsLookup $userOptionsLookup
*/
public function __construct( Config $config, GeoLocation $geoLocation, WANObjectCache $cache ) {
public function __construct(
Config $config,
GeoLocation $geoLocation,
WANObjectCache $cache,
UserOptionsLookup $userOptionsLookup
) {
$this->config = $config;
$this->geoLocation = $geoLocation;
$this->cache = $cache;
$this->userOptionsLookup = $userOptionsLookup;
}
/**
@ -39,7 +48,7 @@ class Decisions {
$user = $context->getUser();
return $this->config->get( 'CookieWarningEnabled' ) &&
!$user->getBoolOption( 'cookiewarning_dismissed', false ) &&
!$this->userOptionsLookup->getBoolOption( $user, 'cookiewarning_dismissed' ) &&
!$context->getRequest()->getCookie( 'cookiewarning_dismissed' ) &&
( $this->config->get( 'CookieWarningGeoIPLookup' ) === 'js' ||
$this->isInConfiguredRegion( $context ) );

View file

@ -21,7 +21,11 @@ return [
return new HttpGeoLocation( $geoIPServiceURL );
},
'CookieWarning.Decisions' => function ( MediaWikiServices $services ) {
return new Decisions( $services->getService( 'CookieWarning.Config' ),
$services->getService( 'GeoLocation' ), $services->getMainWANObjectCache() );
return new Decisions(
$services->getService( 'CookieWarning.Config' ),
$services->getService( 'GeoLocation' ),
$services->getMainWANObjectCache(),
$services->getUserOptionsLookup()
);
},
];

View file

@ -34,7 +34,8 @@ class DecisionsTest extends MediaWikiTestCase {
$cookieWarningDecisions = new Decisions(
MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' ),
$geoLocation,
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] )
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
MediaWikiServices::getInstance()->getUserOptionsLookup()
);
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );