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