Make GenderCache use MediaWikiServices
authoraddshore <addshorewiki@gmail.com>
Sat, 7 May 2016 12:15:44 +0000 (13:15 +0100)
committeraddshore <addshorewiki@gmail.com>
Sat, 7 May 2016 12:26:26 +0000 (13:26 +0100)
Change-Id: Id20310f78d938bdfa4d29ae483bb1a33bacd2b51

includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/cache/GenderCache.php
tests/phpunit/includes/MediaWikiServicesTest.php

index 6c650aa..d39b0df 100644 (file)
@@ -4,6 +4,7 @@ namespace MediaWiki;
 use Config;
 use ConfigFactory;
 use EventRelayerGroup;
+use GenderCache;
 use GlobalVarConfig;
 use Hooks;
 use LBFactory;
@@ -422,6 +423,14 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'WatchedItemStore' );
        }
 
+       /**
+        * @since 1.28
+        * @return GenderCache
+        */
+       public function getGenderCache() {
+               return $this->getService( 'GenderCache' );
+       }
+
        ///////////////////////////////////////////////////////////////////////////
        // NOTE: When adding a service getter here, don't forget to add a test
        // case for it in MediaWikiServicesTest::provideGetters() and in
index 8e95034..e282bda 100644 (file)
@@ -139,6 +139,10 @@ return [
                return $store;
        },
 
+       'GenderCache' => function( MediaWikiServices $services ) {
+               return new GenderCache();
+       },
+
        ///////////////////////////////////////////////////////////////////////////
        // NOTE: When adding a service here, don't forget to add a getter function
        // in the MediaWikiServices class. The convenience getter should just call
index 19695df..80f04ce 100644 (file)
@@ -21,6 +21,7 @@
  * @author Niklas Laxström
  * @ingroup Cache
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Caches user genders when needed to use correct namespace aliases.
@@ -34,18 +35,11 @@ class GenderCache {
        protected $missLimit = 1000;
 
        /**
+        * @deprecated in 1.28 see MediaWikiServices::getInstance()->getGenderCache()
         * @return GenderCache
         */
        public static function singleton() {
-               static $that = null;
-               if ( $that === null ) {
-                       $that = new self();
-               }
-
-               return $that;
-       }
-
-       protected function __construct() {
+               return MediaWikiServices::getInstance()->getGenderCache();
        }
 
        /**
index 6c38d50..4f917a5 100644 (file)
@@ -238,6 +238,7 @@ class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
                        'DBLoadBalancerFactory' => [ 'DBLoadBalancerFactory', 'LBFactory' ],
                        'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
                        'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
+                       'GenderCache' => [ 'GenderCache', GenderCache::class ],
                ];
        }