unbroke classic and cologne blue skins
[lhc/web/wiklou.git] / includes / UserTalkUpdate.php
index 70b6d3b..7c61406 100644 (file)
@@ -1,8 +1,26 @@
 <?php
-/**
- * See deferred.doc
+/** Copyright (C) 2004 Thomas Gries <mail@tgries.de>
+ * http://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ * 
+ * See deferred.txt
  *
  * @package MediaWiki
+ * @author <mail@tgries.de>
  */
 
 /**
  */
 class UserTalkUpdate {
 
-       /* private */ var $mAction, $mNamespace, $mTitle;
+       /**#@+
+        * @access private
+        */
+       var $mAction, $mNamespace, $mTitle, $mSummary, $mMinorEdit, $mTimestamp;
+       /**#@-*/
+
+       /**
+        * @todo document
+        * @param string $action
+        * @param integer $ns
+        * @param $title
+        * @param $summary
+        * @param $minoredit
+        * @param $timestamp
+        */
+       function UserTalkUpdate( $action, $ns, $title, $summary, $minoredit, $timestamp) {
+               global $wgUser, $wgLang, $wgMemc, $wgDBname;
+               $fname = 'UserTalkUpdate::UserTalkUpdate';
 
-       function UserTalkUpdate( $action, $ns, $title ) {
                $this->mAction = $action;
                $this->mNamespace = $ns;
-               $this->mTitle = str_replace( '_', ' ', $title );
-       }
-
-       function doUpdate() {   
-               global $wgUser, $wgLang, $wgMemc, $wgDBname;
-               $fname = 'UserTalkUpdate::doUpdate';
+               $this->mTitle = $title; # str_replace( '_', ' ', $title ); # I do not know, why this was needed . T. Gries 23.11.2004
+               $this->mSummary = $summary;
+               $this->mMinorEdit = $minoredit;
+               $this->mTimestamp = $timestamp;
 
                # If namespace isn't User_talk:, do nothing.
-
-               if ( $this->mNamespace != Namespace::getTalk(
-                 Namespace::getUser() ) ) {
+               if ( $this->mNamespace != NS_USER_TALK ) {
                        return;
                }
+
                # If the user talk page is our own, clear the flag
-               # whether we are reading it or writing it.
+               # when we are reading it or writing it.
                if ( 0 == strcmp( $this->mTitle, $wgUser->getName() ) ) {
-                       $wgUser->setNewtalk( 0 );                       
+                       $wgUser->setNewtalk( 0 );
                        $wgUser->saveSettings();
-
                } else {
-                       # Not ours.  If writing, mark it as modified.
-
+                       # Not ours.  If writing, then mark it as modified.
                        $sql = false;
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $user_newtalk = $dbw->tableName( 'user_newtalk' );
-
                        if ( 1 == $this->mAction ) {
-                               $user = new User();                             
+                               $user = new User();
                                $user->setID(User::idFromName($this->mTitle));
-                               if ($id=$user->getID()) {                                                                       
-                                       $sql = "INSERT INTO $user_newtalk (user_id) values ({$id})";
+
+                               if ($id=$user->getID()) {
+                                       $sql = true;
                                        $wgMemc->delete( "$wgDBname:user:id:$id" );
                                } else {
-                                       #anon
-                                       if(preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle)) { #real anon (user:xxx.xxx.xxx.xxx)
-                                               $sql = "INSERT INTO $user_newtalk (user_id,user_ip) values (0,\"{$this->mTitle}\")";            
+                                       if ( $wgUser->isIP($this->mTitle) ) { # anonymous
+                                               $dbw =& wfGetDB( DB_MASTER );
+                                               $dbw->replace( 'watchlist',
+                                                       array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+                                                         array('wl_user'                       => 0,
+                                                               'wl_namespace'                  => NS_USER_TALK,
+                                                               'wl_title'                      => $this->mTitle,
+                                                               'wl_notificationtimestamp'      => 1
+                                                               ), 'UserTalkUpdate'
+                                                       );
+                                               $sql = true;
                                                $wgMemc->delete( "$wgDBname:newtalk:ip:$this->mTitle" );
                                        }
                                }
-                               
-                               if($sql && !$user->getNewtalk()) { # only insert if real user and it's not already there
-                                       $dbw->query( $sql, $fname );
+
+                               if($sql && !$user->getNewtalk() ) {
+                                       # create an artificial watchlist table entry for the owner X of the user_talk page X
+                                       # only insert if X is a real user and the page is not yet watched
+                                       # mark the changed watch-listed page with a timestamp, so that the page is listed with
+                                       # an "updated since your last visit" icon in the watch list, ...
+                                       # ... no matter, if the watching user has or has not indicated an email address in his/her preferences.
+                                       # We memorise the event of sending out a notification and use this as a flag to suppress
+                                       # further mails for changes on the same page for that watching user
+                                       $dbw =& wfGetDB( DB_MASTER );
+                                       $dbw->replace( 'watchlist',
+                                               array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp')),
+                                                 array('wl_user' => $id,
+                                                       'wl_namespace' => NS_USER_TALK,
+                                                       'wl_title' => $this->mTitle,
+                                                       'wl_notificationtimestamp' => 1
+                                                       ), 'UserTalkUpdate'
+                                               );
                                }
                        }
                }