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 );
40 # REPLACE instead of INSERT because occasionally someone
41 # accidentally reloads a watch-add operation.
43 $sql = "REPLACE INTO watchlist (wl_user, wl_namespace,wl_title) ".
44 "VALUES ($this->id,$this->ns,'$this->eti')";
45 $res = wfQuery( $sql, DB_WRITE
);
47 $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND
48 wl_namespace=$this->ns AND wl_title='$this->eti'";
49 wfQuery( $sql, DB_WRITE
);
50 $sql = "INSERT INTO watchlist (wl_user, wl_namespace,wl_title) ".
51 "VALUES ($this->id,$this->ns,'$this->eti')";
52 $res = wfQuery( $sql, DB_WRITE
);
55 if( $res === false ) return false;
58 $wgMemc->set( $this->watchkey(), 1 );
62 function removeWatch()
64 $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti'";
65 $res = wfQuery( $sql, DB_WRITE
);
66 if( $res === false ) return false;
69 $wgMemc->set( $this->watchkey(), 0 );
73 /* static */ function duplicateEntries( $ot, $nt ) {
74 $fname = "WatchedItem::duplicateEntries";
75 global $wgMemc, $wgDBname;
76 $oldnamespace = $ot->getNamespace() & ~
1;
77 $newnamespace = $nt->getNamespace() & ~
1;
78 $oldtitle = $ot->getDBkey();
79 $newtitle = $nt->getDBkey();
80 $eoldtitle = wfStrencode( $oldtitle );
81 $enewtitle = wfStrencode( $newtitle );
83 $sql = "SELECT wl_user FROM watchlist
84 WHERE wl_namespace={$oldnamespace} AND wl_title='{$eoldtitle}'";
85 $res = wfQuery( $sql, DB_READ
, $fname );
86 if( $s = wfFetchObject( $res ) ) {
87 $sql = "REPLACE INTO watchlist (wl_user,wl_namespace,wl_title)
88 VALUES ({$s->wl_user},{$newnamespace},'{$enewtitle}')";
89 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle";
90 $wgMemc->set( $key, 1 );
91 while( $s = wfFetchObject( $res ) ) {
92 $sql .= ",({$s->wl_user},{$newnamespace},'{$enewtitle}')";
93 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle";
94 $wgMemc->set( $key, 1 );
96 $res = wfQuery( $sql, DB_WRITE
, $fname );
97 if( $res === false ) return false; # db error?