+ return ObjectCache::getMainWANInstance()->getWithSetCallback(
+ self::getCacheKey( $page->getTitle(), $page->getLatest() ),
+ function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
+ $title = $page->getTitle();
+ $id = $title->getArticleID();
+
+ $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
+ $result = array();
+
+ // Number of page watchers
+ $watchers = (int)$dbrWatchlist->selectField(
+ 'watchlist',
+ 'COUNT(*)',
+ array(
+ 'wl_namespace' => $title->getNamespace(),
+ 'wl_title' => $title->getDBkey(),
+ ),
+ $fname
+ );
+ $result['watchers'] = $watchers;
+
+ 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(*)',
+ array(
+ 'wl_namespace' => $title->getNamespace(),
+ 'wl_title' => $title->getDBkey(),
+ 'wl_notificationtimestamp >= ' . $dbrWatchlist->addQuotes( $threshold ) .
+ ' OR wl_notificationtimestamp IS NULL'
+ ),
+ $fname
+ );
+ $result['visitingWatchers'] = $visitingWatchers;
+ }