Add LinkCache to MediaWikiServices

LinkCache::singleton() is now deprecated, and the destroySingleton() and
setSingleton() methods were removed. They were not used in extensions,
and the usage in core was updated to use MediaWikiServices.

Change-Id: I08bb4f7913b03f71331ff683d0197c948aad6790
This commit is contained in:
Kunal Mehta 2016-05-12 15:44:33 -07:00
parent 279dd4156c
commit 449084ec4e
5 changed files with 22 additions and 33 deletions

View file

@ -8,6 +8,7 @@ use GenderCache;
use GlobalVarConfig;
use Hooks;
use LBFactory;
use LinkCache;
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use LoadBalancer;
use MediaWiki\Services\ServiceContainer;
@ -460,6 +461,15 @@ class MediaWikiServices extends ServiceContainer {
public function getGenderCache() {
return $this->getService( 'GenderCache' );
}
/**
* @since 1.28
* @return LinkCache
*/
public function getLinkCache() {
return $this->getService( 'LinkCache' );
}
/**
* @since 1.28
* @return TitleFormatter

View file

@ -139,6 +139,12 @@ return [
return $store;
},
'LinkCache' => function( MediaWikiServices $services ) {
return new LinkCache(
$services->getTitleFormatter()
);
},
'GenderCache' => function( MediaWikiServices $services ) {
return new GenderCache();
},

View file

@ -65,39 +65,10 @@ class LinkCache {
* Get an instance of this class.
*
* @return LinkCache
* @deprecated since 1.28, use MediaWikiServices instead
*/
public static function singleton() {
if ( !self::$instance ) {
self::$instance = new LinkCache(
MediaWikiServices::getInstance()->getTitleFormatter()
);
}
return self::$instance;
}
/**
* Destroy the singleton instance
*
* A new one will be created next time singleton() is called.
*
* @since 1.22
*/
public static function destroySingleton() {
self::$instance = null;
}
/**
* Set the singleton instance to a given object.
*
* Since we do not have an interface for LinkCache, you have to be sure the
* given object implements all the LinkCache public methods.
*
* @param LinkCache $instance
* @since 1.22
*/
public static function setSingleton( LinkCache $instance ) {
self::$instance = $instance;
return MediaWikiServices::getInstance()->getLinkCache();
}
/**

View file

@ -243,6 +243,7 @@ class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
'GenderCache' => [ 'GenderCache', GenderCache::class ],
'LinkCache' => [ 'LinkCache', LinkCache::class ],
'_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ],
'TitleParser' => [ 'TitleParser', TitleParser::class ],

View file

@ -1,4 +1,5 @@
<?php
use MediaWiki\MediaWikiServices;
/**
* @group ContentHandler
@ -36,7 +37,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
MWNamespace::getCanonicalNamespaces( true );
$wgContLang->resetNamespaces();
// And LinkCache
LinkCache::destroySingleton();
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
}
protected function tearDown() {
@ -46,7 +47,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
MWNamespace::getCanonicalNamespaces( true );
$wgContLang->resetNamespaces();
// And LinkCache
LinkCache::destroySingleton();
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
parent::tearDown();
}