Merge "Update LinkCache to use NamespaceInfo"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 6 May 2019 16:48:20 +0000 (16:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 6 May 2019 16:48:20 +0000 (16:48 +0000)
1  2 
includes/ServiceWiring.php
includes/cache/LinkCache.php

@@@ -208,7 -208,7 +208,7 @@@ return 
        },
  
        'GenderCache' => function ( MediaWikiServices $services ) : GenderCache {
 -              return new GenderCache();
 +              return new GenderCache( $services->getNamespaceInfo() );
        },
  
        'HttpRequestFactory' =>
        'LinkCache' => function ( MediaWikiServices $services ) : LinkCache {
                return new LinkCache(
                        $services->getTitleFormatter(),
-                       $services->getMainWANObjectCache()
+                       $services->getMainWANObjectCache(),
+                       $services->getNamespaceInfo()
                );
        },
  
        },
  
        'NamespaceInfo' => function ( MediaWikiServices $services ) : NamespaceInfo {
 -              return new NamespaceInfo( $services->getMainConfig() );
 +              return new NamespaceInfo( new ServiceOptions( NamespaceInfo::$constructorOptions,
 +                      $services->getMainConfig() ) );
        },
  
        'NameTableStoreFactory' => function ( MediaWikiServices $services ) : NameTableStoreFactory {
                                DefaultPreferencesFactory::$constructorOptions, $services->getMainConfig() ),
                        $services->getContentLanguage(),
                        AuthManager::singleton(),
 -                      $services->getLinkRendererFactory()->create()
 +                      $services->getLinkRendererFactory()->create(),
 +                      $services->getNamespaceInfo()
                );
                $factory->setLogger( LoggerFactory::getInstance( 'preferences' ) );
  
                );
        },
  
 +      'RepoGroup' => function ( MediaWikiServices $services ) : RepoGroup {
 +              $config = $services->getMainConfig();
 +              return new RepoGroup(
 +                      $config->get( 'LocalFileRepo' ),
 +                      $config->get( 'ForeignFileRepos' ),
 +                      $services->getMainWANObjectCache()
 +              );
 +      },
 +
        'ResourceLoader' => function ( MediaWikiServices $services ) : ResourceLoader {
                // @todo This should not take a Config object, but it's not so easy to remove because it
                // exposes it in a getter, which is actually used.
@@@ -45,17 -45,29 +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;
        }
  
        /**
         */
        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 );
                        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 ) {