MediaWiki master
IRCColourfulRCFeedFormatter.php
Go to the documentation of this file.
1<?php
2
8namespace MediaWiki\RCFeed;
9
15
37 public function getLine( array $feed, RecentChange $rc, $actionComment ) {
39 $recentChangeRCFeedNotifier = $services->getRecentChangeRCFeedNotifier();
40 $mainConfig = $services->getMainConfig();
41 $localInterwikis = $mainConfig->get( MainConfigNames::LocalInterwikis );
42 $useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol );
43 $useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol );
44 $attribs = $rc->getAttributes();
45 if ( $attribs['rc_source'] == RecentChange::SRC_CATEGORIZE ) {
46 // Don't send SRC_CATEGORIZE events to IRC feed (T127360)
47 return null;
48 }
49
50 if ( $attribs['rc_source'] == RecentChange::SRC_LOG ) {
51 // Don't use SpecialPage::getTitleFor, backwards compatibility with
52 // IRC API which expects "Log".
53 $titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL );
54 } else {
55 $titleObj = $rc->getTitle();
56 }
57 $title = $titleObj->getPrefixedText();
58 $title = self::cleanupForIRC( $title );
59
60 $notifyUrl = $recentChangeRCFeedNotifier->getNotifyUrl( $rc ) ?? '';
61
62 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
63 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
64 if ( $szdiff < -500 ) {
65 $szdiff = "\002$szdiff\002";
66 } elseif ( $szdiff >= 0 ) {
67 $szdiff = '+' . $szdiff;
68 }
69 // @todo i18n with parentheses in content language?
70 $szdiff = '(' . $szdiff . ')';
71 } else {
72 $szdiff = '';
73 }
74
75 $user = self::cleanupForIRC( $attribs['rc_user_text'] );
76
77 if ( $attribs['rc_source'] == RecentChange::SRC_LOG ) {
78 $targetText = $rc->getTitle()->getPrefixedText();
79 $comment = self::cleanupForIRC( str_replace(
80 "[[$targetText]]",
81 "[[\00302$targetText\00310]]",
82 $actionComment
83 ) );
84 $flag = $attribs['rc_log_action'];
85 } else {
86 $store = $services->getCommentStore();
87 $comment = self::cleanupForIRC( $store->getComment( 'rc_comment', $attribs )->text );
88 $flag = '';
89 if ( !$attribs['rc_patrolled']
90 && ( $useRCPatrol || ( $attribs['rc_source'] == RecentChange::SRC_NEW && $useNPPatrol ) )
91 ) {
92 $flag .= '!';
93 }
94 $flag .= ( $attribs['rc_source'] == RecentChange::SRC_NEW ? "N" : "" )
95 . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
96 }
97
98 if ( $feed['add_interwiki_prefix'] === true && $localInterwikis ) {
99 // we use the first entry in $wgLocalInterwikis in recent changes feeds
100 $prefix = $localInterwikis[0];
101 } elseif ( $feed['add_interwiki_prefix'] ) {
102 $prefix = $feed['add_interwiki_prefix'];
103 } else {
104 $prefix = false;
105 }
106 if ( $prefix !== false ) {
107 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
108 } else {
109 $titleString = "\00314[[\00307$title\00314]]";
110 }
111
112 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
113 # no colour (\003) switches back to the term default
114 $fullString = "$titleString\0034 $flag\00310 " .
115 "\00302$notifyUrl\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
116
117 return $fullString;
118 }
119
125 public static function cleanupForIRC( $text ) {
126 return str_replace(
127 [ "\n", "\r" ],
128 [ " ", "" ],
129 Sanitizer::decodeCharReferences( $text )
130 );
131 }
132}
134class_alias( IRCColourfulRCFeedFormatter::class, 'IRCColourfulRCFeedFormatter' );
const NS_SPECIAL
Definition Defines.php:40
A class containing constants representing the names of configuration variables.
const UseRCPatrol
Name constant for the UseRCPatrol setting, for use with Config::get()
const UseNPPatrol
Name constant for the UseNPPatrol setting, for use with Config::get()
const LocalInterwikis
Name constant for the LocalInterwikis setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:32
Format a notification as a human-readable string using IRC colour codes.
getLine(array $feed, RecentChange $rc, $actionComment)
static cleanupForIRC( $text)
Remove newlines, carriage returns and decode html entities.
Utility class for creating and reading rows in the recentchanges table.
Represents a title within MediaWiki.
Definition Title.php:69
Interface for RC feed formatters.