MediaWiki  1.23.2
IRCColourfulRCFeedFormatter.php
Go to the documentation of this file.
1 <?php
2 
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 );
40  } else {
41  $titleObj =& $rc->getTitle();
42  }
43  $title = $titleObj->getPrefixedText();
45 
46  if ( $attribs['rc_type'] == RC_LOG ) {
47  $url = '';
48  } else {
49  $url = $wgCanonicalServer . $wgScript;
50  if ( $attribs['rc_type'] == RC_NEW ) {
51  $query = '?oldid=' . $attribs['rc_this_oldid'];
52  } else {
53  $query = '?diff=' . $attribs['rc_this_oldid'] . '&oldid=' . $attribs['rc_last_oldid'];
54  }
55  if ( $wgUseRCPatrol || ( $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
56  $query .= '&rcid=' . $attribs['rc_id'];
57  }
58  // HACK: We need this hook for WMF's secure server setup
59  wfRunHooks( 'IRCLineURL', array( &$url, &$query, $rc ) );
60  $url .= $query;
61  }
62 
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;
69  }
70  // @todo i18n with parentheses in content language?
71  $szdiff = '(' . $szdiff . ')';
72  } else {
73  $szdiff = '';
74  }
75 
76  $user = self::cleanupForIRC( $attribs['rc_user_text'] );
77 
78  if ( $attribs['rc_type'] == RC_LOG ) {
79  $targetText = $rc->getTitle()->getPrefixedText();
80  $comment = self::cleanupForIRC( str_replace( "[[$targetText]]", "[[\00302$targetText\00310]]", $actionComment ) );
81  $flag = $attribs['rc_log_action'];
82  } else {
83  $comment = self::cleanupForIRC( $attribs['rc_comment'] );
84  $flag = '';
85  if ( !$attribs['rc_patrolled'] && ( $wgUseRCPatrol || $attribs['rc_type'] == RC_NEW && $wgUseNPPatrol ) ) {
86  $flag .= '!';
87  }
88  $flag .= ( $attribs['rc_type'] == RC_NEW ? "N" : "" ) . ( $attribs['rc_minor'] ? "M" : "" ) . ( $attribs['rc_bot'] ? "B" : "" );
89  }
90 
91  if ( $feed['add_interwiki_prefix'] === true && $wgLocalInterwikis ) {
92  // we use the first entry in $wgLocalInterwikis in recent changes feeds
93  $prefix = $wgLocalInterwikis[0];
94  } elseif ( $feed['add_interwiki_prefix'] ) {
95  $prefix = $feed['add_interwiki_prefix'];
96  } else {
97  $prefix = false;
98  }
99  if ( $prefix !== false ) {
100  $titleString = "\00314[[\00303$prefix:\00307$title\00314]]";
101  } else {
102  $titleString = "\00314[[\00307$title\00314]]";
103  }
104 
105  # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
106  # no colour (\003) switches back to the term default
107  $fullString = "$titleString\0034 $flag\00310 " .
108  "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
109 
110  return $fullString;
111  }
112 
118  public static function cleanupForIRC( $text ) {
119  return Sanitizer::decodeCharReferences( str_replace(
120  array( "\n", "\r" ),
121  array( " ", "" ),
122  $text
123  ) );
124  }
125 }
IRCColourfulRCFeedFormatter\getLine
getLine(array $feed, RecentChange $rc, $actionComment)
Definition: IRCColourfulRCFeedFormatter.php:32
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
IRCColourfulRCFeedFormatter
Generates a colourful notification intended for humans on IRC.
Definition: IRCColourfulRCFeedFormatter.php:28
RecentChange\getAttributes
getAttributes()
Definition: RecentChange.php:781
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:63
RC_LOG
const RC_LOG
Definition: Defines.php:181
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$comment
$comment
Definition: importImages.php:107
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
RC_NEW
const RC_NEW
Definition: Defines.php:179
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
IRCColourfulRCFeedFormatter\cleanupForIRC
static cleanupForIRC( $text)
Remove newlines, carriage returns and decode html entites.
Definition: IRCColourfulRCFeedFormatter.php:118
Sanitizer\decodeCharReferences
static decodeCharReferences( $text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string.
Definition: Sanitizer.php:1396
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:200
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
RCFeedFormatter
Interface for RC feed formatters.
Definition: RCFeedFormatter.php:27
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530