From 571567cddcb19e6d12073b75b328382d129e2b6a Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 5 Aug 2018 13:05:44 +0300 Subject: [PATCH] Update GenderCache to use NamespaceInfo Change-Id: I0c2997bf8764249c26251d0f63f3ea0a0b272a7e --- includes/ServiceWiring.php | 2 +- includes/cache/GenderCache.php | 11 +++++++++-- tests/phpunit/includes/TitleTest.php | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index bf722c38b2..fc3f8e257a 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -208,7 +208,7 @@ return [ }, 'GenderCache' => function ( MediaWikiServices $services ) : GenderCache { - return new GenderCache(); + return new GenderCache( $services->getNamespaceInfo() ); }, 'HttpRequestFactory' => diff --git a/includes/cache/GenderCache.php b/includes/cache/GenderCache.php index 7228814d47..eedc3c6f04 100644 --- a/includes/cache/GenderCache.php +++ b/includes/cache/GenderCache.php @@ -34,6 +34,13 @@ class GenderCache { protected $misses = 0; protected $missLimit = 1000; + /** @var NamespaceInfo */ + private $nsInfo; + + public function __construct( NamespaceInfo $nsInfo = null ) { + $this->nsInfo = $nsInfo ?? MediaWikiServices::getInstance()->getNamespaceInfo(); + } + /** * @deprecated in 1.28 see MediaWikiServices::getInstance()->getGenderCache() * @return GenderCache @@ -97,7 +104,7 @@ class GenderCache { public function doLinkBatch( $data, $caller = '' ) { $users = []; foreach ( $data as $ns => $pagenames ) { - if ( !MWNamespace::hasGenderDistinction( $ns ) ) { + if ( !$this->nsInfo->hasGenderDistinction( $ns ) ) { continue; } foreach ( array_keys( $pagenames ) as $username ) { @@ -122,7 +129,7 @@ class GenderCache { if ( !$titleObj ) { continue; } - if ( !MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) { + if ( !$this->nsInfo->hasGenderDistinction( $titleObj->getNamespace() ) ) { continue; } $users[] = $titleObj->getText(); diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index c0de1bfbc0..2159a35bf3 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -157,6 +157,7 @@ class TitleTest extends MediaWikiTestCase { ] ] ); + // Reset services since we modified $wgLocalInterwikis $this->overrideMwServices(); } -- 2.20.1