Move countVisitingWatchers to WatchedItemStore
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index 87d269a..4596e41 100644 (file)
@@ -677,39 +677,17 @@ class InfoAction extends FormlessAction {
 
                                $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
 
-                               $result = [];
+                               $watchedItemStore = WatchedItemStore::getDefaultInstance();
 
-                               // Number of page watchers
-                               $watchers = (int)$dbrWatchlist->selectField(
-                                       'watchlist',
-                                       'COUNT(*)',
-                                       [
-                                               'wl_namespace' => $title->getNamespace(),
-                                               'wl_title' => $title->getDBkey(),
-                                       ],
-                                       $fname
-                               );
-                               $result['watchers'] = $watchers;
+                               $result = [];
+                               $result['watchers'] = $watchedItemStore->countWatchers( $title );
 
                                if ( $config->get( 'ShowUpdatedMarker' ) ) {
-                                       // Threshold: last visited about 26 weeks before latest edit
                                        $updated = wfTimestamp( TS_UNIX, $page->getTimestamp() );
-                                       $age = $config->get( 'WatchersMaxAge' );
-                                       $threshold = $dbrWatchlist->timestamp( $updated - $age );
-                                       // Number of page watchers who also visited a "recent" edit
-                                       $visitingWatchers = (int)$dbrWatchlist->selectField(
-                                               'watchlist',
-                                               'COUNT(*)',
-                                               [
-                                                       'wl_namespace' => $title->getNamespace(),
-                                                       'wl_title' => $title->getDBkey(),
-                                                       'wl_notificationtimestamp >= ' .
-                                                               $dbrWatchlist->addQuotes( $threshold ) .
-                                                               ' OR wl_notificationtimestamp IS NULL'
-                                               ],
-                                               $fname
+                                       $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers(
+                                               $title,
+                                               $updated - $config->get( 'WatchersMaxAge' )
                                        );
-                                       $result['visitingWatchers'] = $visitingWatchers;
                                }
 
                                // Total number of edits