r42236 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42235‎ | r42236 | r42237 >
Date:23:59, 19 October 2008
Author:brion
Status:old
Tags:
Comment:
Back out r42182 for now "Move UDP stuff to new UDP class"

UDP isn't a very clear name for this, especially since we use UDP protocols for multiple different things!

This class should probably be genericized a bit for _change notifications_, which there might be multiple backend implementations for, including the UDP->IRC bot gateway.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/UDP.php (deleted) (history)

Diff [purge]

Index: trunk/phase3/includes/UDP.php
@@ -1,37 +0,0 @@
2 -<?php
3 -
4 -class UDP {
5 - /**
6 - * Send some text to UDP
7 - * @param string $line
8 - * @param string $prefix
9 - * @param string $address
10 - * @return bool success
11 - */
12 - public static function sendToUDP( $line, $address = '', $prefix = '' ) {
13 - global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
14 - # Assume default for standard RC case
15 - $address = $address ? $address : $wgRC2UDPAddress;
16 - $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
17 - # Notify external application via UDP
18 - if( $address ) {
19 - $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
20 - if( $conn ) {
21 - $line = $prefix . $line;
22 - socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
23 - socket_close( $conn );
24 - return true;
25 - }
26 - }
27 - return false;
28 - }
29 -
30 - /**
31 - * Remove newlines and carriage returns
32 - * @param string $line
33 - * @return string
34 - */
35 - public static function cleanupForIRC( $text ) {
36 - return str_replace(array("\n", "\r"), array("", ""), $text);
37 - }
38 -}
\ No newline at end of file
Index: trunk/phase3/includes/RecentChange.php
@@ -169,7 +169,7 @@
170170
171171 # Notify external application via UDP
172172 if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
173 - UDP::sendToUDP( $this->getIRCLine() );
 173+ self::sendToUDP( $this->getIRCLine() );
174174 }
175175
176176 # E-mail notifications
@@ -199,6 +199,40 @@
200200 }
201201
202202 /**
 203+ * Send some text to UDP
 204+ * @param string $line
 205+ * @param string $prefix
 206+ * @param string $address
 207+ * @return bool success
 208+ */
 209+ public static function sendToUDP( $line, $address = '', $prefix = '' ) {
 210+ global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
 211+ # Assume default for standard RC case
 212+ $address = $address ? $address : $wgRC2UDPAddress;
 213+ $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
 214+ # Notify external application via UDP
 215+ if( $address ) {
 216+ $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
 217+ if( $conn ) {
 218+ $line = $prefix . $line;
 219+ socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
 220+ socket_close( $conn );
 221+ return true;
 222+ }
 223+ }
 224+ return false;
 225+ }
 226+
 227+ /**
 228+ * Remove newlines and carriage returns
 229+ * @param string $line
 230+ * @return string
 231+ */
 232+ public static function cleanupForIRC( $text ) {
 233+ return str_replace(array("\n", "\r"), array("", ""), $text);
 234+ }
 235+
 236+ /**
203237 * Mark a given change as patrolled
204238 *
205239 * @param mixed $change RecentChange or corresponding rc_id
@@ -568,7 +602,7 @@
569603 $titleObj =& $this->getTitle();
570604 }
571605 $title = $titleObj->getPrefixedText();
572 - $title = UDP::cleanupForIRC( $title );
 606+ $title = self::cleanupForIRC( $title );
573607
574608 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
575609 if( $rc_type == RC_LOG ) {
@@ -595,14 +629,14 @@
596630 $szdiff = '';
597631 }
598632
599 - $user = UDP::cleanupForIRC( $rc_user_text );
 633+ $user = self::cleanupForIRC( $rc_user_text );
600634
601635 if( $rc_type == RC_LOG ) {
602636 $targetText = $this->getTitle()->getPrefixedText();
603 - $comment = UDP::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
 637+ $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
604638 $flag = $rc_log_action;
605639 } else {
606 - $comment = UDP::cleanupForIRC( $rc_comment );
 640+ $comment = self::cleanupForIRC( $rc_comment );
607641 $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
608642 }
609643 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
Index: trunk/phase3/includes/AutoLoader.php
@@ -507,9 +507,6 @@
508508 'WikiRevision' => 'includes/Import.php',
509509 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php',
510510
511 - # UDP logging
512 - 'UDP' => 'includes/UDP.php',
513 -
514511 # includes/templates
515512 'UsercreateTemplate' => 'includes/templates/Userlogin.php',
516513 'UserloginTemplate' => 'includes/templates/Userlogin.php',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r42182Move UDP stuff to new UDP classaaron23:46, 17 October 2008

Status & tagging log