e2d9506f79e6cd8202dbb6d57feff92c08ced3c0
5 /* static */ function &fromUserTitle( &$user, &$title ) {
9 $wl->id
= $user->getId();
10 $wl->ns
= $title->getNamespace() & ~
1;
11 $wl->ti
= $title->getDBkey();
12 $wl->eti
= wfStrencode( $wl->ti
);
18 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
23 # Pages and their talk pages are considered equivalent for watching;
24 # remember that talk namespaces are numbered as page namespace+1.
26 $key = $this->watchKey();
27 $iswatched = $wgMemc->get( $key );
28 if( is_integer( $iswatched ) ) return $iswatched;
30 $sql = "SELECT 1 FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti'";
31 $res = wfQuery( $sql, DB_READ
);
32 $iswatched = (wfNumRows( $res ) > 0) ?
1 : 0;
33 $wgMemc->set( $key, $iswatched );
39 $fname = "WatchedItem::addWatch";
40 # REPLACE instead of INSERT because occasionally someone
41 # accidentally reloads a watch-add operation.
42 $dbw =& wfGetDB( DB_WRITE
);
43 $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title')),
45 'wl_user' => $this->id
,
46 'wl_namespace' => $this->ns
,
47 'wl_title' => $this->eti
,
51 $wgMemc->set( $this->watchkey(), 1 );
55 function removeWatch()
57 $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti'";
58 $res = wfQuery( $sql, DB_WRITE
);
59 if( $res === false ) return false;
62 $wgMemc->set( $this->watchkey(), 0 );
66 /* static */ function duplicateEntries( $ot, $nt ) {
67 $fname = "WatchedItem::duplicateEntries";
68 global $wgMemc, $wgDBname;
69 $oldnamespace = $ot->getNamespace() & ~
1;
70 $newnamespace = $nt->getNamespace() & ~
1;
71 $oldtitle = $ot->getDBkey();
72 $newtitle = $nt->getDBkey();
73 $eoldtitle = wfStrencode( $oldtitle );
74 $enewtitle = wfStrencode( $newtitle );
76 $sql = "SELECT wl_user FROM watchlist
77 WHERE wl_namespace={$oldnamespace} AND wl_title='{$eoldtitle}'";
78 $res = wfQuery( $sql, DB_READ
, $fname );
79 if( $s = wfFetchObject( $res ) ) {
80 $sql = "REPLACE INTO watchlist (wl_user,wl_namespace,wl_title)
81 VALUES ({$s->wl_user},{$newnamespace},'{$enewtitle}')";
82 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle";
83 $wgMemc->set( $key, 1 );
84 while( $s = wfFetchObject( $res ) ) {
85 $sql .= ",({$s->wl_user},{$newnamespace},'{$enewtitle}')";
86 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle";
87 $wgMemc->set( $key, 1 );
89 $res = wfQuery( $sql, DB_WRITE
, $fname );
90 if( $res === false ) return false; # db error?