6 # Create a WatchedItem object with the given user and title
7 /* static */ function &fromUserTitle( &$user, &$title ) {
10 $wl->mTitle
=& $title;
11 $wl->id
= $user->getId();
12 $wl->ns
= $title->getNamespace() & ~
1;
13 $wl->ti
= $title->getDBkey();
17 # Returns the memcached key for this item
20 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
23 # Is mTitle being watched by mUser?
26 # Pages and their talk pages are considered equivalent for watching;
27 # remember that talk namespaces are numbered as page namespace+1.
29 $fname = 'WatchedItem::isWatched';
31 $key = $this->watchKey();
32 $iswatched = $wgMemc->get( $key );
33 if( is_integer( $iswatched ) ) return $iswatched;
35 $dbr =& wfGetDB( DB_SLAVE
);
36 $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id
, 'wl_namespace' => $this->ns
,
37 'wl_title' => $this->ti
), $fname );
38 $iswatched = ($dbr->numRows( $res ) > 0) ?
1 : 0;
39 $wgMemc->set( $key, $iswatched );
45 $fname = "WatchedItem::addWatch";
46 # REPLACE instead of INSERT because occasionally someone
47 # accidentally reloads a watch-add operation.
48 $dbw =& wfGetDB( DB_MASTER
);
49 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title')),
51 'wl_user' => $this->id
,
52 'wl_namespace' => $this->ns
,
53 'wl_title' => $this->ti
,
57 $wgMemc->set( $this->watchkey(), 1 );
61 function removeWatch()
63 $fname = 'WatchedItem::removeWatch';
65 $dbw =& wfGetDB( DB_MASTER
);
66 $dbw->delete( 'watchlist',
68 'wl_user' => $this->id
,
69 'wl_namespace' => $this->ns
,
70 'wl_title' => $this->ti
74 if ( $dbw->affectedRows() ) {
76 $wgMemc->set( $this->watchkey(), 0 );
83 /* static */ function duplicateEntries( $ot, $nt ) {
84 $fname = "WatchedItem::duplicateEntries";
85 global $wgMemc, $wgDBname;
86 $oldnamespace = $ot->getNamespace() & ~
1;
87 $newnamespace = $nt->getNamespace() & ~
1;
88 $oldtitle = $ot->getDBkey();
89 $newtitle = $nt->getDBkey();
91 $dbw =& wfGetDB( DB_MASTER
);
92 $watchlist = $dbw->tableName( 'watchlist' );
94 $res = $dbw->select( 'watchlist', 'wl_user',
95 array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
98 # Construct array to replace into the watchlist
100 while ( $s = $dbw->fetchObject( $res ) ) {
102 'wl_user' => $s->wl_user
,
103 'wl_namespace' => $newnamespace,
104 'wl_title' => $newtitle
107 $dbw->freeResult( $res );
110 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
111 # some other DBMSes, mostly due to poor simulation by us
112 $dbw->replace( 'watchlist', array(array( 'wl_user', 'wl_namespace', 'wl_title')), $values, $fname );