From: addshore Date: Fri, 15 Apr 2016 16:29:05 +0000 (+0100) Subject: Remove WatchedItemStore::getDefaultInstance X-Git-Tag: 1.31.0-rc.0~7077 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=818984e5cb34502995be1559654bd72bef47f6fe;p=lhc%2Fweb%2Fwiklou.git Remove WatchedItemStore::getDefaultInstance Change-Id: I0c7d706fabee8d1f6fcfbc4c568f375953de8058 --- diff --git a/includes/MovePage.php b/includes/MovePage.php index b9af755325..708dea1fc9 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -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 ); } diff --git a/includes/Title.php b/includes/Title.php index 7887890474..65b2d3a2f2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 { diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index db6ce8744a..50c79dce53 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -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 ); } diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index f3a076b52c..eb652ce118 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -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(), diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index f7c30b71af..b5f7ff2536 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -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 ); diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index b94f5674f4..f5c49ad04f 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -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 ); diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index 0fc443ab21..d3cd0c48c4 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -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 ); diff --git a/includes/mail/EmailNotification.php b/includes/mail/EmailNotification.php index 664c1116eb..1d0bdf6d77 100644 --- a/includes/mail/EmailNotification.php +++ b/includes/mail/EmailNotification.php @@ -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 diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index f2fa9214ee..627dd2cfa9 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -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 ) { diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index b93fb4e2af..b6398cb567 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -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 ) ); } diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 15691f2c46..58cde7e55a 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -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 ); } } diff --git a/includes/user/User.php b/includes/user/User.php index 7c32c3b5a2..44d2b21c58 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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 ); } diff --git a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php index 5b2873a4fc..f34af6113d 100644 --- a/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php +++ b/tests/phpunit/includes/WatchedItemStoreIntegrationTest.php @@ -1,5 +1,7 @@ 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 diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/WatchedItemStoreUnitTest.php index 108c4c5fb7..6c4a6f09c6 100644 --- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php @@ -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 );