Minor log-related changes for documentation and to support a potential extension
[lhc/web/wiklou.git] / includes / RecentChange.php
index 1fe814e..f5d64bd 100644 (file)
@@ -1,7 +1,4 @@
 <?php
-/**
- *
- */
 
 /**
  * Utility class for creating new RC entries
@@ -59,10 +56,10 @@ class RecentChange
                return $rc;
        }
 
-       public static function newFromCurRow( $row, $rc_this_oldid = 0 )
+       public static function newFromCurRow( $row )
        {
                $rc = new RecentChange;
-               $rc->loadFromCurRow( $row, $rc_this_oldid );
+               $rc->loadFromCurRow( $row );
                $rc->notificationtimestamp = false;
                $rc->numberofWatchingusers = false;
                return $rc;
@@ -143,7 +140,8 @@ class RecentChange
        # Writes the data in this object to the database
        function save()
        {
-               global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix;
+               global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, 
+               $wgRC2UDPPort, $wgRC2UDPPrefix, $wgRC2UDPOmitBots;
                $fname = 'RecentChange::save';
 
                $dbw = wfGetDB( DB_MASTER );
@@ -212,7 +210,7 @@ class RecentChange
                }
 
                # Notify external application via UDP
-               if ( $wgRC2UDPAddress ) {
+               if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
                        $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
                        if ( $conn ) {
                                $line = $wgRC2UDPPrefix . $this->getIRCLine();
@@ -222,13 +220,21 @@ class RecentChange
                }
 
                # E-mail notifications
-               global $wgUseEnotif;
-               if( $wgUseEnotif ) {
-                       # this would be better as an extension hook
-                       global $wgUser;
-                       $enotif = new EmailNotification;
+               global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
+               if( $wgUseEnotif || $wgShowUpdatedMarker ) {
+                       // Users
+                       if( $this->mAttribs['rc_user'] ) {
+                               $editor = ($wgUser->getId() == $this->mAttribs['rc_user']) ? 
+                                       $wgUser : User::newFromID( $this->mAttribs['rc_user'] );
+                       // Anons
+                       } else {
+                               $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ? 
+                                       $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
+                       }
+                       # FIXME: this would be better as an extension hook
+                       $enotif = new EmailNotification();
                        $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
-                       $enotif->notifyOnPageChange( $wgUser, $title,
+                       $enotif->notifyOnPageChange( $editor, $title,
                                $this->mAttribs['rc_timestamp'],
                                $this->mAttribs['rc_comment'],
                                $this->mAttribs['rc_minor'],
@@ -283,8 +289,8 @@ class RecentChange
                        'rc_title'      => $title->getDBkey(),
                        'rc_type'       => RC_EDIT,
                        'rc_minor'      => $minor ? 1 : 0,
-                       'rc_cur_id'     => $action === 'delete' ? 0 : $target->getArticleID(),
-                       'rc_user'       => $user->getID(),
+                       'rc_cur_id'     => $title->getArticleID(),
+                       'rc_user'       => $user->getId(),
                        'rc_user_text'  => $user->getName(),
                        'rc_comment'    => $comment,
                        'rc_this_oldid' => $newId,
@@ -338,7 +344,7 @@ class RecentChange
                        'rc_type'           => RC_NEW,
                        'rc_minor'          => $minor ? 1 : 0,
                        'rc_cur_id'         => $title->getArticleID(),
-                       'rc_user'           => $user->getID(),
+                       'rc_user'           => $user->getId(),
                        'rc_user_text'      => $user->getName(),
                        'rc_comment'        => $comment,
                        'rc_this_oldid'     => $newId,
@@ -389,7 +395,7 @@ class RecentChange
                        'rc_type'       => $overRedir ? RC_MOVE_OVER_REDIRECT : RC_MOVE,
                        'rc_minor'      => 0,
                        'rc_cur_id'     => $oldTitle->getArticleID(),
-                       'rc_user'       => $user->getID(),
+                       'rc_user'       => $user->getId(),
                        'rc_user_text'  => $user->getName(),
                        'rc_comment'    => $comment,
                        'rc_this_oldid' => 0,
@@ -425,7 +431,6 @@ class RecentChange
                RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
        }
 
-       # A log entry is different to an edit in that previous revisions are not kept
        public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
           $type, $action, $target, $logComment, $params, $newId=0 )
        {
@@ -447,7 +452,7 @@ class RecentChange
                        'rc_type'       => RC_LOG,
                        'rc_minor'      => 0,
                        'rc_cur_id'     => $target->getArticleID(),
-                       'rc_user'       => $user->getID(),
+                       'rc_user'       => $user->getId(),
                        'rc_user_text'  => $user->getName(),
                        'rc_comment'    => $logComment,
                        'rc_this_oldid' => 0,
@@ -601,7 +606,7 @@ class RecentChange
                        $flag = $rc_log_action;
                } else {
                        $comment = $this->cleanupForIRC( $rc_comment );
-                       $flag = ($rc_minor ? "M" : "") . ($rc_new ? "N" : "");
+                       $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
                }
                # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
                # no colour (\003) switches back to the term default