Remove WatchedItemStore::getDefaultInstance
authoraddshore <addshorewiki@gmail.com>
Fri, 15 Apr 2016 16:29:05 +0000 (17:29 +0100)
committerAddshore <addshorewiki@gmail.com>
Fri, 6 May 2016 08:47:37 +0000 (08:47 +0000)
Change-Id: I0c7d706fabee8d1f6fcfbc4c568f375953de8058

14 files changed:
includes/MovePage.php
includes/Title.php
includes/WatchedItem.php
includes/WatchedItemStore.php
includes/actions/InfoAction.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryUserInfo.php
includes/mail/EmailNotification.php
includes/specials/SpecialEditWatchlist.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialWatchlist.php
includes/user/User.php
tests/phpunit/includes/WatchedItemStoreIntegrationTest.php
tests/phpunit/includes/WatchedItemStoreUnitTest.php

index b9af755..708dea1 100644 (file)
@@ -19,6 +19,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Handles the backend logic of moving a page from one title
  * to another.
@@ -369,7 +371,7 @@ class MovePage {
                $oldsnamespace = MWNamespace::getSubject( $this->oldTitle->getNamespace() );
                $newsnamespace = MWNamespace::getSubject( $this->newTitle->getNamespace() );
                if ( $oldsnamespace != $newsnamespace || $oldtitle != $newtitle ) {
-                       $store = WatchedItemStore::getDefaultInstance();
+                       $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                        $store->duplicateAllAssociatedEntries( $this->oldTitle, $this->newTitle );
                }
 
index 7887890..65b2d3a 100644 (file)
@@ -23,6 +23,8 @@
  */
 use MediaWiki\Linker\LinkTarget;
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Represents a title within MediaWiki.
  * Optionally may contain an interwiki designation or namespace.
@@ -4438,7 +4440,8 @@ class Title implements LinkTarget {
                        $this->mNotificationTimestamp = [];
                }
 
-               $watchedItem = WatchedItemStore::getDefaultInstance()->getWatchedItem( $user, $this );
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+               $watchedItem = $store->getWatchedItem( $user, $this );
                if ( $watchedItem ) {
                        $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp();
                } else {
index db6ce87..50c79dc 100644 (file)
@@ -18,6 +18,7 @@
  * @file
  * @ingroup Watchlist
  */
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Linker\LinkTarget;
 
 /**
@@ -118,7 +119,7 @@ class WatchedItem {
                        if ( $this->checkRights && !$this->user->isAllowed( 'viewmywatchlist' ) ) {
                                return false;
                        }
-                       $item = WatchedItemStore::getDefaultInstance()
+                       $item = MediaWikiServices::getInstance()->getWatchedItemStore()
                                ->loadWatchedItem( $this->user, $this->linkTarget );
                        if ( $item ) {
                                $this->notificationTimestamp = $item->getNotificationTimestamp();
@@ -163,7 +164,7 @@ class WatchedItem {
                if ( $this->checkRights && !$this->user->isAllowed( 'editmywatchlist' ) ) {
                        return;
                }
-               WatchedItemStore::getDefaultInstance()->resetNotificationTimestamp(
+               MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp(
                        $this->user,
                        $this->getTitle(),
                        $force,
@@ -194,7 +195,7 @@ class WatchedItem {
                        $targets[$userId][] = $watchedItem->getTitle()->getTalkPage();
                }
 
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $success = true;
                foreach ( $users as $userId => $user ) {
                        $success &= $store->addWatchBatchForUser( $user, $targets[$userId] );
@@ -240,7 +241,7 @@ class WatchedItem {
         */
        public static function duplicateEntries( Title $oldTitle, Title $newTitle ) {
                // wfDeprecated( __METHOD__, '1.27' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $store->duplicateAllAssociatedEntries( $oldTitle, $newTitle );
        }
 
index f3a076b..eb652ce 100644 (file)
@@ -121,14 +121,6 @@ class WatchedItemStore implements StatsdAwareInterface {
                } );
        }
 
-       /**
-        * @deprecated use MediaWikiServices::getInstance()->getWatchedItemStore()
-        * @return self
-        */
-       public static function getDefaultInstance() {
-               return MediaWikiServices::getInstance()->getWatchedItemStore();
-       }
-
        private function getCacheKey( User $user, LinkTarget $target ) {
                return $this->cache->makeKey(
                        (string)$target->getNamespace(),
index f7c30b7..b5f7ff2 100644 (file)
@@ -22,6 +22,8 @@
  * @ingroup Actions
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Displays information about a page.
  *
@@ -677,7 +679,7 @@ class InfoAction extends FormlessAction {
 
                                $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
 
-                               $watchedItemStore = WatchedItemStore::getDefaultInstance();
+                               $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
 
                                $result = [];
                                $result['watchers'] = $watchedItemStore->countWatchers( $title );
index b94f567..f5c49ad 100644 (file)
@@ -23,6 +23,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Linker\LinkTarget;
 
 /**
@@ -760,7 +761,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->watched = [];
                $this->notificationtimestamps = [];
 
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $timestamps = $store->getNotificationTimestampsBatch( $user, $this->everything );
 
                if ( $this->fld_watched ) {
@@ -800,7 +801,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $countOptions['minimumWatchers'] = $unwatchedPageThreshold;
                }
 
-               $this->watchers = WatchedItemStore::getDefaultInstance()->countWatchersMultiple(
+               $this->watchers = MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchersMultiple(
                        $this->everything,
                        $countOptions
                );
@@ -867,8 +868,8 @@ class ApiQueryInfo extends ApiQueryBase {
                                )
                        );
                }
-
-               $this->visitingwatchers = WatchedItemStore::getDefaultInstance()->countVisitingWatchersMultiple(
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+               $this->visitingwatchers = $store->countVisitingWatchersMultiple(
                        $titlesWithThresholds,
                        !$canUnwatchedpages ? $unwatchedPageThreshold : null
                );
index 0fc443a..d3cd0c4 100644 (file)
@@ -24,6 +24,8 @@
  * @file
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Query module to get information about the currently logged-in user
  *
@@ -225,7 +227,8 @@ class ApiQueryUserInfo extends ApiQueryBase {
                }
 
                if ( isset( $this->prop['unreadcount'] ) ) {
-                       $unreadNotifications = WatchedItemStore::getDefaultInstance()->countUnreadNotifications(
+                       $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+                       $unreadNotifications = $store->countUnreadNotifications(
                                $user,
                                self::WL_UNREAD_LIMIT
                        );
index 664c111..1d0bdf6 100644 (file)
@@ -25,6 +25,8 @@
  */
 use MediaWiki\Linker\LinkTarget;
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * This module processes the email notifications when the current page is
  * changed. It looks up the table watchlist to find out which users are watching
@@ -92,7 +94,7 @@ class EmailNotification {
                if ( !$config->get( 'EnotifWatchlist' ) && !$config->get( 'ShowUpdatedMarker' ) ) {
                        return [];
                }
-               return WatchedItemStore::getDefaultInstance()->updateNotificationTimestamp(
+               return MediaWikiServices::getInstance()->getWatchedItemStore()->updateNotificationTimestamp(
                        $editor,
                        $linkTarget,
                        $timestamp
@@ -125,7 +127,7 @@ class EmailNotification {
                $config = RequestContext::getMain()->getConfig();
                $watchers = [];
                if ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) {
-                       $watchers = WatchedItemStore::getDefaultInstance()->updateNotificationTimestamp(
+                       $watchers = MediaWikiServices::getInstance()->getWatchedItemStore()->updateNotificationTimestamp(
                                $editor,
                                $title,
                                $timestamp
index f2fa921..627dd2c 100644 (file)
@@ -27,6 +27,8 @@ use MediaWiki\Linker\LinkTarget;
  * @ingroup Watchlist
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Provides the UI through which users can perform editing
  * operations on their watchlist
@@ -325,7 +327,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
        private function getWatchlist() {
                $list = [];
 
-               $watchedItems = WatchedItemStore::getDefaultInstance()->getWatchedItemsForUser(
+               $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()->getWatchedItemsForUser(
                        $this->getUser(),
                        [ 'forWrite' => $this->getRequest()->wasPosted() ]
                );
@@ -366,7 +368,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
        protected function getWatchlistInfo() {
                $titles = [];
 
-               $watchedItems = WatchedItemStore::getDefaultInstance()
+               $watchedItems = MediaWikiServices::getInstance()->getWatchedItemStore()
                        ->getWatchedItemsForUser( $this->getUser(), [ 'sort' => WatchedItemStore::SORT_ASC ] );
 
                $lb = new LinkBatch();
@@ -421,7 +423,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                }
 
                $user = $this->getUser();
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
 
                foreach ( $this->badItems as $row ) {
                        list( $title, $namespace, $dbKey ) = $row;
@@ -472,7 +474,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                        $expandedTargets[] = new TitleValue( MWNamespace::getTalk( $ns ), $dbKey );
                }
 
-               WatchedItemStore::getDefaultInstance()->addWatchBatchForUser(
+               MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser(
                        $this->getUser(),
                        $expandedTargets
                );
@@ -487,7 +489,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
         * @param array $titles Array of strings, or Title objects
         */
        private function unwatchTitles( $titles ) {
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
 
                foreach ( $titles as $title ) {
                        if ( !$title instanceof Title ) {
index b93fb4e..b6398cb 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A special page that lists last changes made to the wiki
  *
@@ -355,7 +357,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                        if ( $showWatcherCount && $obj->rc_namespace >= 0 ) {
                                if ( !isset( $watcherCache[$obj->rc_namespace][$obj->rc_title] ) ) {
                                        $watcherCache[$obj->rc_namespace][$obj->rc_title] =
-                                               WatchedItemStore::getDefaultInstance()->countWatchers(
+                                               MediaWikiServices::getInstance()->getWatchedItemStore()->countWatchers(
                                                        new TitleValue( (int)$obj->rc_namespace, $obj->rc_title )
                                                );
                                }
index 15691f2..58cde7e 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * A special page that lists last changes made to the wiki,
  * limited to user-defined list of titles.
@@ -365,7 +367,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
                        && $user->getOption( 'shownumberswatching' )
                ) {
-                       $watchedItemStore = WatchedItemStore::getDefaultInstance();
+                       $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
                }
 
                $s = $list->beginRecentChangesList();
@@ -646,7 +648,8 @@ class SpecialWatchlist extends ChangesListSpecialPage {
         * @return int
         */
        protected function countItems() {
-               $count = WatchedItemStore::getDefaultInstance()->countWatchedItems( $this->getUser() );
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+               $count = $store->countWatchedItems( $this->getUser() );
                return floor( $count / 2 );
        }
 }
index 7c32c3b..44d2b21 100644 (file)
@@ -3500,7 +3500,7 @@ class User implements IDBAccessObject {
         */
        public function isWatched( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
                if ( $title->isWatchable() && ( !$checkRights || $this->isAllowed( 'viewmywatchlist' ) ) ) {
-                       return WatchedItemStore::getDefaultInstance()->isWatched( $this, $title );
+                       return MediaWikiServices::getInstance()->getWatchedItemStore()->isWatched( $this, $title );
                }
                return false;
        }
@@ -3514,7 +3514,7 @@ class User implements IDBAccessObject {
         */
        public function addWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
                if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) {
-                       WatchedItemStore::getDefaultInstance()->addWatchBatchForUser(
+                       MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser(
                                $this,
                                [ $title->getSubjectPage(), $title->getTalkPage() ]
                        );
@@ -3531,8 +3531,9 @@ class User implements IDBAccessObject {
         */
        public function removeWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) {
                if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) {
-                       WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getSubjectPage() );
-                       WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getTalkPage() );
+                       $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+                       $store->removeWatch( $this, $title->getSubjectPage() );
+                       $store->removeWatch( $this, $title->getTalkPage() );
                }
                $this->invalidateCache();
        }
@@ -3601,7 +3602,7 @@ class User implements IDBAccessObject {
                        $force = 'force';
                }
 
-               WatchedItemStore::getDefaultInstance()
+               MediaWikiServices::getInstance()->getWatchedItemStore()
                        ->resetNotificationTimestamp( $this, $title, $force, $oldid );
        }
 
index 5b2873a..f34af61 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @author Addshore
  *
@@ -22,7 +24,7 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
        public function testWatchAndUnWatchItem() {
                $user = $this->getUser();
                $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                // Cleanup after previous tests
                $store->removeWatch( $user, $title );
                $initialWatchers = $store->countWatchers( $title );
@@ -108,7 +110,7 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                $user = $this->getUser();
                $otherUser = ( new TestUser( 'WatchedItemStoreIntegrationTestUser_otherUser' ) )->getUser();
                $title = Title::newFromText( 'WatchedItemStoreIntegrationTestPage' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $store->addWatch( $user, $title );
                $this->assertNull( $store->loadWatchedItem( $user, $title )->getNotificationTimestamp() );
                $initialVisitingWatchers = $store->countVisitingWatchers( $title, '20150202020202' );
@@ -176,7 +178,7 @@ class WatchedItemStoreIntegrationTest extends MediaWikiTestCase {
                $user = $this->getUser();
                $titleOld = Title::newFromText( 'WatchedItemStoreIntegrationTestPageOld' );
                $titleNew = Title::newFromText( 'WatchedItemStoreIntegrationTestPageNew' );
-               $store = WatchedItemStore::getDefaultInstance();
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
                $store->addWatch( $user, $titleOld->getSubjectPage() );
                $store->addWatch( $user, $titleOld->getTalkPage() );
                // Cleanup after previous tests
index 108c4c5..6c4a6f0 100644 (file)
@@ -94,12 +94,6 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase {
                );
        }
 
-       public function testGetDefaultInstance() {
-               $instanceOne = WatchedItemStore::getDefaultInstance();
-               $instanceTwo = WatchedItemStore::getDefaultInstance();
-               $this->assertSame( $instanceOne, $instanceTwo );
-       }
-
        public function testCountWatchedItems() {
                $user = $this->getMockNonAnonUserWithId( 1 );