Use DefaultOptionsLookup for default option in GenderCache
Change-Id: I778d2c4cd8de2aee138566fe82d658d046edf3f4
This commit is contained in:
parent
8d7015037d
commit
63eaa9ae89
3 changed files with 31 additions and 3 deletions
|
|
@ -369,7 +369,7 @@ return [
|
|||
$dbLoadBalancer = $services->isServiceDisabled( 'DBLoadBalancer' )
|
||||
? null
|
||||
: $services->getDBLoadBalancer();
|
||||
return new GenderCache( $nsInfo, $dbLoadBalancer );
|
||||
return new GenderCache( $nsInfo, $dbLoadBalancer, $services->get( '_DefaultOptionsLookup' ) );
|
||||
},
|
||||
|
||||
'GlobalIdGenerator' => function ( MediaWikiServices $services ) : GlobalIdGenerator {
|
||||
|
|
|
|||
13
includes/cache/GenderCache.php
vendored
13
includes/cache/GenderCache.php
vendored
|
|
@ -25,6 +25,7 @@
|
|||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
|
|
@ -44,9 +45,17 @@ class GenderCache {
|
|||
/** @var ILoadBalancer|null */
|
||||
private $loadBalancer;
|
||||
|
||||
public function __construct( NamespaceInfo $nsInfo = null, ILoadBalancer $loadBalancer = null ) {
|
||||
/** @var UserOptionsLookup */
|
||||
private $userOptionsLookup;
|
||||
|
||||
public function __construct(
|
||||
NamespaceInfo $nsInfo = null,
|
||||
ILoadBalancer $loadBalancer = null,
|
||||
UserOptionsLookup $userOptionsLookup = null
|
||||
) {
|
||||
$this->nsInfo = $nsInfo ?? MediaWikiServices::getInstance()->getNamespaceInfo();
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->userOptionsLookup = $userOptionsLookup ?? MediaWikiServices::getInstance()->getUserOptionsLookup();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,7 +74,7 @@ class GenderCache {
|
|||
*/
|
||||
protected function getDefault() {
|
||||
if ( $this->default === null ) {
|
||||
$this->default = User::getDefaultOption( 'gender' );
|
||||
$this->default = $this->userOptionsLookup->getDefaultOption( 'gender' );
|
||||
}
|
||||
|
||||
return $this->default;
|
||||
|
|
|
|||
19
tests/phpunit/includes/cache/GenderCacheTest.php
vendored
19
tests/phpunit/includes/cache/GenderCacheTest.php
vendored
|
|
@ -85,4 +85,23 @@ class GenderCacheTest extends MediaWikiLangTestCase {
|
|||
$gender = $genderCache->getGenderOf( "$username/subpage" );
|
||||
$this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );
|
||||
}
|
||||
|
||||
/**
|
||||
* GenderCache must work without database (like Installer)
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testWithoutDB() {
|
||||
self::overrideMwServices();
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$services->disableService( 'DBLoadBalancer' );
|
||||
$services->disableService( 'DBLoadBalancerFactory' );
|
||||
|
||||
// Make sure the disable works
|
||||
$this->assertTrue( $services->isServiceDisabled( 'DBLoadBalancer' ) );
|
||||
|
||||
// Test, if it is possible to create the gender cache
|
||||
$genderCache = $services->getGenderCache();
|
||||
$this->assertInstanceOf( GenderCache::class, $genderCache );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue