X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fcache%2FLinkCache.php;h=80181179e458da014f5df3eff3f14d4c448adf92;hp=c13f95e1ed42972f1877974c966bebb0a24a16de;hb=bd5a37aacf600bdd5f3a6e7998f92bd1d9326a8a;hpb=ae58991566bd7f666982cdfcac9c84a79173d6ab diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index c13f95e1ed..80181179e4 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; } /** @@ -231,9 +243,7 @@ class LinkCache { */ public function addLinkObj( LinkTarget $nt ) { $key = $this->titleFormatter->getPrefixedDBkey( $nt ); - if ( $this->isBadLink( $key ) || $nt->isExternal() - || $nt->inNamespace( NS_SPECIAL ) - ) { + if ( $this->isBadLink( $key ) || $nt->isExternal() || $nt->getNamespace() < 0 ) { return 0; } $id = $this->getGoodLinkID( $key ); @@ -296,15 +306,15 @@ class LinkCache { private function isCacheable( LinkTarget $title ) { $ns = $title->getNamespace(); - if ( in_array( $ns, [ NS_TEMPLATE, NS_FILE, NS_CATEGORY ] ) ) { + if ( in_array( $ns, [ NS_TEMPLATE, NS_FILE, NS_CATEGORY, NS_MEDIAWIKI ] ) ) { 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 ) {