15 * Create a WatchedItem object with the given user and title
19 function &fromUserTitle( &$user, &$title ) {
20 $wl = new WatchedItem
;
22 $wl->mTitle
=& $title;
23 $wl->id
= $user->getId();
24 # Patch (also) for email notification on page changes T.Gries/M.Arndt 11.09.2004
25 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
26 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
27 # $wl->ns = $title->getNamespace() & ~1;
28 $wl->ns
= $title->getNamespace();
30 $wl->ti
= $title->getDBkey();
35 * Returns the memcached key for this item
38 return wfMemcKey( 'watchlist', 'user', $this->id
, 'page', $this->ns
, $this->ti
);
42 * Is mTitle being watched by mUser?
44 function isWatched() {
45 # Pages and their talk pages are considered equivalent for watching;
46 # remember that talk namespaces are numbered as page namespace+1.
48 $fname = 'WatchedItem::isWatched';
50 $key = $this->watchKey();
51 $iswatched = $wgMemc->get( $key );
52 if( is_integer( $iswatched ) ) return $iswatched;
54 $dbr =& wfGetDB( DB_SLAVE
);
55 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
56 'wl_title' => $this->ti
), $fname );
57 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
58 $wgMemc->set( $key, $iswatched );
66 $fname = 'WatchedItem::addWatch';
67 wfProfileIn( $fname );
69 // Use INSERT IGNORE to avoid overwriting the notification timestamp
70 // if there's already an entry for this page
71 $dbw =& wfGetDB( DB_MASTER
);
72 $dbw->insert( 'watchlist',
74 'wl_user' => $this->id
,
75 'wl_namespace' => ($this->ns
& ~
1),
76 'wl_title' => $this->ti
,
77 'wl_notificationtimestamp' => NULL
78 ), $fname, 'IGNORE' );
80 // Every single watched page needs now to be listed in watchlist;
81 // namespace:page and namespace_talk:page need separate entries:
82 $dbw->insert( 'watchlist',
84 'wl_user' => $this->id
,
85 'wl_namespace' => ($this->ns |
1 ),
86 'wl_title' => $this->ti
,
87 'wl_notificationtimestamp' => NULL
88 ), $fname, 'IGNORE' );
91 $wgMemc->set( $this->watchkey(), 1 );
92 wfProfileOut( $fname );
96 function removeWatch() {
98 $fname = 'WatchedItem::removeWatch';
101 $dbw =& wfGetDB( DB_MASTER
);
102 $dbw->delete( 'watchlist',
104 'wl_user' => $this->id
,
105 'wl_namespace' => ($this->ns
& ~
1),
106 'wl_title' => $this->ti
109 if ( $dbw->affectedRows() ) {
113 # the following code compensates the new behaviour, introduced by the
114 # enotif patch, that every single watched page needs now to be listed
115 # in watchlist namespace:page and namespace_talk:page had separate
116 # entries: clear them
117 $dbw->delete( 'watchlist',
119 'wl_user' => $this->id
,
120 'wl_namespace' => ($this->ns |
1),
121 'wl_title' => $this->ti
125 if ( $dbw->affectedRows() ) {
129 $wgMemc->set( $this->watchkey(), 0 );
135 * Check if the given title already is watched by the user, and if so
136 * add watches on a new title. To be used for page renames and such.
138 * @param Title $ot Page title to duplicate entries from, if present
139 * @param Title $nt Page title to add watches on
142 function duplicateEntries( $ot, $nt ) {
143 WatchedItem
::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
144 WatchedItem
::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
151 function doDuplicateEntries( $ot, $nt ) {
152 $fname = "WatchedItem::duplicateEntries";
153 $oldnamespace = $ot->getNamespace();
154 $newnamespace = $nt->getNamespace();
155 $oldtitle = $ot->getDBkey();
156 $newtitle = $nt->getDBkey();
158 $dbw =& wfGetDB( DB_MASTER
);
159 $res = $dbw->select( 'watchlist', 'wl_user',
160 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
163 # Construct array to replace into the watchlist
165 while ( $s = $dbw->fetchObject( $res ) ) {
167 'wl_user' => $s->wl_user
,
168 'wl_namespace' => $newnamespace,
169 'wl_title' => $newtitle
172 $dbw->freeResult( $res );
174 if( empty( $values ) ) {
180 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
181 # some other DBMSes, mostly due to poor simulation by us
182 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );