Another step in removing deferred updates. Removed the UserTalkUpdate
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 17:36:13 +0000 (17:36 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 29 Nov 2004 17:36:13 +0000 (17:36 +0000)
module and moved user talk modification code to User (it's read in
User, should probably be written in User, too). Changed calling code
in Article to update the user directly, rather than using the
UserTalkUpdate class. Tested with logged-in and not-logged-in users.

includes/Article.php
includes/UpdateClasses.php
includes/User.php
includes/UserTalkUpdate.php [deleted file]

index ccffe7d..13b42ef 100644 (file)
@@ -1816,6 +1816,7 @@ class Article {
         */
        function viewUpdates() {
                global $wgDeferredUpdateList;
+               
                if ( 0 != $this->getID() ) {
                        global $wgDisableCounters;
                        if( !$wgDisableCounters ) {
@@ -1824,9 +1825,18 @@ class Article {
                                array_push( $wgDeferredUpdateList, $u );
                        }
                }
-               $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
-                 $this->mTitle->getDBkey() );
-               array_push( $wgDeferredUpdateList, $u );
+               
+               # Update newtalk status if user is reading their own
+               # talk page
+
+               global $wgUser;
+               
+               if ($this->mTitle->getNamespace() == NS_USER_TALK &&
+                       $this->mTitle->getText() == $wgUser->getName())
+               {
+                       $wgUser->setNewtalk(0);
+                       $wgUser->saveNewtalk();
+               }
        }
 
        /**
@@ -1837,7 +1847,7 @@ class Article {
         */
        function editUpdates( $text ) {
                global $wgDeferredUpdateList, $wgDBname, $wgMemc;
-               global $wgMessageCache;
+               global $wgMessageCache, $wgUser;
 
                wfSeedRandom();
                if ( 0 == mt_rand( 0, 999 ) ) {
@@ -1860,8 +1870,17 @@ class Article {
                        $u = new SearchUpdate( $id, $title, $text );
                        array_push( $wgDeferredUpdateList, $u );
 
-                       $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle );
-                       array_push( $wgDeferredUpdateList, $u );
+                       # If this is another user's talk page, save a
+                       # newtalk notification for them
+                       
+                       if ($this->mTitle->getNamespace() == NS_USER_TALK &&
+                               $shortTitle != $wgUser->getName())
+                       {
+                               $other = User::newFromName($shortTitle);
+                               $other->setID(User::idFromName($shortTitle));
+                               $other->setNewtalk(1);
+                               $other->saveNewtalk();
+                       }
 
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                $wgMessageCache->replace( $shortTitle, $text );
index 7cd39fc..f4778b5 100644 (file)
@@ -12,7 +12,6 @@
 require_once( 'SiteStatsUpdate.php' );
 require_once( 'LinksUpdate.php' );
 require_once( 'SearchUpdate.php' );
-require_once( 'UserTalkUpdate.php' );
 require_once( 'SquidUpdate.php' );
 
 ?>
index f51edcd..07d0227 100644 (file)
@@ -814,18 +814,12 @@ class User {
                global $wgMemc, $wgDBname;
                $fname = 'User::saveSettings';
 
-               $dbw =& wfGetDB( DB_MASTER );
-               if ( ! $this->getNewtalk() ) {
-                       # Delete user_newtalk row
-                       if( $this->mId ) {
-                               $dbw->delete( 'user_newtalk', array( 'user_id' => $this->mId ), $fname );
-                       } else {
-                               $dbw->delete( 'user_newtalk', array( 'user_ip' => $this->mName ), $fname );
-                               $wgMemc->delete( "$wgDBname:newtalk:ip:{$this->mName}" );
-                       }
-               }
-               if ( 0 == $this->mId ) { return; }
+               $this->saveNewtalk();
 
+               if ( 0 == $this->mId ) { return; }
+               
+               $dbw =& wfGetDB( DB_MASTER );
+               
                $dbw->update( 'user',
                        array( /* SET */
                                'user_name' => $this->mName,
@@ -859,6 +853,39 @@ class User {
                }
        }
 
+       /**
+        * Save value of new talk flag.
+        */
+       function saveNewtalk() {
+               global $wgDBname, $wgMemc;
+               
+               $fname = 'User::saveNewtalk';
+
+               if ($this->getID() != 0) {
+                       $field = 'user_id';
+                       $value = $this->getID();
+                       $key = "$wgDBname:user:id:$this->mId";
+               } else {
+                       $field = 'user_ip';
+                       $value = $this->mName;
+                       $key = "$wgDBname:newtalk:ip:$this->mName";
+               }
+               
+               $dbr =& wfGetDB( DB_SLAVE );
+               $dbw =& wfGetDB( DB_MASTER );
+
+               $res = $dbr->selectField('user_newtalk', $field,
+                                                                array($field => $value), $fname);
+
+               if ($res !== false && $this->mNewtalk == 0) {
+                       $dbw->delete('user_newtalk', array($field => $value), $fname);
+                       $wgMemc->delete($key);
+               } else if ($res === false && $this->mNewtalk == 1) {
+                       $dbw->insert('user_newtalk', array($field => $value), $fname);
+                       $wgMemc->delete($key);                  
+               }
+       }
+       
        /**
         * Checks if a user with the given name exists, returns the ID
         */
diff --git a/includes/UserTalkUpdate.php b/includes/UserTalkUpdate.php
deleted file mode 100644 (file)
index 70b6d3b..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * See deferred.doc
- *
- * @package MediaWiki
- */
-
-/**
- *
- * @package MediaWiki
- */
-class UserTalkUpdate {
-
-       /* private */ var $mAction, $mNamespace, $mTitle;
-
-       function UserTalkUpdate( $action, $ns, $title ) {
-               $this->mAction = $action;
-               $this->mNamespace = $ns;
-               $this->mTitle = str_replace( '_', ' ', $title );
-       }
-
-       function doUpdate() {   
-               global $wgUser, $wgLang, $wgMemc, $wgDBname;
-               $fname = 'UserTalkUpdate::doUpdate';
-
-               # If namespace isn't User_talk:, do nothing.
-
-               if ( $this->mNamespace != Namespace::getTalk(
-                 Namespace::getUser() ) ) {
-                       return;
-               }
-               # If the user talk page is our own, clear the flag
-               # whether we are reading it or writing it.
-               if ( 0 == strcmp( $this->mTitle, $wgUser->getName() ) ) {
-                       $wgUser->setNewtalk( 0 );                       
-                       $wgUser->saveSettings();
-
-               } else {
-                       # Not ours.  If writing, mark it as modified.
-
-                       $sql = false;
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $user_newtalk = $dbw->tableName( 'user_newtalk' );
-
-                       if ( 1 == $this->mAction ) {
-                               $user = new User();                             
-                               $user->setID(User::idFromName($this->mTitle));
-                               if ($id=$user->getID()) {                                                                       
-                                       $sql = "INSERT INTO $user_newtalk (user_id) values ({$id})";
-                                       $wgMemc->delete( "$wgDBname:user:id:$id" );
-                               } else {
-                                       #anon
-                                       if(preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle)) { #real anon (user:xxx.xxx.xxx.xxx)
-                                               $sql = "INSERT INTO $user_newtalk (user_id,user_ip) values (0,\"{$this->mTitle}\")";            
-                                               $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
-                                       }
-                               }
-                               
-                               if($sql && !$user->getNewtalk()) { # only insert if real user and it's not already there
-                                       $dbw->query( $sql, $fname );
-                               }
-                       }
-               }
-       }
-}
-
-?>