MediaWiki REL1_34
IRCColourfulRCFeedFormatter.php
Go to the documentation of this file.
1<?php
2
23
38 public function getLine( array $feed, RecentChange $rc, $actionComment ) {
41 $attribs = $rc->getAttributes();
42 if ( $attribs['rc_type'] == RC_CATEGORIZE ) {
43 // Don't send RC_CATEGORIZE events to IRC feed (T127360)
44 return null;
45 }
46
47 if ( $attribs['rc_type'] == RC_LOG ) {
48 // Don't use SpecialPage::getTitleFor, backwards compatibility with
49 // IRC API which expects "Log".
50 $titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL );
51 } else {
52 $titleObj =& $rc->getTitle();
53 }
54 $title = $titleObj->getPrefixedText();
56
57 if ( $attribs['rc_type'] == RC_LOG ) {
58 $url = '';
59 } else {
61 if ( $attribs['rc_type'] == RC_NEW ) {
62 $query = '?oldid=' . $attribs['rc_this_oldid'];
63 } else {
64 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
65 }
66 if ( $wgUseRCPatrol || ( $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
67 $query .= '&rcid=' . $attribs['rc_id'];
68 }
69 // HACK: We need this hook for WMF's secure server setup
70 Hooks::run( 'IRCLineURL', [ &$url, &$query, $rc ] );
71 $url .= $query;
72 }
73
74 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
75 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
76 if ( $szdiff < -500 ) {
77 $szdiff = "\002$szdiff\002";
78 } elseif ( $szdiff >= 0 ) {
79 $szdiff = '+' . $szdiff;
80 }
81 // @todo i18n with parentheses in content language?
82 $szdiff = '(' . $szdiff . ')';
83 } else {
84 $szdiff = '';
85 }
86
87 $user = self::cleanupForIRC( $attribs['rc_user_text'] );
88
89 if ( $attribs['rc_type'] == RC_LOG ) {
90 $targetText = $rc->getTitle()->getPrefixedText();
91 $comment = self::cleanupForIRC( str_replace(
92 "[[$targetText]]",
93 "[[\00302$targetText\00310]]",
94 $actionComment
95 ) );
96 $flag = $attribs['rc_log_action'];
97 } else {
98 $store = MediaWikiServices::getInstance()->getCommentStore();
99 $comment = self::cleanupForIRC(
100 $store->getComment( 'rc_comment', $attribs )->text
101 );
102 $flag = '';
103 if ( !$attribs['rc_patrolled']
104 && ( $wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol )
105 ) {
106 $flag .= '!';
107 }
108 $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" )
109 . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
110 }
111
112 if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) {
113 // we use the first entry in $wgLocalInterwikis in recent changes feeds
114 $prefix = $wgLocalInterwikis[0];
115 } elseif ( $feed['add_interwiki_prefix'] ) {
116 $prefix = $feed['add_interwiki_prefix'];
117 } else {
118 $prefix = false;
119 }
120 if ( $prefix !== false ) {
121 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
122 } else {
123 $titleString = "\00314[[\00307$title\00314]]";
124 }
125
126 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
127 # no colour (\003) switches back to the term default
128 $fullString = "$titleString\0034 $flag\00310 " .
129 "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
130
131 return $fullString;
132 }
133
139 public static function cleanupForIRC( $text ) {
140 return str_replace(
141 [ "\n", "\r" ],
142 [ " ", "" ],
143 Sanitizer::decodeCharReferences( $text )
144 );
145 }
146}
$wgScript
The URL path to index.php.
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
Generates a colourful notification intended for humans on IRC.
static cleanupForIRC( $text)
Remove newlines, carriage returns and decode html entities.
getLine(array $feed, RecentChange $rc, $actionComment)
MediaWikiServices is the service locator for the application scope of MediaWiki.
Utility class for creating new RC entries.
const RC_NEW
Definition Defines.php:132
const NS_SPECIAL
Definition Defines.php:58
const RC_LOG
Definition Defines.php:133
const RC_CATEGORIZE
Definition Defines.php:135
Interface for RC feed formatters.