MediaWiki
REL1_22
|
00001 <?php 00002 class IRCColourfulRCFeedFormatter implements RCFeedFormatter { 00007 public function getLine( array $feed, RecentChange $rc, $actionComment ) { 00008 global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwiki, 00009 $wgCanonicalServer, $wgScript; 00010 $attribs = $rc->getAttributes(); 00011 if ( $attribs['rc_type'] == RC_LOG ) { 00012 // Don't use SpecialPage::getTitleFor, backwards compatibility with 00013 // IRC API which expects "Log". 00014 $titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL ); 00015 } else { 00016 $titleObj =& $rc->getTitle(); 00017 } 00018 $title = $titleObj->getPrefixedText(); 00019 $title = self::cleanupForIRC( $title ); 00020 00021 if ( $attribs['rc_type'] == RC_LOG ) { 00022 $url = ''; 00023 } else { 00024 $url = $wgCanonicalServer . $wgScript; 00025 if ( $attribs['rc_type'] == RC_NEW ) { 00026 $query = '?oldid=' . $attribs['rc_this_oldid']; 00027 } else { 00028 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid']; 00029 } 00030 if ( $wgUseRCPatrol || ( $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) { 00031 $query .= '&rcid=' . $attribs['rc_id']; 00032 } 00033 // HACK: We need this hook for WMF's secure server setup 00034 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) ); 00035 $url .= $query; 00036 } 00037 00038 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) { 00039 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len']; 00040 if ( $szdiff < -500 ) { 00041 $szdiff = "\002$szdiff\002"; 00042 } elseif ( $szdiff >= 0 ) { 00043 $szdiff = '+' . $szdiff; 00044 } 00045 // @todo i18n with parentheses in content language? 00046 $szdiff = '(' . $szdiff . ')'; 00047 } else { 00048 $szdiff = ''; 00049 } 00050 00051 $user = self::cleanupForIRC( $attribs['rc_user_text'] ); 00052 00053 if ( $attribs['rc_type'] == RC_LOG ) { 00054 $targetText = $rc->getTitle()->getPrefixedText(); 00055 $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $actionComment ) ); 00056 $flag = $attribs['rc_log_action']; 00057 } else { 00058 $comment = self::cleanupForIRC( $attribs['rc_comment'] ); 00059 $flag = ''; 00060 if ( !$attribs['rc_patrolled'] && ( $wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) { 00061 $flag .= '!'; 00062 } 00063 $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" ) . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" ); 00064 } 00065 00066 if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwiki !== false ) { 00067 $prefix = $wgLocalInterwiki; 00068 } elseif ( $feed['add_interwiki_prefix'] ) { 00069 $prefix = $feed['add_interwiki_prefix']; 00070 } else { 00071 $prefix = false; 00072 } 00073 if ( $prefix !== false ) { 00074 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]"; 00075 } else { 00076 $titleString = "\00314[[\00307$title\00314]]"; 00077 } 00078 00079 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003, 00080 # no colour (\003) switches back to the term default 00081 $fullString = "$titleString\0034 $flag\00310 " . 00082 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n"; 00083 00084 return $fullString; 00085 } 00086 00092 public static function cleanupForIRC( $text ) { 00093 return Sanitizer::decodeCharReferences( str_replace( 00094 array( "\n", "\r" ), 00095 array( " ", "" ), 00096 $text 00097 ) ); 00098 } 00099 }