584097e0886fc5409d7495e783f56b8e8c74bc7d
[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
21 /**
22 * See deferred.doc
23 *
24 * @package MediaWiki
25 */
26
27 /**
28 *
29 * @package MediaWiki
30 */
31 class UserTalkUpdate {
32
33 /**#@+
34 * @access private
35 */
36 var $mAction, $mNamespace, $mTitle, $mSummary, $mMinorEdit, $mTimestamp;
37 /**#@-*/
38
39 /**
40 * @todo document
41 * @param string $action
42 * @param integer $ns
43 * @param $title
44 * @param $summary
45 * @param $minoredit
46 * @param $timestamp
47 */
48 function UserTalkUpdate( $action, $ns, $title, $summary, $minoredit, $timestamp) {
49 global $wgUser, $wgLang, $wgMemc, $wgDBname;
50 $fname = 'UserTalkUpdate::UserTalkUpdate';
51
52 $this->mAction = $action;
53 $this->mNamespace = $ns;
54 $this->mTitle = $title; # str_replace( '_', ' ', $title ); # I do not know, why this was needed . T. Gries 23.11.2004
55 $this->mSummary = $summary;
56 $this->mMinorEdit = $minoredit;
57 $this->mTimestamp = $timestamp;
58
59 # If namespace isn't User_talk:, do nothing.
60 if ( $this->mNamespace != Namespace::getTalk(Namespace::getUser() ) ) {
61 return;
62 }
63
64 # If the user talk page is our own, clear the flag
65 # when we are reading it or writing it.
66 if ( 0 == strcmp( $this->mTitle, $wgUser->getName() ) ) {
67 $wgUser->setNewtalk( 0 );
68 $wgUser->saveSettings();
69 } else {
70 # Not ours. If writing, then mark it as modified.
71 $sql = false;
72 if ( 1 == $this->mAction ) {
73 $user = new User();
74 $user->setID(User::idFromName($this->mTitle));
75
76 if ($id=$user->getID()) {
77 $sql = true;
78 $wgMemc->delete( "$wgDBname:user:id:$id" );
79 } else {
80 if ( $wgUser->isIP($this->mTitle) ) { # anonymous
81 $dbw =& wfGetDB( DB_MASTER );
82 $dbw->replace( 'watchlist',
83 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
84 array('wl_user' => 0,
85 'wl_namespace' => NS_USER_TALK,
86 'wl_title' => $this->mTitle,
87 'wl_notificationtimestamp' => 1
88 ), 'UserTalkUpdate'
89 );
90 $sql = true;
91 $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
92 }
93 }
94
95 if($sql && !$user->getNewtalk() ) {
96 # create an artificial watchlist table entry for the owner X of the user_talk page X
97 # only insert if X is a real user and the page is not yet watched
98 # mark the changed watch-listed page with a timestamp, so that the page is listed with
99 # an "updated since your last visit" icon in the watch list, ...
100 # ... no matter, if the watching user has or has not indicated an email address in his/her preferences.
101 # We memorise the event of sending out a notification and use this as a flag to suppress
102 # further mails for changes on the same page for that watching user
103 $dbw =& wfGetDB( DB_MASTER );
104 $dbw->replace( 'watchlist',
105 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
106 array('wl_user' => $id,
107 'wl_namespace' => NS_USER_TALK,
108 'wl_title' => $this->mTitle,
109 'wl_notificationtimestamp' => 1
110 ), 'UserTalkUpdate'
111 );
112 }
113 }
114 }
115 }
116 }
117
118 ?>