aboutsummaryrefslogtreecommitdiffstats
path: root/includes/UserTalkUpdate.php
blob: 66ea7a9aee25569fb638d494771f990bd1ac20bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
# See deferred.doc

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;
			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
					wfQuery( $sql, DB_WRITE, $fname );
				}
			}
		}
	}
}

?>