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
39 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
43 * Is mTitle being watched by mUser?
45 function isWatched() {
46 # Pages and their talk pages are considered equivalent for watching;
47 # remember that talk namespaces are numbered as page namespace+1.
49 $fname = 'WatchedItem::isWatched';
51 $key = $this->watchKey();
52 $iswatched = $wgMemc->get( $key );
53 if( is_integer( $iswatched ) ) return $iswatched;
55 $dbr =& wfGetDB( DB_SLAVE
);
56 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
57 'wl_title' => $this->ti
), $fname );
58 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
59 $wgMemc->set( $key, $iswatched );
67 $fname = 'WatchedItem::addWatch';
68 wfProfileIn( $fname );
69 # REPLACE instead of INSERT because occasionally someone
70 # accidentally reloads a watch-add operation.
71 $dbw =& wfGetDB( DB_MASTER
);
72 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
74 'wl_user' => $this->id
,
75 'wl_namespace' => ($this->ns
& ~
1),
76 'wl_title' => $this->ti
,
77 'wl_notificationtimestamp' => NULL
80 # the following code compensates the new behaviour, introduced by the enotif patch,
81 # that every single watched page needs now to be listed in watchlist
82 # namespace:page and namespace_talk:page need separate entries: create them
83 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
85 'wl_user' => $this->id
,
86 'wl_namespace' => ($this->ns |
1 ),
87 'wl_title' => $this->ti
,
88 'wl_notificationtimestamp' => NULL
92 $wgMemc->set( $this->watchkey(), 1 );
93 wfProfileOut( $fname );
97 function removeWatch() {
99 $fname = 'WatchedItem::removeWatch';
102 $dbw =& wfGetDB( DB_MASTER
);
103 $dbw->delete( 'watchlist',
105 'wl_user' => $this->id
,
106 'wl_namespace' => ($this->ns
& ~
1),
107 'wl_title' => $this->ti
110 if ( $dbw->affectedRows() ) {
114 # the following code compensates the new behaviour, introduced by the
115 # enotif patch, that every single watched page needs now to be listed
116 # in watchlist namespace:page and namespace_talk:page had separate
117 # entries: clear them
118 $dbw->delete( 'watchlist',
120 'wl_user' => $this->id
,
121 'wl_namespace' => ($this->ns |
1),
122 'wl_title' => $this->ti
126 if ( $dbw->affectedRows() ) {
130 $wgMemc->set( $this->watchkey(), 0 );
138 function duplicateEntries( $ot, $nt ) {
139 $fname = "WatchedItem::duplicateEntries";
140 global $wgMemc, $wgDBname;
141 $oldnamespace = $ot->getNamespace() & ~
1;
142 $newnamespace = $nt->getNamespace() & ~
1;
143 $oldtitle = $ot->getDBkey();
144 $newtitle = $nt->getDBkey();
146 $dbw =& wfGetDB( DB_MASTER
);
147 $watchlist = $dbw->tableName( 'watchlist' );
149 $res = $dbw->select( 'watchlist', 'wl_user',
150 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
153 # Construct array to replace into the watchlist
155 while ( $s = $dbw->fetchObject( $res ) ) {
157 'wl_user' => $s->wl_user
,
158 'wl_namespace' => $newnamespace,
159 'wl_title' => $newtitle
162 $dbw->freeResult( $res );
165 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
166 # some other DBMSes, mostly due to poor simulation by us
167 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );