From: Aryeh Gregor Date: Tue, 9 Apr 2019 09:30:58 +0000 (+0300) Subject: Update LinkCache to use NamespaceInfo X-Git-Tag: 1.34.0-rc.0~1795^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=6f2906e36a78acc2d74487986ab3465495eaffcf;p=lhc%2Fweb%2Fwiklou.git Update LinkCache to use NamespaceInfo Change-Id: Ie9ebc2564861068dea8a64aea5cbeacb03597cea --- diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index bf722c38b2..9be85eb6a4 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -231,7 +231,8 @@ return [ 'LinkCache' => function ( MediaWikiServices $services ) : LinkCache { return new LinkCache( $services->getTitleFormatter(), - $services->getMainWANObjectCache() + $services->getMainWANObjectCache(), + $services->getNamespaceInfo() ); }, diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index c13f95e1ed..eb94f9da80 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -45,17 +45,29 @@ class LinkCache { /** @var TitleFormatter */ private $titleFormatter; + /** @var NamespaceInfo */ + private $nsInfo; + /** * How many Titles to store. There are two caches, so the amount actually * stored in memory can be up to twice this. */ const MAX_SIZE = 10000; - public function __construct( TitleFormatter $titleFormatter, WANObjectCache $cache ) { + public function __construct( + TitleFormatter $titleFormatter, + WANObjectCache $cache, + NamespaceInfo $nsInfo = null + ) { + if ( !$nsInfo ) { + wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + } $this->goodLinks = new MapCacheLRU( self::MAX_SIZE ); $this->badLinks = new MapCacheLRU( self::MAX_SIZE ); $this->wanCache = $cache; $this->titleFormatter = $titleFormatter; + $this->nsInfo = $nsInfo; } /** @@ -300,11 +312,11 @@ class LinkCache { return true; } // Focus on transcluded pages more than the main content - if ( MWNamespace::isContent( $ns ) ) { + if ( $this->nsInfo->isContent( $ns ) ) { return false; } // Non-talk extension namespaces (e.g. NS_MODULE) - return ( $ns >= 100 && MWNamespace::isSubject( $ns ) ); + return ( $ns >= 100 && $this->nsInfo->isSubject( $ns ) ); } private function fetchPageRow( IDatabase $db, LinkTarget $nt ) { diff --git a/tests/phpunit/includes/linker/LinkRendererTest.php b/tests/phpunit/includes/linker/LinkRendererTest.php index 91ee276550..e90577c907 100644 --- a/tests/phpunit/includes/linker/LinkRendererTest.php +++ b/tests/phpunit/includes/linker/LinkRendererTest.php @@ -140,7 +140,8 @@ class LinkRendererTest extends MediaWikiLangTestCase { public function testGetLinkClasses() { $wanCache = ObjectCache::getMainWANInstance(); $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter(); - $linkCache = new LinkCache( $titleFormatter, $wanCache ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + $linkCache = new LinkCache( $titleFormatter, $wanCache, $nsInfo ); $foobarTitle = new TitleValue( NS_MAIN, 'FooBar' ); $redirectTitle = new TitleValue( NS_MAIN, 'Redirect' ); $userTitle = new TitleValue( NS_USER, 'Someuser' );