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