Merge "Fix wrong @return type hints in Language::tsTo… methods"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index dffc9d9..15691f2 100644 (file)
@@ -362,11 +362,28 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $list->initChangesListRows( $rows );
                $dbr->dataSeek( $rows, 0 );
 
+               if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
+                       && $user->getOption( 'shownumberswatching' )
+               ) {
+                       $watchedItemStore = WatchedItemStore::getDefaultInstance();
+               }
+
                $s = $list->beginRecentChangesList();
+               $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
                $counter = 1;
                foreach ( $rows as $obj ) {
                        # Make RC entry
                        $rc = RecentChange::newFromRow( $obj );
+
+                       # Skip CatWatch entries for hidden cats based on user preference
+                       if (
+                               $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
+                               !$userShowHiddenCats &&
+                               $rc->getParam( 'hidden-cat' )
+                       ) {
+                               continue;
+                       }
+
                        $rc->counter = $counter++;
 
                        if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
@@ -375,16 +392,9 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                $updated = false;
                        }
 
-                       if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
-                               && $user->getOption( 'shownumberswatching' )
-                       ) {
-                               $rc->numberofWatchingusers = $dbr->selectField( 'watchlist',
-                                       'COUNT(*)',
-                                       [
-                                               'wl_namespace' => $obj->rc_namespace,
-                                               'wl_title' => $obj->rc_title,
-                                       ],
-                                       __METHOD__ );
+                       if ( isset( $watchedItemStore ) ) {
+                               $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
+                               $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
                        } else {
                                $rc->numberofWatchingusers = 0;
                        }
@@ -569,8 +579,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $form = "";
                $user = $this->getUser();
 
-               $dbr = $this->getDB();
-               $numItems = $this->countItems( $dbr );
+               $numItems = $this->countItems();
                $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
 
                // Show watchlist header
@@ -630,18 +639,14 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        /**
-        * Count the number of items on a user's watchlist
+        * Count the number of paired items on a user's watchlist.
+        * The assumption made here is that when a subject page is watched a talk page is also watched.
+        * Hence the number of individual items is halved.
         *
-        * @param IDatabase $dbr A database connection
         * @return int
         */
-       protected function countItems( $dbr ) {
-               # Fetch the raw count
-               $rows = $dbr->select( 'watchlist', [ 'count' => 'COUNT(*)' ],
-                       [ 'wl_user' => $this->getUser()->getId() ], __METHOD__ );
-               $row = $dbr->fetchObject( $rows );
-               $count = $row->count;
-
+       protected function countItems() {
+               $count = WatchedItemStore::getDefaultInstance()->countWatchedItems( $this->getUser() );
                return floor( $count / 2 );
        }
 }