* Removed redudant global decleration
[lhc/web/wiklou.git] / includes / WatchedItem.php
index 3793762..fbbc366 100644 (file)
@@ -38,7 +38,7 @@ class WatchedItem {
                global $wgDBname;
                return "$wgDBname:watchlist:user:$this->id:page:$this->ns:$this->ti";
        }
-       
+
        /**
         * Is mTitle being watched by mUser?
         */
@@ -51,9 +51,9 @@ class WatchedItem {
                $key = $this->watchKey();
                $iswatched = $wgMemc->get( $key );
                if( is_integer( $iswatched ) ) return $iswatched;
-               
+
                $dbr =& wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id, 'wl_namespace' => $this->ns, 
+               $res = $dbr->select( 'watchlist', 1, array( 'wl_user' => $this->id, 'wl_namespace' => $this->ns,
                        'wl_title' => $this->ti ), $fname );
                $iswatched = ($dbr->numRows( $res ) > 0) ? 1 : 0;
                $wgMemc->set( $key, $iswatched );
@@ -65,15 +65,16 @@ class WatchedItem {
         */
        function addWatch() {
                $fname = 'WatchedItem::addWatch';
+               wfProfileIn( $fname );
                # REPLACE instead of INSERT because occasionally someone
                # accidentally reloads a watch-add operation.
                $dbw =& wfGetDB( DB_MASTER );
                $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
-                 array( 
+                 array(
                    'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns & ~1),
                        'wl_title' => $this->ti,
-                       'wl_notificationtimestamp' => '0'
+                       'wl_notificationtimestamp' => NULL
                  ), $fname );
 
                # the following code compensates the new behaviour, introduced by the enotif patch,
@@ -84,25 +85,31 @@ class WatchedItem {
                        'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns | 1 ),
                        'wl_title' => $this->ti,
-                       'wl_notificationtimestamp' => '0'
+                       'wl_notificationtimestamp' => NULL
                  ), $fname );
 
                global $wgMemc;
                $wgMemc->set( $this->watchkey(), 1 );
+               wfProfileOut( $fname );
                return true;
        }
 
        function removeWatch() {
+               global $wgMemc;
                $fname = 'WatchedItem::removeWatch';
 
+               $success = false;
                $dbw =& wfGetDB( DB_MASTER );
-               $dbw->delete( 'watchlist', 
-                       array( 
-                               'wl_user' => $this->id, 
+               $dbw->delete( 'watchlist',
+                       array(
+                               'wl_user' => $this->id,
                                'wl_namespace' => ($this->ns & ~1),
                                'wl_title' => $this->ti
                        ), $fname
                );
+               if ( $dbw->affectedRows() ) {
+                       $success = true;
+               }
 
                # the following code compensates the new behaviour, introduced by the
                # enotif patch, that every single watched page needs now to be listed
@@ -115,14 +122,14 @@ class WatchedItem {
                                'wl_title' => $this->ti
                        ), $fname
                );
-               
+
                if ( $dbw->affectedRows() ) {
-                       global $wgMemc;
+                       $success = true;
+               }
+               if ( $success ) {
                        $wgMemc->set( $this->watchkey(), 0 );
-                       return true;
-               } else {
-                       return false;
                }
+               return $success;
        }
 
        /**
@@ -138,8 +145,8 @@ class WatchedItem {
 
                $dbw =& wfGetDB( DB_MASTER );
                $watchlist = $dbw->tableName( 'watchlist' );
-               
-               $res = $dbw->select( 'watchlist', 'wl_user', 
+
+               $res = $dbw->select( 'watchlist', 'wl_user',
                        array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
                        $fname, 'FOR UPDATE'
                );