4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
23 * Generates a colourful notification intended for humans on IRC.
28 class IRCColourfulRCFeedFormatter
implements RCFeedFormatter
{
30 * @see RCFeedFormatter::getLine
32 public function getLine( array $feed, RecentChange
$rc, $actionComment ) {
33 global $wgUseRCPatrol, $wgUseNPPatrol, $wgLocalInterwikis,
34 $wgCanonicalServer, $wgScript;
35 $attribs = $rc->getAttributes();
36 if ( $attribs['rc_type'] == RC_LOG
) {
37 // Don't use SpecialPage::getTitleFor, backwards compatibility with
38 // IRC API which expects "Log".
39 $titleObj = Title
::newFromText( 'Log/' . $attribs['rc_log_type'], NS_SPECIAL
);
41 $titleObj =& $rc->getTitle();
43 $title = $titleObj->getPrefixedText();
44 $title = self
::cleanupForIRC( $title );
46 if ( $attribs['rc_type'] == RC_LOG
) {
49 $url = $wgCanonicalServer . $wgScript;
50 if ( $attribs['rc_type'] == RC_NEW
) {
51 $query = '?oldid=' . $attribs['rc_this_oldid'];
53 $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
55 if ( $wgUseRCPatrol ||
( $attribs['rc_type'] == RC_NEW
&& $wgUseNPPatrol ) ) {
56 $query .= '&rcid=' . $attribs['rc_id'];
58 // HACK: We need this hook for WMF's secure server setup
59 wfRunHooks( 'IRCLineURL', array( &$url, &$query, $rc ) );
63 if ( $attribs['rc_old_len'] !== null && $attribs['rc_new_len'] !== null ) {
64 $szdiff = $attribs['rc_new_len'] - $attribs['rc_old_len'];
65 if ( $szdiff < -500 ) {
66 $szdiff = "\002$szdiff\002";
67 } elseif ( $szdiff >= 0 ) {
68 $szdiff = '+' . $szdiff;
70 // @todo i18n with parentheses in content language?
71 $szdiff = '(' . $szdiff . ')';
76 $user = self
::cleanupForIRC( $attribs['rc_user_text'] );
78 if ( $attribs['rc_type'] == RC_LOG
) {
79 $targetText = $rc->getTitle()->getPrefixedText();
80 $comment = self
::cleanupForIRC( str_replace(
82 "[[\00302$targetText\00310]]",
85 $flag = $attribs['rc_log_action'];
87 $comment = self
::cleanupForIRC( $attribs['rc_comment'] );
89 if ( !$attribs['rc_patrolled']
90 && ( $wgUseRCPatrol ||
$attribs['rc_type'] == RC_NEW
&& $wgUseNPPatrol )
94 $flag .= ( $attribs['rc_type'] == RC_NEW ?
"N" : "" )
95 . ( $attribs['rc_minor'] ?
"M" : "" ) . ( $attribs['rc_bot'] ?
"B" : "" );
98 if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) {
99 // we use the first entry in $wgLocalInterwikis in recent changes feeds
100 $prefix = $wgLocalInterwikis[0];
101 } elseif ( $feed['add_interwiki_prefix'] ) {
102 $prefix = $feed['add_interwiki_prefix'];
106 if ( $prefix !== false ) {
107 $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
109 $titleString = "\00314[[\00307$title\00314]]";
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$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
121 * Remove newlines, carriage returns and decode html entites
122 * @param string $text
125 public static function cleanupForIRC( $text ) {
126 return Sanitizer
::decodeCharReferences( str_replace(