X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FRecentChange.php;h=cd8a1b5ba8c2f8963f1228b8a478ac6a7834ddb7;hb=aba5b4c583dcc739d6588c9ce43c7e2560bcdc8d;hp=67bc5307c603fced1653444e9c88014d0dd13df0;hpb=75da88318c532ddfe9c8cdd6c893a0ce39326236;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 67bc5307c6..cd8a1b5ba8 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -1,5 +1,25 @@ 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; @@ -166,7 +185,7 @@ class RecentChange { * @param $noudp bool */ public function save( $noudp = false ) { - global $wgLocalInterwiki, $wgPutIPinRC; + global $wgLocalInterwiki, $wgPutIPinRC, $wgContLang; $dbw = wfGetDB( DB_MASTER ); if( !is_array($this->mExtra) ) { @@ -183,6 +202,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']); @@ -380,12 +402,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, @@ -403,7 +419,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, @@ -444,14 +460,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, @@ -469,7 +477,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, @@ -503,10 +511,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! @@ -514,7 +523,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; } @@ -531,17 +540,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( @@ -560,7 +564,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, @@ -571,10 +575,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; } @@ -672,7 +678,9 @@ class RecentChange { $wgCanonicalServer, $wgScript; if( $this->mAttribs['rc_type'] == RC_LOG ) { - $titleObj = SpecialPage::getTitleFor( 'Log', $this->mAttribs['rc_log_type'] ); + // Don't use SpecialPage::getTitleFor, backwards compatibility with + // IRC API which expects "Log". + $titleObj = Title::newFromText( 'Log/' . $this->mAttribs['rc_log_type'], NS_SPECIAL ); } else { $titleObj =& $this->getTitle(); } @@ -703,6 +711,7 @@ class RecentChange { } elseif($szdiff >= 0) { $szdiff = '+' . $szdiff ; } + // @todo i18n with parentheses in content language? $szdiff = '(' . $szdiff . ')' ; } else { $szdiff = ''; @@ -712,7 +721,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'] ); @@ -763,4 +772,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; + } }