* code formatting
[lhc/web/wiklou.git] / includes / UserTalkUpdate.php
1 <?php
2 /** Copyright (C) 2004 Thomas Gries <mail@tgries.de>
3 * http://www.mediawiki.org/
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * See deferred.txt
21 *
22 * @package MediaWiki
23 * @author <mail@tgries.de>
24 */
25
26 /**
27 *
28 * @package MediaWiki
29 */
30 class UserTalkUpdate {
31
32 /**#@+
33 * @access private
34 */
35 var $mAction, $mNamespace, $mTitle, $mSummary, $mMinorEdit, $mTimestamp;
36 /**#@-*/
37
38 /**
39 * @todo document
40 * @param string $action
41 * @param integer $ns
42 * @param $title
43 * @param $summary
44 * @param $minoredit
45 * @param $timestamp
46 */
47 function UserTalkUpdate( $action, $ns, $title, $summary, $minoredit, $timestamp) {
48 global $wgUser, $wgMemc, $wgDBname;
49
50 $this->mAction = $action;
51 $this->mNamespace = $ns;
52 $this->mTitle = $title; # str_replace( '_', ' ', $title ); # I do not know, why this was needed . T. Gries 23.11.2004
53 $this->mSummary = $summary;
54 $this->mMinorEdit = $minoredit;
55 $this->mTimestamp = $timestamp;
56
57 # If namespace isn't User_talk:, do nothing.
58 if ( $this->mNamespace != NS_USER_TALK ) {
59 return;
60 }
61
62 # If the user talk page is our own, clear the flag
63 # when we are reading it or writing it.
64 if ( 0 == strcmp( $this->mTitle, $wgUser->getName() ) ) {
65 $wgUser->setNewtalk( 0 );
66 $wgUser->saveSettings();
67 } else {
68 # Not ours. If writing, then mark it as modified.
69 $sql = false;
70 if ( 1 == $this->mAction ) {
71 $user = new User();
72 $user->setID(User::idFromName($this->mTitle));
73
74 if ($id=$user->getID()) {
75 $sql = true;
76 $wgMemc->delete( "$wgDBname:user:id:$id" );
77 } else {
78 if ( $wgUser->isIP($this->mTitle) ) { # anonymous
79 $dbw =& wfGetDB( DB_MASTER );
80 $dbw->replace( 'watchlist',
81 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
82 array('wl_user' => 0,
83 'wl_namespace' => NS_USER_TALK,
84 'wl_title' => $this->mTitle,
85 'wl_notificationtimestamp' => 1
86 ), 'UserTalkUpdate'
87 );
88 $sql = true;
89 $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
90 }
91 }
92
93 if($sql && !$user->getNewtalk() ) {
94 # create an artificial watchlist table entry for the owner X of the user_talk page X
95 # only insert if X is a real user and the page is not yet watched
96 # mark the changed watch-listed page with a timestamp, so that the page is listed with
97 # an "updated since your last visit" icon in the watch list, ...
98 # ... no matter, if the watching user has or has not indicated an email address in his/her preferences.
99 # We memorise the event of sending out a notification and use this as a flag to suppress
100 # further mails for changes on the same page for that watching user
101 $dbw =& wfGetDB( DB_MASTER );
102 $dbw->replace( 'watchlist',
103 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
104 array('wl_user' => $id,
105 'wl_namespace' => NS_USER_TALK,
106 'wl_title' => $this->mTitle,
107 'wl_notificationtimestamp' => 1
108 ), 'UserTalkUpdate'
109 );
110 }
111 }
112 }
113 }
114 }
115
116 ?>