MediaWiki REL1_39
IRCColourfulRCFeedFormatter.php
Go to the documentation of this file.
1<?php
2
24
46 public function getLine( array $feed, RecentChange $rc, $actionComment ) {
47 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
48 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
49 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
50 $localInterwikis = $mainConfig->get( MainConfigNames::LocalInterwikis );
51 $canonicalServer = $mainConfig->get( MainConfigNames::CanonicalServer );
52 $script = $mainConfig->get( MainConfigNames::Script );
53 $attribs = $rc->getAttributes();
54 if ( $attribs['rc_type'] == RC_CATEGORIZE ) {
55 // Don't send RC_CATEGORIZE events to IRC feed (T127360)
56 return null;
57 }
58
59 if ( $attribs['rc_type'] == RC_LOG ) {
60 // Don't use SpecialPage::getTitleFor, backwards compatibility with
61 // IRC API which expects "Log".
62 $titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL );
63 } else {
64 $titleObj = $rc->getTitle();
65 }
66 $title = $titleObj->getPrefixedText();
68
69 if ( $attribs['rc_type'] == RC_LOG ) {
70 $url = '';
71 } else {
72 $url = $canonicalServer . $script;
73 if ( $attribs['rc_type'] == RC_NEW ) {
74 $query = '?oldid=' . $attribs['rc_this_oldid'];
75 } else {
76 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
77 }
78 if ( $useRCPatrol || ( $attribs['rc_type'] == RC_NEW && $useNPPatrol ) ) {
79 $query .= '&rcid=' . $attribs['rc_id'];
80 }
81
82 Hooks::runner()->onIRCLineURL( $url, $query, $rc );
83 $url .= $query;
84 }
85
86 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
87 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
88 if ( $szdiff < -500 ) {
89 $szdiff = "\002$szdiff\002";
90 } elseif ( $szdiff >= 0 ) {
91 $szdiff = '+' . $szdiff;
92 }
93 // @todo i18n with parentheses in content language?
94 $szdiff = '(' . $szdiff . ')';
95 } else {
96 $szdiff = '';
97 }
98
99 $user = self::cleanupForIRC( $attribs['rc_user_text'] );
100
101 if ( $attribs['rc_type'] == RC_LOG ) {
102 $targetText = $rc->getTitle()->getPrefixedText();
103 $comment = self::cleanupForIRC( str_replace(
104 "[[$targetText]]",
105 "[[\00302$targetText\00310]]",
106 $actionComment
107 ) );
108 $flag = $attribs['rc_log_action'];
109 } else {
110 $store = MediaWikiServices::getInstance()->getCommentStore();
111 $comment = self::cleanupForIRC( $store->getComment( 'rc_comment', $attribs )->text );
112 $flag = '';
113 if ( !$attribs['rc_patrolled']
114 && ( $useRCPatrol || $attribs['rc_type'] == RC_NEW && $useNPPatrol )
115 ) {
116 $flag .= '!';
117 }
118 $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" )
119 . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
120 }
121
122 if ( $feed['add_interwiki_prefix'] === true && $localInterwikis ) {
123 // we use the first entry in $wgLocalInterwikis in recent changes feeds
124 $prefix = $localInterwikis[0];
125 } elseif ( $feed['add_interwiki_prefix'] ) {
126 $prefix = $feed['add_interwiki_prefix'];
127 } else {
128 $prefix = false;
129 }
130 if ( $prefix !== false ) {
131 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
132 } else {
133 $titleString = "\00314[[\00307$title\00314]]";
134 }
135
136 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
137 # no colour (\003) switches back to the term default
138 $fullString = "$titleString\0034 $flag\00310 " .
139 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
140
141 return $fullString;
142 }
143
149 public static function cleanupForIRC( $text ) {
150 return str_replace(
151 [ "\n", "\r" ],
152 [ " ", "" ],
153 Sanitizer::decodeCharReferences( $text )
154 );
155 }
156}
const RC_NEW
Definition Defines.php:117
const NS_SPECIAL
Definition Defines.php:53
const RC_LOG
Definition Defines.php:118
const RC_CATEGORIZE
Definition Defines.php:120
Format a notification as a human-readable string using IRC colour codes.
static cleanupForIRC( $text)
Remove newlines, carriage returns and decode html entities.
getLine(array $feed, RecentChange $rc, $actionComment)
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
Utility class for creating new RC entries.
Interface for RC feed formatters.