bd47214aa2925828732a92fc516ac08f17948df7
12 # Create a WatchedItem object with the given user and title
13 /* static */ function &fromUserTitle( &$user, &$title ) {
14 $wl = new WatchedItem
;
16 $wl->mTitle
=& $title;
17 $wl->id
= $user->getId();
18 $wl->ns
= $title->getNamespace() & ~
1;
19 $wl->ti
= $title->getDBkey();
24 * Returns the memcached key for this item
28 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
32 * Is mTitle being watched by mUser?
36 # Pages and their talk pages are considered equivalent for watching;
37 # remember that talk namespaces are numbered as page namespace+1.
39 $fname = 'WatchedItem::isWatched';
41 $key = $this->watchKey();
42 $iswatched = $wgMemc->get( $key );
43 if( is_integer( $iswatched ) ) return $iswatched;
45 $dbr =& wfGetDB( DB_SLAVE
);
46 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
47 'wl_title' => $this->ti
), $fname );
48 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
49 $wgMemc->set( $key, $iswatched );
54 $fname = "WatchedItem::addWatch";
55 # REPLACE instead of INSERT because occasionally someone
56 # accidentally reloads a watch-add operation.
57 $dbw =& wfGetDB( DB_MASTER
);
58 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title')),
60 'wl_user' => $this->id
,
61 'wl_namespace' => $this->ns
,
62 'wl_title' => $this->ti
,
66 $wgMemc->set( $this->watchkey(), 1 );
70 function removeWatch() {
71 $fname = 'WatchedItem::removeWatch';
73 $dbw =& wfGetDB( DB_MASTER
);
74 $dbw->delete( 'watchlist',
76 'wl_user' => $this->id
,
77 'wl_namespace' => $this->ns
,
78 'wl_title' => $this->ti
82 if ( $dbw->affectedRows() ) {
84 $wgMemc->set( $this->watchkey(), 0 );
94 function duplicateEntries( $ot, $nt ) {
95 $fname = "WatchedItem::duplicateEntries";
96 global $wgMemc, $wgDBname;
97 $oldnamespace = $ot->getNamespace() & ~
1;
98 $newnamespace = $nt->getNamespace() & ~
1;
99 $oldtitle = $ot->getDBkey();
100 $newtitle = $nt->getDBkey();
102 $dbw =& wfGetDB( DB_MASTER
);
103 $watchlist = $dbw->tableName( 'watchlist' );
105 $res = $dbw->select( 'watchlist', 'wl_user',
106 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
109 # Construct array to replace into the watchlist
111 while ( $s = $dbw->fetchObject( $res ) ) {
113 'wl_user' => $s->wl_user
,
114 'wl_namespace' => $newnamespace,
115 'wl_title' => $newtitle
118 $dbw->freeResult( $res );
121 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
122 # some other DBMSes, mostly due to poor simulation by us
123 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );