MediaWiki  master
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();
55  $title = self::cleanupForIRC( $title );
56 
57  if ( $attribs['rc_type'] == RC_LOG ) {
58  $url = '';
59  } else {
60  $url = $wgCanonicalServer . $wgScript;
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  [ " ", "" ],
144  );
145  }
146 }
const RC_CATEGORIZE
Definition: Defines.php:142
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1585
$wgScript
The URL path to index.php.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Generates a colourful notification intended for humans on IRC.
const NS_SPECIAL
Definition: Defines.php:49
getLine(array $feed, RecentChange $rc, $actionComment)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
static cleanupForIRC( $text)
Remove newlines, carriage returns and decode html entites.
Interface for RC feed formatters.
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
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:1982
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static decodeCharReferences( $text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string...
Definition: Sanitizer.php:1662
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
const RC_NEW
Definition: Defines.php:139
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
const RC_LOG
Definition: Defines.php:140
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319