Update GenderCache to use NamespaceInfo
authorAryeh Gregor <ayg@aryeh.name>
Sun, 5 Aug 2018 10:05:44 +0000 (13:05 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 6 May 2019 09:08:45 +0000 (12:08 +0300)
Change-Id: I0c2997bf8764249c26251d0f63f3ea0a0b272a7e

includes/ServiceWiring.php
includes/cache/GenderCache.php
tests/phpunit/includes/TitleTest.php

index bf722c3..fc3f8e2 100644 (file)
@@ -208,7 +208,7 @@ return [
        },
 
        'GenderCache' => function ( MediaWikiServices $services ) : GenderCache {
-               return new GenderCache();
+               return new GenderCache( $services->getNamespaceInfo() );
        },
 
        'HttpRequestFactory' =>
index 7228814..eedc3c6 100644 (file)
@@ -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();
index c0de1bf..2159a35 100644 (file)
@@ -157,6 +157,7 @@ class TitleTest extends MediaWikiTestCase {
                        ]
                ] );
 
+               // Reset services since we modified $wgLocalInterwikis
                $this->overrideMwServices();
        }