| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\RCFeed; |
| 23 |
|
| 24 |
use MediaWiki\MainConfigNames; |
| 25 |
use MediaWiki\MediaWikiServices; |
| 26 |
use MediaWiki\Parser\Sanitizer; |
| 27 |
use MediaWiki\Title\Title; |
| 28 |
use RecentChange; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
class IRCColourfulRCFeedFormatter implements RCFeedFormatter { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function getLine( array $feed, RecentChange $rc, $actionComment ) { |
| 52 |
$services = MediaWikiServices::getInstance(); |
| 53 |
$mainConfig = $services->getMainConfig(); |
| 54 |
$localInterwikis = $mainConfig->get( MainConfigNames::LocalInterwikis ); |
| 55 |
$useRCPatrol = $mainConfig->get( MainConfigNames::UseRCPatrol ); |
| 56 |
$useNPPatrol = $mainConfig->get( MainConfigNames::UseNPPatrol ); |
| 57 |
$attribs = $rc->getAttributes(); |
| 58 |
if ( $attribs['rc_type'] == RC_CATEGORIZE ) { |
| 59 |
|
| 60 |
return null; |
| 61 |
} |
| 62 |
|
| 63 |
if ( $attribs['rc_type'] == RC_LOG ) { |
| 64 |
|
| 65 |
|
| 66 |
$titleObj = Title::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL ); |
| 67 |
} else { |
| 68 |
$titleObj = $rc->getTitle(); |
| 69 |
} |
| 70 |
$title = $titleObj->getPrefixedText(); |
| 71 |
$title = self::cleanupForIRC( $title ); |
| 72 |
|
| 73 |
$notifyUrl = $rc->getNotifyUrl() ?? ''; |
| 74 |
|
| 75 |
if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) { |
| 76 |
$szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len']; |
| 77 |
if ( $szdiff < -500 ) { |
| 78 |
$szdiff = "\002$szdiff\002"; |
| 79 |
} elseif ( $szdiff >= 0 ) { |
| 80 |
$szdiff = '+' . $szdiff; |
| 81 |
} |
| 82 |
|
| 83 |
$szdiff = '(' . $szdiff . ')'; |
| 84 |
} else { |
| 85 |
$szdiff = ''; |
| 86 |
} |
| 87 |
|
| 88 |
$user = self::cleanupForIRC( $attribs['rc_user_text'] ); |
| 89 |
|
| 90 |
if ( $attribs['rc_type'] == RC_LOG ) { |
| 91 |
$targetText = $rc->getTitle()->getPrefixedText(); |
| 92 |
$comment = self::cleanupForIRC( str_replace( |
| 93 |
"[[$targetText]]", |
| 94 |
"[[\00302$targetText\00310]]", |
| 95 |
$actionComment |
| 96 |
) ); |
| 97 |
$flag = $attribs['rc_log_action']; |
| 98 |
} else { |
| 99 |
$store = $services->getCommentStore(); |
| 100 |
$comment = self::cleanupForIRC( $store->getComment( 'rc_comment', $attribs )->text ); |
| 101 |
$flag = ''; |
| 102 |
if ( !$attribs['rc_patrolled'] |
| 103 |
&& ( $useRCPatrol || ( $attribs['rc_type'] == RC_NEW && $useNPPatrol ) ) |
| 104 |
) { |
| 105 |
$flag .= '!'; |
| 106 |
} |
| 107 |
$flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" ) |
| 108 |
. ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" ); |
| 109 |
} |
| 110 |
|
| 111 |
if ( $feed['add_interwiki_prefix'] === true && $localInterwikis ) { |
| 112 |
|
| 113 |
$prefix = $localInterwikis[0]; |
| 114 |
} elseif ( $feed['add_interwiki_prefix'] ) { |
| 115 |
$prefix = $feed['add_interwiki_prefix']; |
| 116 |
} else { |
| 117 |
$prefix = false; |
| 118 |
} |
| 119 |
if ( $prefix !== false ) { |
| 120 |
$titleString = "\00314[[\00303$prefix:\00307$title\00314]]"; |
| 121 |
} else { |
| 122 |
$titleString = "\00314[[\00307$title\00314]]"; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
$fullString = "$titleString\0034 $flag\00310 " . |
| 128 |
"\00302$notifyUrl\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n"; |
| 129 |
|
| 130 |
return $fullString; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public static function cleanupForIRC( $text ) { |
| 139 |
return str_replace( |
| 140 |
[ "\n", "\r" ], |
| 141 |
[ " ", "" ], |
| 142 |
Sanitizer::decodeCharReferences( $text ) |
| 143 |
); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
class_alias( IRCColourfulRCFeedFormatter::class, 'IRCColourfulRCFeedFormatter' ); |