MediaWiki  REL1_24
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(
00081                 "[[$targetText]]",
00082                 "[[\00302$targetText\00310]]",
00083                 $actionComment
00084             ) );
00085             $flag = $attribs['rc_log_action'];
00086         } else {
00087             $comment = self::cleanupForIRC( $attribs['rc_comment'] );
00088             $flag = '';
00089             if ( !$attribs['rc_patrolled']
00090                 && ( $wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol )
00091             ) {
00092                 $flag .= '!';
00093             }
00094             $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" )
00095                 . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
00096         }
00097 
00098         if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) {
00099             // we use the first entry in $wgLocalInterwikis in recent changes feeds
00100             $prefix = $wgLocalInterwikis[0];
00101         } elseif ( $feed['add_interwiki_prefix'] ) {
00102             $prefix = $feed['add_interwiki_prefix'];
00103         } else {
00104             $prefix = false;
00105         }
00106         if ( $prefix !== false ) {
00107             $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
00108         } else {
00109             $titleString = "\00314[[\00307$title\00314]]";
00110         }
00111 
00112         # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
00113         # no colour (\003) switches back to the term default
00114         $fullString = "$titleString\0034 $flag\00310 " .
00115             "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
00116 
00117         return $fullString;
00118     }
00119 
00125     public static function cleanupForIRC( $text ) {
00126         return Sanitizer::decodeCharReferences( str_replace(
00127             array( "\n", "\r" ),
00128             array( " ", "" ),
00129             $text
00130         ) );
00131     }
00132 }