13 * Create a WatchedItem object with the given user and title
17 static function fromUserTitle( $user, $title ) {
18 $wl = new WatchedItem
;
21 $wl->id
= $user->getId();
22 # Patch (also) for email notification on page changes T.Gries/M.Arndt 11.09.2004
23 # TG patch: here we do not consider pages and their talk pages equivalent - why should we ?
24 # The change results in talk-pages not automatically included in watchlists, when their parent page is included
25 # $wl->ns = $title->getNamespace() & ~1;
26 $wl->ns
= $title->getNamespace();
28 $wl->ti
= $title->getDBkey();
33 * Is mTitle being watched by mUser?
35 function isWatched() {
36 # Pages and their talk pages are considered equivalent for watching;
37 # remember that talk namespaces are numbered as page namespace+1.
38 $fname = 'WatchedItem::isWatched';
40 $dbr = wfGetDB( DB_SLAVE
);
41 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
42 'wl_title' => $this->ti
), $fname );
43 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
51 $fname = 'WatchedItem::addWatch';
52 wfProfileIn( $fname );
54 // Use INSERT IGNORE to avoid overwriting the notification timestamp
55 // if there's already an entry for this page
56 $dbw = wfGetDB( DB_MASTER
);
57 $dbw->insert( 'watchlist',
59 'wl_user' => $this->id
,
60 'wl_namespace' => ($this->ns
& ~
1),
61 'wl_title' => $this->ti
,
62 'wl_notificationtimestamp' => NULL
63 ), $fname, 'IGNORE' );
65 // Every single watched page needs now to be listed in watchlist;
66 // namespace:page and namespace_talk:page need separate entries:
67 $dbw->insert( 'watchlist',
69 'wl_user' => $this->id
,
70 'wl_namespace' => ($this->ns |
1 ),
71 'wl_title' => $this->ti
,
72 'wl_notificationtimestamp' => NULL
73 ), $fname, 'IGNORE' );
75 wfProfileOut( $fname );
79 function removeWatch() {
80 $fname = 'WatchedItem::removeWatch';
83 $dbw = wfGetDB( DB_MASTER
);
84 $dbw->delete( 'watchlist',
86 'wl_user' => $this->id
,
87 'wl_namespace' => ($this->ns
& ~
1),
88 'wl_title' => $this->ti
91 if ( $dbw->affectedRows() ) {
95 # the following code compensates the new behaviour, introduced by the
96 # enotif patch, that every single watched page needs now to be listed
97 # in watchlist namespace:page and namespace_talk:page had separate
99 $dbw->delete( 'watchlist',
101 'wl_user' => $this->id
,
102 'wl_namespace' => ($this->ns |
1),
103 'wl_title' => $this->ti
107 if ( $dbw->affectedRows() ) {
114 * Check if the given title already is watched by the user, and if so
115 * add watches on a new title. To be used for page renames and such.
117 * @param Title $ot Page title to duplicate entries from, if present
118 * @param Title $nt Page title to add watches on
120 static function duplicateEntries( $ot, $nt ) {
121 WatchedItem
::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
122 WatchedItem
::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
125 private static function doDuplicateEntries( $ot, $nt ) {
126 $fname = "WatchedItem::duplicateEntries";
127 $oldnamespace = $ot->getNamespace();
128 $newnamespace = $nt->getNamespace();
129 $oldtitle = $ot->getDBkey();
130 $newtitle = $nt->getDBkey();
132 $dbw = wfGetDB( DB_MASTER
);
133 $res = $dbw->select( 'watchlist', 'wl_user',
134 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
137 # Construct array to replace into the watchlist
139 while ( $s = $dbw->fetchObject( $res ) ) {
141 'wl_user' => $s->wl_user
,
142 'wl_namespace' => $newnamespace,
143 'wl_title' => $newtitle
146 $dbw->freeResult( $res );
148 if( empty( $values ) ) {
154 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
155 # some other DBMSes, mostly due to poor simulation by us
156 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );