MediaWiki  REL1_23
IRCColourfulRCFeedFormatter.php
Go to the documentation of this file.
00001 <?php
00002 
00028 class IRCColourfulRCFeedFormatter implements RCFeedFormatter {
00032     public function getLine( array $feed, RecentChange $rc, $actionComment ) {
00033         global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwikis,
00034             $wgCanonicalServer, $wgScript;
00035         $attribs = $rc->getAttributes();
00036         if ( $attribs['rc_type'] == RC_LOG ) {
00037             // Don't use SpecialPage::getTitleFor, backwards compatibility with
00038             // IRC API which expects "Log".
00039             $titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL );
00040         } else {
00041             $titleObj =& $rc->getTitle();
00042         }
00043         $title = $titleObj->getPrefixedText();
00044         $title = self::cleanupForIRC( $title );
00045 
00046         if ( $attribs['rc_type'] == RC_LOG ) {
00047             $url = '';
00048         } else {
00049             $url = $wgCanonicalServer . $wgScript;
00050             if ( $attribs['rc_type'] == RC_NEW ) {
00051                 $query = '?oldid=' . $attribs['rc_this_oldid'];
00052             } else {
00053                 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
00054             }
00055             if ( $wgUseRCPatrol || ( $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
00056                 $query .= '&rcid=' . $attribs['rc_id'];
00057             }
00058             // HACK: We need this hook for WMF's secure server setup
00059             wfRunHooks( 'IRCLineURL', array( &$url, &$query, $rc ) );
00060             $url .= $query;
00061         }
00062 
00063         if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
00064             $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
00065             if ( $szdiff < -500 ) {
00066                 $szdiff = "\002$szdiff\002";
00067             } elseif ( $szdiff >= 0 ) {
00068                 $szdiff = '+' . $szdiff;
00069             }
00070             // @todo i18n with parentheses in content language?
00071             $szdiff = '(' . $szdiff . ')';
00072         } else {
00073             $szdiff = '';
00074         }
00075 
00076         $user = self::cleanupForIRC( $attribs['rc_user_text'] );
00077 
00078         if ( $attribs['rc_type'] == RC_LOG ) {
00079             $targetText = $rc->getTitle()->getPrefixedText();
00080             $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $actionComment ) );
00081             $flag = $attribs['rc_log_action'];
00082         } else {
00083             $comment = self::cleanupForIRC( $attribs['rc_comment'] );
00084             $flag = '';
00085             if ( !$attribs['rc_patrolled'] && ( $wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
00086                 $flag .= '!';
00087             }
00088             $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" ) . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
00089         }
00090 
00091         if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) {
00092             // we use the first entry in $wgLocalInterwikis in recent changes feeds
00093             $prefix = $wgLocalInterwikis[0];
00094         } elseif ( $feed['add_interwiki_prefix'] ) {
00095             $prefix = $feed['add_interwiki_prefix'];
00096         } else {
00097             $prefix = false;
00098         }
00099         if ( $prefix !== false ) {
00100             $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
00101         } else {
00102             $titleString = "\00314[[\00307$title\00314]]";
00103         }
00104 
00105         # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
00106         # no colour (\003) switches back to the term default
00107         $fullString = "$titleString\0034 $flag\00310 " .
00108             "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
00109 
00110         return $fullString;
00111     }
00112 
00118     public static function cleanupForIRC( $text ) {
00119         return Sanitizer::decodeCharReferences( str_replace(
00120             array( "\n", "\r" ),
00121             array( " ", "" ),
00122             $text
00123         ) );
00124     }
00125 }