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