*/
function viewUpdates() {
global $wgDeferredUpdateList;
+
if ( 0 != $this->getID() ) {
global $wgDisableCounters;
if( !$wgDisableCounters ) {
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();
+ }
}
/**
*/
function editUpdates( $text ) {
global $wgDeferredUpdateList, $wgDBname, $wgMemc;
- global $wgMessageCache;
+ global $wgMessageCache, $wgUser;
wfSeedRandom();
if ( 0 == mt_rand( 0, 999 ) ) {
$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 );
require_once( 'SiteStatsUpdate.php' );
require_once( 'LinksUpdate.php' );
require_once( 'SearchUpdate.php' );
-require_once( 'UserTalkUpdate.php' );
require_once( 'SquidUpdate.php' );
?>
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,
}
}
+ /**
+ * 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
*/
+++ /dev/null
-<?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 );
- }
- }
- }
- }
-}
-
-?>