Suppress some more warnings on separate execution of files. Shouldn't
[lhc/web/wiklou.git] / includes / UserTalkUpdate.php
1 <?php
2 # See deferred.doc
3
4 class UserTalkUpdate {
5
6 /* private */ var $mAction, $mNamespace, $mTitle;
7
8 function UserTalkUpdate( $action, $ns, $title )
9 {
10 $this->mAction = $action;
11 $this->mNamespace = $ns;
12 $this->mTitle = str_replace( "_", " ", $title );
13 }
14
15 function doUpdate()
16 {
17
18 global $wgUser, $wgLang, $wgMemc, $wgDBname;
19 $fname = "UserTalkUpdate::doUpdate";
20
21 # If namespace isn't User_talk:, do nothing.
22
23 if ( $this->mNamespace != Namespace::getTalk(
24 Namespace::getUser() ) ) {
25 return;
26 }
27 # If the user talk page is our own, clear the flag
28 # whether we are reading it or writing it.
29 if ( 0 == strcmp( $this->mTitle, $wgUser->getName() ) ) {
30 $wgUser->setNewtalk( 0 );
31 $wgUser->saveSettings();
32
33 } else {
34 # Not ours. If writing, mark it as modified.
35
36 $sql = false;
37 $dbw =& wfGetDB( DB_MASTER );
38 $user_newtalk = $dbw->tableName( 'user_newtalk' );
39
40 if ( 1 == $this->mAction ) {
41 $user = new User();
42 $user->setID(User::idFromName($this->mTitle));
43 if ($id=$user->getID()) {
44 $sql = "INSERT INTO $user_newtalk (user_id) values ({$id})";
45 $wgMemc->delete( "$wgDBname:user:id:$id" );
46 } else {
47 #anon
48 if(preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle)) { #real anon (user:xxx.xxx.xxx.xxx)
49 $sql = "INSERT INTO $user_newtalk (user_id,user_ip) values (0,\"{$this->mTitle}\")";
50 $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
51 }
52 }
53
54 if($sql && !$user->getNewtalk()) { # only insert if real user and it's not already there
55 $dbw->query( $sql, $fname );
56 }
57 }
58 }
59 }
60 }
61
62 ?>