From bcc5c346ad4c5b793e65776341995bab0466b97a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 29 Nov 2004 17:36:13 +0000 Subject: [PATCH] Another step in removing deferred updates. Removed the UserTalkUpdate 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 | 31 +++++++++++++---- includes/UpdateClasses.php | 1 - includes/User.php | 49 +++++++++++++++++++++------ includes/UserTalkUpdate.php | 67 ------------------------------------- 4 files changed, 63 insertions(+), 85 deletions(-) delete mode 100644 includes/UserTalkUpdate.php diff --git a/includes/Article.php b/includes/Article.php index ccffe7d23b..13b42efa17 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ); diff --git a/includes/UpdateClasses.php b/includes/UpdateClasses.php index 7cd39fc854..f4778b52e8 100644 --- a/includes/UpdateClasses.php +++ b/includes/UpdateClasses.php @@ -12,7 +12,6 @@ require_once( 'SiteStatsUpdate.php' ); require_once( 'LinksUpdate.php' ); require_once( 'SearchUpdate.php' ); -require_once( 'UserTalkUpdate.php' ); require_once( 'SquidUpdate.php' ); ?> diff --git a/includes/User.php b/includes/User.php index f51edcdd43..07d02277df 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 index 70b6d3b6fa..0000000000 --- a/includes/UserTalkUpdate.php +++ /dev/null @@ -1,67 +0,0 @@ -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 ); - } - } - } - } -} - -?> -- 2.20.1