2 class IRCColourfulRCFeedFormatter
implements RCFeedFormatter
{
4 * Generates a colourful notification intended for humans on IRC.
5 * @see RCFeedFormatter::getLine
7 public function getLine( array $feed, RecentChange
$rc, $actionComment ) {
8 global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwiki,
9 $wgCanonicalServer, $wgScript;
10 $attribs = $rc->getAttributes();
11 if ( $attribs['rc_type'] == RC_LOG
) {
12 // Don't use SpecialPage::getTitleFor, backwards compatibility with
13 // IRC API which expects "Log".
14 $titleObj = Title
::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL
);
16 $titleObj =& $rc->getTitle();
18 $title = $titleObj->getPrefixedText();
19 $title = self
::cleanupForIRC( $title );
21 if ( $attribs['rc_type'] == RC_LOG
) {
24 $url = $wgCanonicalServer . $wgScript;
25 if ( $attribs['rc_type'] == RC_NEW
) {
26 $query = '?oldid=' . $attribs['rc_this_oldid'];
28 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
30 if ( $wgUseRCPatrol ||
( $attribs['rc_type'] == RC_NEW
&& $wgUseNPPatrol ) ) {
31 $query .= '&rcid=' . $attribs['rc_id'];
33 // HACK: We need this hook for WMF's secure server setup
34 wfRunHooks( 'IRCLineURL', array( &$url, &$query ) );
38 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
39 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
40 if ( $szdiff < -500 ) {
41 $szdiff = "\002$szdiff\002";
42 } elseif ( $szdiff >= 0 ) {
43 $szdiff = '+' . $szdiff;
45 // @todo i18n with parentheses in content language?
46 $szdiff = '(' . $szdiff . ')';
51 $user = self
::cleanupForIRC( $attribs['rc_user_text'] );
53 if ( $attribs['rc_type'] == RC_LOG
) {
54 $targetText = $rc->getTitle()->getPrefixedText();
55 $comment = self
::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $actionComment ) );
56 $flag = $attribs['rc_log_action'];
58 $comment = self
::cleanupForIRC( $attribs['rc_comment'] );
60 if ( !$attribs['rc_patrolled'] && ( $wgUseRCPatrol ||
$attribs['rc_type'] == RC_NEW
&& $wgUseNPPatrol ) ) {
63 $flag .= ( $attribs['rc_type'] == RC_NEW ?
"N" : "" ) . ( $attribs['rc_minor'] ?
"M" : "" ) . ( $attribs['rc_bot'] ?
"B" : "" );
66 if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwiki !== false ) {
67 $prefix = $wgLocalInterwiki;
68 } elseif ( $feed['add_interwiki_prefix'] ) {
69 $prefix = $feed['add_interwiki_prefix'];
73 if ( $prefix !== false ) {
74 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
76 $titleString = "\00314[[\00307$title\00314]]";
79 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
80 # no colour (\003) switches back to the term default
81 $fullString = "$titleString\0034 $flag\00310 " .
82 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
88 * Remove newlines, carriage returns and decode html entites
92 public static function cleanupForIRC( $text ) {
93 return Sanitizer
::decodeCharReferences( str_replace(