r42182 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42181‎ | r42182 | r42183 >
Date:23:46, 17 October 2008
Author:aaron
Status:old (Comments)
Tags:
Comment:
Move UDP stuff to new UDP class
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/UDP.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/RecentChange.php
@@ -176,7 +176,7 @@
177177
178178 # Notify external application via UDP
179179 if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
180 - self::sendToUDP( $this->getIRCLine() );
 180+ UDP::sendToUDP( $this->getIRCLine() );
181181 }
182182
183183 # E-mail notifications
@@ -206,40 +206,6 @@
207207 }
208208
209209 /**
210 - * Send some text to UDP
211 - * @param string $line
212 - * @param string $prefix
213 - * @param string $address
214 - * @return bool success
215 - */
216 - public static function sendToUDP( $line, $address = '', $prefix = '' ) {
217 - global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
218 - # Assume default for standard RC case
219 - $address = $address ? $address : $wgRC2UDPAddress;
220 - $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
221 - # Notify external application via UDP
222 - if( $address ) {
223 - $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
224 - if( $conn ) {
225 - $line = $prefix . $line;
226 - socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
227 - socket_close( $conn );
228 - return true;
229 - }
230 - }
231 - return false;
232 - }
233 -
234 - /**
235 - * Remove newlines and carriage returns
236 - * @param string $line
237 - * @return string
238 - */
239 - public static function cleanupForIRC( $text ) {
240 - return str_replace(array("\n", "\r"), array("", ""), $text);
241 - }
242 -
243 - /**
244210 * Mark a given change as patrolled
245211 *
246212 * @param mixed $change RecentChange or corresponding rc_id
@@ -618,7 +584,7 @@
619585 $titleObj =& $this->getTitle();
620586 }
621587 $title = $titleObj->getPrefixedText();
622 - $title = self::cleanupForIRC( $title );
 588+ $title = UDP::cleanupForIRC( $title );
623589
624590 // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
625591 if ( $rc_type == RC_LOG ) {
@@ -645,14 +611,14 @@
646612 $szdiff = '';
647613 }
648614
649 - $user = self::cleanupForIRC( $rc_user_text );
 615+ $user = UDP::cleanupForIRC( $rc_user_text );
650616
651617 if ( $rc_type == RC_LOG ) {
652618 $targetText = $this->getTitle()->getPrefixedText();
653 - $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
 619+ $comment = UDP::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) );
654620 $flag = $rc_log_action;
655621 } else {
656 - $comment = self::cleanupForIRC( $rc_comment );
 622+ $comment = UDP::cleanupForIRC( $rc_comment );
657623 $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
658624 }
659625 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
Index: trunk/phase3/includes/AutoLoader.php
@@ -505,6 +505,9 @@
506506 'WikiImporter' => 'includes/Import.php',
507507 'WikiRevision' => 'includes/Import.php',
508508 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php',
 509+
 510+ # UDP logging
 511+ 'UDP' => 'includes/UDP.php',
509512
510513 # includes/templates
511514 'UsercreateTemplate' => 'includes/templates/Userlogin.php',
Index: trunk/phase3/includes/UDP.php
@@ -0,0 +1,37 @@
 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
Property changes on: trunk/phase3/includes/UDP.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -1018,7 +1018,7 @@
10191019 global $wgCentralAuthUDPAddress, $wgCentralAuthNew2UDPPrefix;
10201020 if( $wgCentralAuthUDPAddress ) {
10211021 $userpage = Title::makeTitleSafe( NS_USER, $this->mName );
1022 - RecentChange::sendToUDP( self::getIRCLine( $userpage, $wikiID ),
 1022+ UDP::sendToUDP( self::getIRCLine( $userpage, $wikiID ),
10231023 $wgCentralAuthUDPAddress, $wgCentralAuthNew2UDPPrefix );
10241024 }
10251025 }
@@ -1030,11 +1030,11 @@
10311031 * @return string
10321032 */
10331033 protected static function getIRCLine( $userpage, $wikiID ) {
1034 - $title = RecentChange::cleanupForIRC( $userpage->getPrefixedText() );
1035 - $wikiID = RecentChange::cleanupForIRC( $wikiID );
 1034+ $title = UDP::cleanupForIRC( $userpage->getPrefixedText() );
 1035+ $wikiID = UDP::cleanupForIRC( $wikiID );
10361036 // FIXME: *HACK* should be getFullURL(), hacked for SSL madness
10371037 $url = $userpage->getInternalURL();
1038 - $user = RecentChange::cleanupForIRC( $userpage->getText() );
 1038+ $user = UDP::cleanupForIRC( $userpage->getText() );
10391039 # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
10401040 # no colour (\003) switches back to the term default
10411041 $fullString = "\00314[[\00307$title\00314]]\0034@$wikiID\00310 " .

Follow-up revisions

RevisionCommit summaryAuthorDate
r42236Back out r42182 for now "Move UDP stuff to new UDP class"...brion23:59, 19 October 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   23:59, 19 October 2008

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.

Backed out in r42236

Status & tagging log