From 65b0335134db11d2afaeff05b940b0f23f731269 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 14 Apr 2015 18:06:04 -0700 Subject: [PATCH] Removed some code duplication in Title::getNotificationTimestamp Change-Id: I02114258448c1dec894e51c2d4c84cb2517eccb7 --- includes/Title.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 80cddd5ef4..9d5321742f 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4410,34 +4410,28 @@ class Title { */ public function getNotificationTimestamp( $user = null ) { global $wgUser, $wgShowUpdatedMarker; + // Assume current user if none given if ( !$user ) { $user = $wgUser; } // Check cache first $uid = $user->getId(); + if ( !$uid || !$wgShowUpdatedMarker ) { + return false; + } // avoid isset here, as it'll return false for null entries if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) { return $this->mNotificationTimestamp[$uid]; } - if ( !$uid || !$wgShowUpdatedMarker || !$user->isAllowed( 'viewmywatchlist' ) ) { - $this->mNotificationTimestamp[$uid] = false; - return $this->mNotificationTimestamp[$uid]; - } // Don't cache too much! if ( count( $this->mNotificationTimestamp ) >= self::CACHE_MAX ) { $this->mNotificationTimestamp = array(); } - $dbr = wfGetDB( DB_SLAVE ); - $this->mNotificationTimestamp[$uid] = $dbr->selectField( 'watchlist', - 'wl_notificationtimestamp', - array( - 'wl_user' => $user->getId(), - 'wl_namespace' => $this->getNamespace(), - 'wl_title' => $this->getDBkey(), - ), - __METHOD__ - ); + + $watchedItem = WatchedItem::fromUserTitle( $user, $this ); + $this->mNotificationTimestamp[$uid] = $watchedItem->getNotificationTimestamp(); + return $this->mNotificationTimestamp[$uid]; } -- 2.20.1