diff options
author | Catrope <roan.kattouw@gmail.com> | 2016-04-11 20:25:47 +0000 |
---|---|---|
committer | Catrope <roan.kattouw@gmail.com> | 2016-04-11 20:25:47 +0000 |
commit | deb22bced75964dc1d5b8783ab0f6a7e66ee945a (patch) | |
tree | 9e26fdcf659119e32dd566f675db7776fa485afa /includes/WatchedItemStore.php | |
parent | 99e8d45b50993113b26ced7c8bb91e44c7d908b1 (diff) | |
download | mediawikicore-deb22bced75964dc1d5b8783ab0f6a7e66ee945a.tar.gz mediawikicore-deb22bced75964dc1d5b8783ab0f6a7e66ee945a.zip |
Revert "Make WatchedItemStore use MediaWikiServices"
In order to cleanly revert "Allow reset of global services"
which breaks login.
This reverts commit 99e8d45b50993113b26ced7c8bb91e44c7d908b1.
Change-Id: Iae7f7b7b7083345dd50c313ee68e2e814f130f1a
Diffstat (limited to 'includes/WatchedItemStore.php')
-rw-r--r-- | includes/WatchedItemStore.php | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 603bacd1cd64..8ae7932be0b4 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -1,7 +1,6 @@ <?php use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; -use MediaWiki\MediaWikiServices; use Wikimedia\Assert\Assert; /** @@ -51,6 +50,11 @@ class WatchedItemStore implements StatsdAwareInterface { private $stats; /** + * @var self|null + */ + private static $instance; + + /** * @param LoadBalancer $loadBalancer * @param HashBagOStuff $cache */ @@ -121,11 +125,43 @@ class WatchedItemStore implements StatsdAwareInterface { } /** - * @deprecated use MediaWikiServices::getInstance()->getWatchedItemStore() + * Overrides the default instance of this class + * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. + * + * If this method is used it MUST also be called with null after a test to ensure a new + * default instance is created next time getDefaultInstance is called. + * + * @param WatchedItemStore|null $store + * + * @return ScopedCallback to reset the overridden value + * @throws MWException + */ + public static function overrideDefaultInstance( WatchedItemStore $store = null ) { + if ( !defined( 'MW_PHPUNIT_TEST' ) ) { + throw new MWException( + 'Cannot override ' . __CLASS__ . 'default instance in operation.' + ); + } + + $previousValue = self::$instance; + self::$instance = $store; + return new ScopedCallback( function() use ( $previousValue ) { + self::$instance = $previousValue; + } ); + } + + /** * @return self */ public static function getDefaultInstance() { - return MediaWikiServices::getInstance()->getWatchedItemStore(); + if ( !self::$instance ) { + self::$instance = new self( + wfGetLB(), + new HashBagOStuff( [ 'maxKeys' => 100 ] ) + ); + self::$instance->setStatsdDataFactory( RequestContext::getMain()->getStats() ); + } + return self::$instance; } private function getCacheKey( User $user, LinkTarget $target ) { |