summaryrefslogtreecommitdiff
path: root/includes/WatchedItem.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/WatchedItem.php')
-rw-r--r--includes/WatchedItem.php75
1 files changed, 47 insertions, 28 deletions
diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php
index 932af169..5ac92f73 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,25 +40,44 @@ 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.
*
* @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(),
+ );
}
/**
@@ -143,22 +162,22 @@ class WatchedItem {
// if there's already an entry for this page
$dbw = wfGetDB( DB_MASTER );
$dbw->insert( 'watchlist',
- array(
- 'wl_user' => $this->id,
- 'wl_namespace' => MWNamespace::getSubject($this->ns),
- 'wl_title' => $this->ti,
- 'wl_notificationtimestamp' => null
- ), __METHOD__, 'IGNORE' );
+ array(
+ 'wl_user' => $this->getUserId(),
+ 'wl_namespace' => MWNamespace::getSubject( $this->getTitleNs() ),
+ 'wl_title' => $this->getTitleDBkey(),
+ 'wl_notificationtimestamp' => null
+ ), __METHOD__, 'IGNORE' );
// Every single watched page needs now to be listed in watchlist;
// 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_notificationtimestamp' => null
- ), __METHOD__, 'IGNORE' );
+ array(
+ 'wl_user' => $this->getUserId(),
+ 'wl_namespace' => MWNamespace::getTalk( $this->getTitleNs() ),
+ 'wl_title' => $this->getTitleDBkey(),
+ 'wl_notificationtimestamp' => null
+ ), __METHOD__, 'IGNORE' );
$this->watched = true;
@@ -177,24 +196,24 @@ 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() ) {
$success = true;
}
- # the following code compensates the new behaviour, introduced by the
+ # the following code compensates the new behavior, introduced by the
# enotif patch, that every single watched page needs now to be listed
# in watchlist namespace:page and namespace_talk:page had separate
# 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__
);