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 * Is mTitle being watched by mUser?
37 function isWatched() {
38 # Pages and their talk pages are considered equivalent for watching;
39 # remember that talk namespaces are numbered as page namespace+1.
40 $fname = 'WatchedItem::isWatched';
42 $dbr =& wfGetDB( DB_SLAVE
);
43 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
44 'wl_title' => $this->ti
), $fname );
45 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
53 $fname = 'WatchedItem::addWatch';
54 wfProfileIn( $fname );
56 // Use INSERT IGNORE to avoid overwriting the notification timestamp
57 // if there's already an entry for this page
58 $dbw =& wfGetDB( DB_MASTER
);
59 $dbw->insert( 'watchlist',
61 'wl_user' => $this->id
,
62 'wl_namespace' => ($this->ns
& ~
1),
63 'wl_title' => $this->ti
,
64 'wl_notificationtimestamp' => NULL
65 ), $fname, 'IGNORE' );
67 // Every single watched page needs now to be listed in watchlist;
68 // namespace:page and namespace_talk:page need separate entries:
69 $dbw->insert( 'watchlist',
71 'wl_user' => $this->id
,
72 'wl_namespace' => ($this->ns |
1 ),
73 'wl_title' => $this->ti
,
74 'wl_notificationtimestamp' => NULL
75 ), $fname, 'IGNORE' );
77 wfProfileOut( $fname );
81 function removeWatch() {
82 $fname = 'WatchedItem::removeWatch';
85 $dbw =& wfGetDB( DB_MASTER
);
86 $dbw->delete( 'watchlist',
88 'wl_user' => $this->id
,
89 'wl_namespace' => ($this->ns
& ~
1),
90 'wl_title' => $this->ti
93 if ( $dbw->affectedRows() ) {
97 # the following code compensates the new behaviour, introduced by the
98 # enotif patch, that every single watched page needs now to be listed
99 # in watchlist namespace:page and namespace_talk:page had separate
100 # entries: clear them
101 $dbw->delete( 'watchlist',
103 'wl_user' => $this->id
,
104 'wl_namespace' => ($this->ns |
1),
105 'wl_title' => $this->ti
109 if ( $dbw->affectedRows() ) {
116 * Check if the given title already is watched by the user, and if so
117 * add watches on a new title. To be used for page renames and such.
119 * @param Title $ot Page title to duplicate entries from, if present
120 * @param Title $nt Page title to add watches on
123 function duplicateEntries( $ot, $nt ) {
124 WatchedItem
::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
125 WatchedItem
::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
132 function doDuplicateEntries( $ot, $nt ) {
133 $fname = "WatchedItem::duplicateEntries";
134 $oldnamespace = $ot->getNamespace();
135 $newnamespace = $nt->getNamespace();
136 $oldtitle = $ot->getDBkey();
137 $newtitle = $nt->getDBkey();
139 $dbw =& wfGetDB( DB_MASTER
);
140 $res = $dbw->select( 'watchlist', 'wl_user',
141 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
144 # Construct array to replace into the watchlist
146 while ( $s = $dbw->fetchObject( $res ) ) {
148 'wl_user' => $s->wl_user
,
149 'wl_namespace' => $newnamespace,
150 'wl_title' => $newtitle
153 $dbw->freeResult( $res );
155 if( empty( $values ) ) {
161 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
162 # some other DBMSes, mostly due to poor simulation by us
163 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );