14 # Create a WatchedItem object with the given user and title
15 /* static */ function &fromUserTitle( &$user, &$title ) {
16 $wl = new WatchedItem
;
18 $wl->mTitle
=& $title;
19 $wl->id
= $user->getId();
20 $wl->ns
= $title->getNamespace() & ~
1;
21 $wl->ti
= $title->getDBkey();
26 * Returns the memcached key for this item
30 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
34 * Is mTitle being watched by mUser?
38 # Pages and their talk pages are considered equivalent for watching;
39 # remember that talk namespaces are numbered as page namespace+1.
41 $fname = 'WatchedItem::isWatched';
43 $key = $this->watchKey();
44 $iswatched = $wgMemc->get( $key );
45 if( is_integer( $iswatched ) ) return $iswatched;
47 $dbr =& wfGetDB( DB_SLAVE
);
48 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
49 'wl_title' => $this->ti
), $fname );
50 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
51 $wgMemc->set( $key, $iswatched );
56 $fname = "WatchedItem::addWatch";
57 # REPLACE instead of INSERT because occasionally someone
58 # accidentally reloads a watch-add operation.
59 $dbw =& wfGetDB( DB_MASTER
);
60 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title')),
62 'wl_user' => $this->id
,
63 'wl_namespace' => $this->ns
,
64 'wl_title' => $this->ti
,
68 $wgMemc->set( $this->watchkey(), 1 );
72 function removeWatch() {
73 $fname = 'WatchedItem::removeWatch';
75 $dbw =& wfGetDB( DB_MASTER
);
76 $dbw->delete( 'watchlist',
78 'wl_user' => $this->id
,
79 'wl_namespace' => $this->ns
,
80 'wl_title' => $this->ti
84 if ( $dbw->affectedRows() ) {
86 $wgMemc->set( $this->watchkey(), 0 );
96 function duplicateEntries( $ot, $nt ) {
97 $fname = "WatchedItem::duplicateEntries";
98 global $wgMemc, $wgDBname;
99 $oldnamespace = $ot->getNamespace() & ~
1;
100 $newnamespace = $nt->getNamespace() & ~
1;
101 $oldtitle = $ot->getDBkey();
102 $newtitle = $nt->getDBkey();
104 $dbw =& wfGetDB( DB_MASTER
);
105 $watchlist = $dbw->tableName( 'watchlist' );
107 $res = $dbw->select( 'watchlist', 'wl_user',
108 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
111 # Construct array to replace into the watchlist
113 while ( $s = $dbw->fetchObject( $res ) ) {
115 'wl_user' => $s->wl_user
,
116 'wl_namespace' => $newnamespace,
117 'wl_title' => $newtitle
120 $dbw->freeResult( $res );
123 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
124 # some other DBMSes, mostly due to poor simulation by us
125 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );