From 02217b3d17f167cafe70a836a55f21627a89b8e0 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sat, 17 Nov 2012 15:26:01 +0100 Subject: [PATCH] cleanup WatchedItem class * removed $id, $ns, $ti which were set on construction and replace them with meaningful accessor getUserId(), getTitleNs and getTitleDBkey() * removed a commented out hack from September 2004 Change-Id: Iaa9e851516e0522492b0452430c7583fe3526ffc --- includes/WatchedItem.php | 61 ++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php index 932af1692e..ffdc285481 100644 --- a/includes/WatchedItem.php +++ b/includes/WatchedItem.php @@ -27,7 +27,7 @@ * @ingroup Watchlist */ class WatchedItem { - var $mTitle, $mUser, $id, $ns, $ti; + var $mTitle, $mUser; private $loaded = false, $watched, $timestamp; /** @@ -40,17 +40,32 @@ class WatchedItem { $wl = new WatchedItem; $wl->mUser = $user; $wl->mTitle = $title; - $wl->id = $user->getId(); - # Patch (also) for email notification on page changes T.Gries/M.Arndt 11.09.2004 - # TG patch: here we do not consider pages and their talk pages equivalent - why should we ? - # The change results in talk-pages not automatically included in watchlists, when their parent page is included - # $wl->ns = $title->getNamespace() & ~1; - $wl->ns = $title->getNamespace(); - $wl->ti = $title->getDBkey(); return $wl; } + /** + * Title being watched + * @return Title + */ + protected function getTitle() { + return $this->mTitle; + } + + /** Helper to retrieve the title namespace */ + protected function getTitleNs() { + return $this->getTitle()->getNamespace(); + } + + /** Helper to retrieve the title DBkey */ + protected function getTitleDBkey() { + return $this->getTitle()->getDBkey(); + } + /** Helper to retrieve the user id */ + protected function getUserId() { + return $this->mUser->getId(); + } + /** * Return an array of conditions to select or update the appropriate database * row. @@ -58,7 +73,11 @@ class WatchedItem { * @return array */ private function dbCond() { - return array( 'wl_user' => $this->id, 'wl_namespace' => $this->ns, 'wl_title' => $this->ti ); + return array( + 'wl_user' => $this->getUserId(), + 'wl_namespace' => $this->getTitleNs(), + 'wl_title' => $this->getTitleDBkey(), + ); } /** @@ -144,9 +163,9 @@ class WatchedItem { $dbw = wfGetDB( DB_MASTER ); $dbw->insert( 'watchlist', array( - 'wl_user' => $this->id, - 'wl_namespace' => MWNamespace::getSubject($this->ns), - 'wl_title' => $this->ti, + 'wl_user' => $this->getUserId(), + 'wl_namespace' => MWNamespace::getSubject($this->getTitleNs()), + 'wl_title' => $this->getTitleDBkey(), 'wl_notificationtimestamp' => null ), __METHOD__, 'IGNORE' ); @@ -154,9 +173,9 @@ class WatchedItem { // namespace:page and namespace_talk:page need separate entries: $dbw->insert( 'watchlist', array( - 'wl_user' => $this->id, - 'wl_namespace' => MWNamespace::getTalk($this->ns), - 'wl_title' => $this->ti, + 'wl_user' => $this->getUserId(), + 'wl_namespace' => MWNamespace::getTalk($this->getTitleNs()), + 'wl_title' => $this->getTitleDBkey(), 'wl_notificationtimestamp' => null ), __METHOD__, 'IGNORE' ); @@ -177,9 +196,9 @@ class WatchedItem { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'watchlist', array( - 'wl_user' => $this->id, - 'wl_namespace' => MWNamespace::getSubject($this->ns), - 'wl_title' => $this->ti + 'wl_user' => $this->getUserId(), + 'wl_namespace' => MWNamespace::getSubject($this->getTitleNs()), + 'wl_title' => $this->getTitleDBkey(), ), __METHOD__ ); if ( $dbw->affectedRows() ) { @@ -192,9 +211,9 @@ class WatchedItem { # entries: clear them $dbw->delete( 'watchlist', array( - 'wl_user' => $this->id, - 'wl_namespace' => MWNamespace::getTalk($this->ns), - 'wl_title' => $this->ti + 'wl_user' => $this->getUserId(), + 'wl_namespace' => MWNamespace::getTalk($this->getTitleNs()), + 'wl_title' => $this->getTitleDBkey(), ), __METHOD__ ); -- 2.20.1