Fix newline in the message per CR
[lhc/web/wiklou.git] / includes / RecentChange.php
index fd5325c..e57efae 100644 (file)
@@ -55,6 +55,7 @@ class RecentChange {
         */
        var $mMovedToTitle = false;
        var $numberofWatchingusers = 0 ; # Dummy to prevent error message in SpecialRecentchangeslinked
+       var $notificationtimestamp;
 
        # Factory methods
 
@@ -69,7 +70,7 @@ class RecentChange {
        }
 
        /**
-        * @staticw
+        * @param $row
         * @return RecentChange
         */
        public static function newFromCurRow( $row ) {
@@ -88,9 +89,8 @@ class RecentChange {
         */
        public static function newFromId( $rcid ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
-               if( $res && $dbr->numRows( $res ) > 0 ) {
-                       $row = $dbr->fetchObject( $res );
+               $row = $dbr->selectRow( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
+               if( $row !== false ) {
                        return self::newFromRow( $row );
                } else {
                        return null;
@@ -104,9 +104,7 @@ class RecentChange {
         * @param $fname Mixed: override the method name in profiling/logs
         * @return RecentChange
         */
-       public static function newFromConds( $conds, $fname = false ) {
-               if( $fname === false )
-                       $fname = __METHOD__;
+       public static function newFromConds( $conds, $fname = __METHOD__ ) {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select(
                        'recentchanges',
@@ -124,10 +122,16 @@ class RecentChange {
 
        # Accessors
 
+       /**
+        * @param $attribs array
+        */
        public function setAttribs( $attribs ) {
                $this->mAttribs = $attribs;
        }
 
+       /**
+        * @param $extra array
+        */
        public function setExtra( $extra ) {
                $this->mExtra = $extra;
        }
@@ -158,10 +162,10 @@ class RecentChange {
 
        /**
         * Writes the data in this object to the database
-        * @param $noudp bool 
+        * @param $noudp bool
         */
        public function save( $noudp = false ) {
-               global $wgLocalInterwiki, $wgPutIPinRC;
+               global $wgLocalInterwiki, $wgPutIPinRC, $wgContLang;
 
                $dbw = wfGetDB( DB_MASTER );
                if( !is_array($this->mExtra) ) {
@@ -178,6 +182,9 @@ class RecentChange {
                        unset( $this->mAttribs['rc_ip'] );
                }
 
+               # Make sure summary is truncated (whole multibyte characters)
+               $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 );
+
                # Fixup database timestamps
                $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
                $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
@@ -199,7 +206,7 @@ class RecentChange {
 
                # Notify external application via UDP
                if ( !$noudp ) {
-                       $this->notifyRC2UDP()
+                       $this->notifyRC2UDP();
                }
 
                # E-mail notifications
@@ -214,10 +221,11 @@ class RecentChange {
                                $editor = ($wgUser->getName() == $this->mAttribs['rc_user_text']) ?
                                        $wgUser : User::newFromName( $this->mAttribs['rc_user_text'], false );
                        }
+                       $title = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
+
                        # @todo 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( $editor, $title,
+                       $status = $enotif->notifyOnPageChange( $editor, $title,
                                $this->mAttribs['rc_timestamp'],
                                $this->mAttribs['rc_comment'],
                                $this->mAttribs['rc_minor'],
@@ -330,7 +338,7 @@ class RecentChange {
                // Actually set the 'patrolled' flag in RC
                $this->reallyMarkPatrolled();
                // Log this patrol event
-               PatrolLog::record( $this, $auto );
+               PatrolLog::record( $this, $auto, $user );
                wfRunHooks( 'MarkPatrolledComplete', array($this->getAttribute('rc_id'), &$user, false) );
                return array();
        }
@@ -374,12 +382,6 @@ class RecentChange {
         */
        public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
                $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 ) {
-               global $wgRequest;
-               if( !$ip ) {
-                       $ip = $wgRequest->getIP();
-                       if( !$ip ) $ip = '';
-               }
-
                $rc = new RecentChange;
                $rc->mAttribs = array(
                        'rc_timestamp'  => $timestamp,
@@ -397,7 +399,7 @@ class RecentChange {
                        'rc_bot'        => $bot ? 1 : 0,
                        'rc_moved_to_ns' => 0,
                        'rc_moved_to_title' => '',
-                       'rc_ip'         => $ip,
+                       'rc_ip'         => self::checkIPAddress( $ip ),
                        'rc_patrolled'  => intval($patrol),
                        'rc_new'        => 0,  # obsolete
                        'rc_old_len'    => $oldSize,
@@ -438,12 +440,6 @@ class RecentChange {
         */
        public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
                $ip='', $size=0, $newId=0, $patrol=0 ) {
-               global $wgRequest;
-               if( !$ip ) {
-                       $ip = $wgRequest->getIP();
-                       if( !$ip ) $ip = '';
-               }
-
                $rc = new RecentChange;
                $rc->mAttribs = array(
                        'rc_timestamp'      => $timestamp,
@@ -461,7 +457,7 @@ class RecentChange {
                        'rc_bot'            => $bot ? 1 : 0,
                        'rc_moved_to_ns'    => 0,
                        'rc_moved_to_title' => '',
-                       'rc_ip'             => $ip,
+                       'rc_ip'             => self::checkIPAddress( $ip ),
                        'rc_patrolled'      => intval($patrol),
                        'rc_new'            => 1, # obsolete
                        'rc_old_len'        => 0,
@@ -495,10 +491,11 @@ class RecentChange {
         * @param $logComment
         * @param $params
         * @param $newId int
+        * @param $actionCommentIRC string
         * @return bool
         */
-       public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='', $type,
-               $action, $target, $logComment, $params, $newId=0 )
+       public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
+               $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' )
        {
                global $wgLogRestrictions;
                # Don't add private logs to RC!
@@ -506,7 +503,7 @@ class RecentChange {
                        return false;
                }
                $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
-                       $target, $logComment, $params, $newId );
+                       $target, $logComment, $params, $newId, $actionCommentIRC );
                $rc->save();
                return true;
        }
@@ -523,17 +520,12 @@ class RecentChange {
         * @param $logComment
         * @param $params
         * @param $newId int
+        * @param $actionCommentIRC string
         * @return RecentChange
         */
-       public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
-               $type, $action, $target, $logComment, $params, $newId=0 ) {
+       public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
+               $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='' ) {
                global $wgRequest;
-               if( !$ip ) {
-                       $ip = $wgRequest->getIP();
-                       if( !$ip ) {
-                               $ip = '';
-                       }
-               }
 
                $rc = new RecentChange;
                $rc->mAttribs = array(
@@ -552,7 +544,7 @@ class RecentChange {
                        'rc_bot'        => $user->isAllowed( 'bot' ) ? $wgRequest->getBool( 'bot', true ) : 0,
                        'rc_moved_to_ns' => 0,
                        'rc_moved_to_title' => '',
-                       'rc_ip'         => $ip,
+                       'rc_ip'         => self::checkIPAddress( $ip ),
                        'rc_patrolled'  => 1,
                        'rc_new'        => 0, # obsolete
                        'rc_old_len'    => null,
@@ -563,10 +555,12 @@ class RecentChange {
                        'rc_log_action' => $action,
                        'rc_params'     => $params
                );
+
                $rc->mExtra =  array(
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
+                       'actionCommentIRC' => $actionCommentIRC
                );
                return $rc;
        }
@@ -695,6 +689,7 @@ class RecentChange {
                        } elseif($szdiff >= 0) {
                                $szdiff = '+' . $szdiff ;
                        }
+                       // @todo i18n with parentheses in content language?
                        $szdiff = '(' . $szdiff . ')' ;
                } else {
                        $szdiff = '';
@@ -704,7 +699,7 @@ class RecentChange {
 
                if ( $this->mAttribs['rc_type'] == RC_LOG ) {
                        $targetText = $this->getTitle()->getPrefixedText();
-                       $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionComment'] ) );
+                       $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $this->mExtra['actionCommentIRC'] ) );
                        $flag = $this->mAttribs['rc_log_action'];
                } else {
                        $comment = self::cleanupForIRC( $this->mAttribs['rc_comment'] );
@@ -731,7 +726,7 @@ class RecentChange {
                # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
                # no colour (\003) switches back to the term default
                $fullString = "$titleString\0034 $flag\00310 " .
-                             "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
+                                         "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
 
                return $fullString;
        }
@@ -755,4 +750,18 @@ class RecentChange {
                }
                return ChangesList::showCharacterDifference( $old, $new );
        }
+
+       private static function checkIPAddress( $ip ) {
+               global $wgRequest;
+               if ( $ip ) {
+                       if ( !IP::isIPAddress( $ip ) ) {
+                               throw new MWException( "Attempt to write \"" . $ip . "\" as an IP address into recent changes" );
+                       }
+               } else {
+                       $ip = $wgRequest->getIP();
+                       if( !$ip ) 
+                               $ip = '';
+               }
+               return $ip;
+       }
 }