Merge "Add autocomplete for WhatLinksHere subpages"
[lhc/web/wiklou.git] / includes / site / SiteSQLStore.php
index fde22f1..8f25c76 100644 (file)
@@ -51,15 +51,25 @@ class SiteSQLStore implements SiteStore {
         */
        private $cacheTimeout = 3600;
 
+       /**
+        * @var BagOStuff
+        */
+       private $cache;
+
        /**
         * @since 1.21
         *
         * @param ORMTable|null $sitesTable
+        * @param BagOStuff|null $cache
         *
         * @return SiteStore
         */
-       public static function newInstance( ORMTable $sitesTable = null ) {
-               return new static( $sitesTable );
+       public static function newInstance( ORMTable $sitesTable = null, BagOStuff $cache = null ) {
+               if ( $cache === null ) {
+                       $cache = wfGetMainCache();
+               }
+
+               return new static( $cache, $sitesTable );
        }
 
        /**
@@ -67,13 +77,15 @@ class SiteSQLStore implements SiteStore {
         *
         * @since 1.21
         *
+        * @param BagOStuff $cache
         * @param ORMTable|null $sitesTable
         */
-       protected function __construct( ORMTable $sitesTable = null ) {
+       protected function __construct( BagOStuff $cache, ORMTable $sitesTable = null ) {
                if ( $sitesTable === null ) {
                        $sitesTable = $this->newSitesTable();
                }
 
+               $this->cache = $cache;
                $this->sitesTable = $sitesTable;
        }
 
@@ -92,7 +104,6 @@ class SiteSQLStore implements SiteStore {
         * @return string The cache key.
         */
        protected function getCacheKey() {
-               wfProfileIn( __METHOD__ );
 
                if ( $this->cacheKey === null ) {
                        $type = 'SiteList#' . SiteList::getSerialVersionId();
@@ -105,7 +116,6 @@ class SiteSQLStore implements SiteStore {
                        $this->cacheKey = wfMemcKey( "$source/$type" );
                }
 
-               wfProfileOut( __METHOD__ );
                return $this->cacheKey;
        }
 
@@ -119,12 +129,10 @@ class SiteSQLStore implements SiteStore {
         * @return SiteList
         */
        public function getSites( $source = 'cache' ) {
-               wfProfileIn( __METHOD__ );
 
                if ( $source === 'cache' ) {
                        if ( $this->sites === null ) {
-                               $cache = wfGetMainCache();
-                               $sites = $cache->get( $this->getCacheKey() );
+                               $sites = $this->cache->get( $this->getCacheKey() );
 
                                if ( is_object( $sites ) ) {
                                        $this->sites = $sites;
@@ -137,7 +145,6 @@ class SiteSQLStore implements SiteStore {
                        $this->loadSites();
                }
 
-               wfProfileOut( __METHOD__ );
                return $this->sites;
        }
 
@@ -151,7 +158,6 @@ class SiteSQLStore implements SiteStore {
         * @return Site
         */
        protected function siteFromRow( ORMRow $siteRow ) {
-               wfProfileIn( __METHOD__ );
 
                $site = Site::newForType( $siteRow->getField( 'type', Site::TYPE_UNKNOWN ) );
 
@@ -186,7 +192,6 @@ class SiteSQLStore implements SiteStore {
                        $site->setExtraConfig( $siteRow->getField( 'config' ) );
                }
 
-               wfProfileOut( __METHOD__ );
                return $site;
        }
 
@@ -229,7 +234,6 @@ class SiteSQLStore implements SiteStore {
         * @since 1.21
         */
        protected function loadSites() {
-               wfProfileIn( __METHOD__ );
 
                $this->sites = new SiteList();
 
@@ -257,10 +261,8 @@ class SiteSQLStore implements SiteStore {
                        }
                }
 
-               $cache = wfGetMainCache();
-               $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
+               $this->cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -274,11 +276,9 @@ class SiteSQLStore implements SiteStore {
         * @return Site|null
         */
        public function getSite( $globalId, $source = 'cache' ) {
-               wfProfileIn( __METHOD__ );
 
                $sites = $this->getSites( $source );
 
-               wfProfileOut( __METHOD__ );
                return $sites->hasSite( $globalId ) ? $sites->getSite( $globalId ) : null;
        }
 
@@ -305,10 +305,8 @@ class SiteSQLStore implements SiteStore {
         * @return bool Success indicator
         */
        public function saveSites( array $sites ) {
-               wfProfileIn( __METHOD__ );
 
                if ( empty( $sites ) ) {
-                       wfProfileOut( __METHOD__ );
                        return true;
                }
 
@@ -361,7 +359,6 @@ class SiteSQLStore implements SiteStore {
                // purge cache
                $this->reset();
 
-               wfProfileOut( __METHOD__ );
                return $success;
        }
 
@@ -372,13 +369,10 @@ class SiteSQLStore implements SiteStore {
         * @since 1.21
         */
        public function reset() {
-               wfProfileIn( __METHOD__ );
                // purge cache
-               $cache = wfGetMainCache();
-               $cache->delete( $this->getCacheKey() );
+               $this->cache->delete( $this->getCacheKey() );
                $this->sites = null;
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -389,7 +383,6 @@ class SiteSQLStore implements SiteStore {
         * @return bool Success
         */
        public function clear() {
-               wfProfileIn( __METHOD__ );
                $dbw = $this->sitesTable->getWriteDbConnection();
 
                $dbw->startAtomic( __METHOD__ );
@@ -399,7 +392,6 @@ class SiteSQLStore implements SiteStore {
 
                $this->reset();
 
-               wfProfileOut( __METHOD__ );
                return $ok;
        }