Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

WatchedItem.php

Go to the documentation of this file.
00001 <?php 00002 00003 class WatchedItem { 00004 00005 /* static */ function &fromUserTitle( &$user, &$title ) { 00006 $wl = new WatchedItem; 00007 $wl->mUser =& $user; 00008 $wl->mTitle =& $title; 00009 $wl->id = $user->getId(); 00010 $wl->ns = $title->getNamespace() & ~1; 00011 $wl->ti = $title->getDBkey(); 00012 $wl->eti = wfStrencode( $wl->ti ); 00013 return $wl; 00014 } 00015 00016 function watchKey() { 00017 global $wgDBname; 00018 return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti"; 00019 } 00020 00021 function isWatched() 00022 { 00023 # Pages and their talk pages are considered equivalent for watching; 00024 # remember that talk namespaces are numbered as page namespace+1. 00025 global $wgMemc; 00026 $key = $this->watchKey(); 00027 $iswatched = $wgMemc->get( $key ); 00028 if( is_integer( $iswatched ) ) return $iswatched; 00029 00030 $sql = "SELECT 1 FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti'"; 00031 $res = wfQuery( $sql, DB_READ ); 00032 $iswatched = (wfNumRows( $res ) > 0) ? 1 : 0; 00033 $wgMemc->set( $key, $iswatched ); 00034 return $iswatched; 00035 } 00036 00037 function addWatch() 00038 { 00039 global $wgIsMySQL; 00040 # REPLACE instead of INSERT because occasionally someone 00041 # accidentally reloads a watch-add operation. 00042 if ($wgIsMySQL) { 00043 $sql = "REPLACE INTO watchlist (wl_user, wl_namespace,wl_title) ". 00044 "VALUES ($this->id,$this->ns,'$this->eti')"; 00045 $res = wfQuery( $sql, DB_WRITE ); 00046 } else { 00047 $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND 00048 wl_namespace=$this->ns AND wl_title='$this->eti'"; 00049 wfQuery( $sql, DB_WRITE); 00050 $sql = "INSERT INTO watchlist (wl_user, wl_namespace,wl_title) ". 00051 "VALUES ($this->id,$this->ns,'$this->eti')"; 00052 $res = wfQuery( $sql, DB_WRITE ); 00053 } 00054 00055 if( $res === false ) return false; 00056 00057 global $wgMemc; 00058 $wgMemc->set( $this->watchkey(), 1 ); 00059 return true; 00060 } 00061 00062 function removeWatch() 00063 { 00064 $sql = "DELETE FROM watchlist WHERE wl_user=$this->id AND wl_namespace=$this->ns AND wl_title='$this->eti'"; 00065 $res = wfQuery( $sql, DB_WRITE ); 00066 if( $res === false ) return false; 00067 00068 global $wgMemc; 00069 $wgMemc->set( $this->watchkey(), 0 ); 00070 return true; 00071 } 00072 00073 /* static */ function duplicateEntries( $ot, $nt ) { 00074 $fname = "WatchedItem::duplicateEntries"; 00075 global $wgMemc, $wgDBname; 00076 $oldnamespace = $ot->getNamespace() & ~1; 00077 $newnamespace = $nt->getNamespace() & ~1; 00078 $oldtitle = $ot->getDBkey(); 00079 $newtitle = $nt->getDBkey(); 00080 $eoldtitle = wfStrencode( $oldtitle ); 00081 $enewtitle = wfStrencode( $newtitle ); 00082 00083 $sql = "SELECT wl_user FROM watchlist 00084 WHERE wl_namespace={$oldnamespace} AND wl_title='{$eoldtitle}'"; 00085 $res = wfQuery( $sql, DB_READ, $fname ); 00086 if( $s = wfFetchObject( $res ) ) { 00087 $sql = "REPLACE INTO watchlist (wl_user,wl_namespace,wl_title) 00088 VALUES ({$s->wl_user},{$newnamespace},'{$enewtitle}')"; 00089 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle"; 00090 $wgMemc->set( $key, 1 ); 00091 while( $s = wfFetchObject( $res ) ) { 00092 $sql .= ",({$s->wl_user},{$newnamespace},'{$enewtitle}')"; 00093 $key = "$wgDBname:watchlist:user:$s->wl_user:page:$newnamespace:$newtitle"; 00094 $wgMemc->set( $key, 1 ); 00095 } 00096 $res = wfQuery( $sql, DB_WRITE, $fname ); 00097 if( $res === false ) return false; # db error? 00098 } 00099 return true; 00100 } 00101 00102 00103 } 00104 00105 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7