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:
parent
279dd4156c
commit
449084ec4e
5 changed files with 22 additions and 33 deletions
|
|
@ -8,6 +8,7 @@ use GenderCache;
|
||||||
use GlobalVarConfig;
|
use GlobalVarConfig;
|
||||||
use Hooks;
|
use Hooks;
|
||||||
use LBFactory;
|
use LBFactory;
|
||||||
|
use LinkCache;
|
||||||
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
|
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
|
||||||
use LoadBalancer;
|
use LoadBalancer;
|
||||||
use MediaWiki\Services\ServiceContainer;
|
use MediaWiki\Services\ServiceContainer;
|
||||||
|
|
@ -460,6 +461,15 @@ class MediaWikiServices extends ServiceContainer {
|
||||||
public function getGenderCache() {
|
public function getGenderCache() {
|
||||||
return $this->getService( 'GenderCache' );
|
return $this->getService( 'GenderCache' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.28
|
||||||
|
* @return LinkCache
|
||||||
|
*/
|
||||||
|
public function getLinkCache() {
|
||||||
|
return $this->getService( 'LinkCache' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.28
|
* @since 1.28
|
||||||
* @return TitleFormatter
|
* @return TitleFormatter
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,12 @@ return [
|
||||||
return $store;
|
return $store;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'LinkCache' => function( MediaWikiServices $services ) {
|
||||||
|
return new LinkCache(
|
||||||
|
$services->getTitleFormatter()
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
'GenderCache' => function( MediaWikiServices $services ) {
|
'GenderCache' => function( MediaWikiServices $services ) {
|
||||||
return new GenderCache();
|
return new GenderCache();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
33
includes/cache/LinkCache.php
vendored
33
includes/cache/LinkCache.php
vendored
|
|
@ -65,39 +65,10 @@ class LinkCache {
|
||||||
* Get an instance of this class.
|
* Get an instance of this class.
|
||||||
*
|
*
|
||||||
* @return LinkCache
|
* @return LinkCache
|
||||||
|
* @deprecated since 1.28, use MediaWikiServices instead
|
||||||
*/
|
*/
|
||||||
public static function singleton() {
|
public static function singleton() {
|
||||||
if ( !self::$instance ) {
|
return MediaWikiServices::getInstance()->getLinkCache();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,7 @@ class MediaWikiServicesTest extends PHPUnit_Framework_TestCase {
|
||||||
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
|
'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ],
|
||||||
'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
|
'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
|
||||||
'GenderCache' => [ 'GenderCache', GenderCache::class ],
|
'GenderCache' => [ 'GenderCache', GenderCache::class ],
|
||||||
|
'LinkCache' => [ 'LinkCache', LinkCache::class ],
|
||||||
'_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
|
'_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
|
||||||
'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ],
|
'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ],
|
||||||
'TitleParser' => [ 'TitleParser', TitleParser::class ],
|
'TitleParser' => [ 'TitleParser', TitleParser::class ],
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group ContentHandler
|
* @group ContentHandler
|
||||||
|
|
@ -36,7 +37,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
|
||||||
MWNamespace::getCanonicalNamespaces( true );
|
MWNamespace::getCanonicalNamespaces( true );
|
||||||
$wgContLang->resetNamespaces();
|
$wgContLang->resetNamespaces();
|
||||||
// And LinkCache
|
// And LinkCache
|
||||||
LinkCache::destroySingleton();
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
|
|
@ -46,7 +47,7 @@ class ContentHandlerTest extends MediaWikiTestCase {
|
||||||
MWNamespace::getCanonicalNamespaces( true );
|
MWNamespace::getCanonicalNamespaces( true );
|
||||||
$wgContLang->resetNamespaces();
|
$wgContLang->resetNamespaces();
|
||||||
// And LinkCache
|
// And LinkCache
|
||||||
LinkCache::destroySingleton();
|
MediaWikiServices::getInstance()->resetServiceForTesting( 'LinkCache' );
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue