(bug 4974) Don't follow redirected talk page on "new messages" link
[lhc/web/wiklou.git] / includes / WatchedItem.php
index 11c6eec..f0f5623 100644 (file)
@@ -14,7 +14,7 @@ class WatchedItem {
        /**
         * Create a WatchedItem object with the given user and title
         * @todo document
-        * @private
+        * @access private
         */
        function &fromUserTitle( &$user, &$title ) {
                $wl = new WatchedItem;
@@ -66,27 +66,27 @@ class WatchedItem {
        function addWatch() {
                $fname = 'WatchedItem::addWatch';
                wfProfileIn( $fname );
-               # REPLACE instead of INSERT because occasionally someone
-               # accidentally reloads a watch-add operation.
+
+               // Use INSERT IGNORE to avoid overwriting the notification timestamp
+               // if there's already an entry for this page
                $dbw =& wfGetDB( DB_MASTER );
-               $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+               $dbw->insert( 'watchlist',
                  array(
                    'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns & ~1),
                        'wl_title' => $this->ti,
                        'wl_notificationtimestamp' => NULL
-                 ), $fname );
+                 ), $fname, 'IGNORE' );
 
-               # the following code compensates the new behaviour, introduced by the enotif patch,
-               # that every single watched page needs now to be listed in watchlist
-               # namespace:page and namespace_talk:page need separate entries: create them
-               $dbw->replace( 'watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+               // Every single watched page needs now to be listed in watchlist;
+               // namespace:page and namespace_talk:page need separate entries:
+               $dbw->insert( 'watchlist',
                  array(
                        'wl_user' => $this->id,
                        'wl_namespace' => ($this->ns | 1 ),
                        'wl_title' => $this->ti,
                        'wl_notificationtimestamp' => NULL
-                 ), $fname );
+                 ), $fname, 'IGNORE' );
 
                global $wgMemc;
                $wgMemc->set( $this->watchkey(), 1 );
@@ -144,7 +144,7 @@ class WatchedItem {
                WatchedItem::doDuplicateEntries( $ot->getSubjectPage(), $nt->getSubjectPage() );
                WatchedItem::doDuplicateEntries( $ot->getTalkPage(), $nt->getTalkPage() );
        }
-       
+
        /**
         * @static
         * @access private
@@ -158,8 +158,6 @@ class WatchedItem {
                $newtitle = $nt->getDBkey();
 
                $dbw =& wfGetDB( DB_MASTER );
-               $watchlist = $dbw->tableName( 'watchlist' );
-
                $res = $dbw->select( 'watchlist', 'wl_user',
                        array( 'wl_namespace' => $oldnamespace, 'wl_title' => $oldtitle ),
                        $fname, 'FOR UPDATE'
@@ -174,7 +172,7 @@ class WatchedItem {
                        );
                }
                $dbw->freeResult( $res );
-               
+
                if( empty( $values ) ) {
                        // Nothing to do
                        return true;