14 * Create a WatchedItem object with the given user and title
18 static function fromUserTitle( $user, $title ) {
19 $wl = new WatchedItem
;
22 $wl->id
= $user->getId();
23 # Patch (also) for email notification on page changes T.Gries/M.Arndt 11.09.2004
24 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
25 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
26 # $wl->ns = $title->getNamespace() & ~1;
27 $wl->ns
= $title->getNamespace();
29 $wl->ti
= $title->getDBkey();
34 * Is mTitle being watched by mUser?
36 function isWatched() {
37 # Pages and their talk pages are considered equivalent for watching;
38 # remember that talk namespaces are numbered as page namespace+1.
39 $fname = 'WatchedItem::isWatched';
41 $dbr = wfGetDB( DB_SLAVE
);
42 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
43 'wl_title' => $this->ti
), $fname );
44 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
52 $fname = 'WatchedItem::addWatch';
53 wfProfileIn( $fname );
55 // Use INSERT IGNORE to avoid overwriting the notification timestamp
56 // if there's already an entry for this page
57 $dbw = wfGetDB( DB_MASTER
);
58 $dbw->insert( 'watchlist',
60 'wl_user' => $this->id
,
61 'wl_namespace' => ($this->ns
& ~
1),
62 'wl_title' => $this->ti
,
63 'wl_notificationtimestamp' => NULL
64 ), $fname, 'IGNORE' );
66 // Every single watched page needs now to be listed in watchlist;
67 // namespace:page and namespace_talk:page need separate entries:
68 $dbw->insert( 'watchlist',
70 'wl_user' => $this->id
,
71 'wl_namespace' => ($this->ns |
1 ),
72 'wl_title' => $this->ti
,
73 'wl_notificationtimestamp' => NULL
74 ), $fname, 'IGNORE' );
76 wfProfileOut( $fname );
80 function removeWatch() {
81 $fname = 'WatchedItem::removeWatch';
84 $dbw = wfGetDB( DB_MASTER
);
85 $dbw->delete( 'watchlist',
87 'wl_user' => $this->id
,
88 'wl_namespace' => ($this->ns
& ~
1),
89 'wl_title' => $this->ti
92 if ( $dbw->affectedRows() ) {
96 # the following code compensates the new behaviour, introduced by the
97 # enotif patch, that every single watched page needs now to be listed
98 # in watchlist namespace:page and namespace_talk:page had separate
100 $dbw->delete( 'watchlist',
102 'wl_user' => $this->id
,
103 'wl_namespace' => ($this->ns |
1),
104 'wl_title' => $this->ti
108 if ( $dbw->affectedRows() ) {
115 * Check if the given title already is watched by the user, and if so
116 * add watches on a new title. To be used for page renames and such.
118 * @param $ot Title: page title to duplicate entries from, if present
119 * @param $nt Title: page title to add watches on
121 static function duplicateEntries( $ot, $nt ) {
122 WatchedItem
::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
123 WatchedItem
::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
126 private static function doDuplicateEntries( $ot, $nt ) {
127 $fname = "WatchedItem::duplicateEntries";
128 $oldnamespace = $ot->getNamespace();
129 $newnamespace = $nt->getNamespace();
130 $oldtitle = $ot->getDBkey();
131 $newtitle = $nt->getDBkey();
133 $dbw = wfGetDB( DB_MASTER
);
134 $res = $dbw->select( 'watchlist', 'wl_user',
135 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
138 # Construct array to replace into the watchlist
140 while ( $s = $dbw->fetchObject( $res ) ) {
142 'wl_user' => $s->wl_user
,
143 'wl_namespace' => $newnamespace,
144 'wl_title' => $newtitle
147 $dbw->freeResult( $res );
149 if( empty( $values ) ) {
155 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
156 # some other DBMSes, mostly due to poor simulation by us
157 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );