From: Aaron Schulz Date: Fri, 17 Oct 2008 23:46:21 +0000 (+0000) Subject: Move UDP stuff to new UDP class X-Git-Tag: 1.31.0-rc.0~44709 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=46a4a8bb7eefe12391d7a01fa44b00c35d431afd;p=lhc%2Fweb%2Fwiklou.git Move UDP stuff to new UDP class --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d0f417f6ae..029e1f67a1 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -505,6 +505,9 @@ $wgAutoloadLocalClasses = array( 'WikiImporter' => 'includes/Import.php', 'WikiRevision' => 'includes/Import.php', 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php', + + # UDP logging + 'UDP' => 'includes/UDP.php', # includes/templates 'UsercreateTemplate' => 'includes/templates/Userlogin.php', diff --git a/includes/RecentChange.php b/includes/RecentChange.php index aa3a649eed..b60cf63f07 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -176,7 +176,7 @@ class RecentChange # Notify external application via UDP if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) { - self::sendToUDP( $this->getIRCLine() ); + UDP::sendToUDP( $this->getIRCLine() ); } # E-mail notifications @@ -205,40 +205,6 @@ class RecentChange wfRunHooks( 'RecentChange_save', array( &$this ) ); } - /** - * Send some text to UDP - * @param string $line - * @param string $prefix - * @param string $address - * @return bool success - */ - public static function sendToUDP( $line, $address = '', $prefix = '' ) { - global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort; - # Assume default for standard RC case - $address = $address ? $address : $wgRC2UDPAddress; - $prefix = $prefix ? $prefix : $wgRC2UDPPrefix; - # Notify external application via UDP - if( $address ) { - $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); - if( $conn ) { - $line = $prefix . $line; - socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort ); - socket_close( $conn ); - return true; - } - } - return false; - } - - /** - * Remove newlines and carriage returns - * @param string $line - * @return string - */ - public static function cleanupForIRC( $text ) { - return str_replace(array("\n", "\r"), array("", ""), $text); - } - /** * Mark a given change as patrolled * @@ -618,7 +584,7 @@ class RecentChange $titleObj =& $this->getTitle(); } $title = $titleObj->getPrefixedText(); - $title = self::cleanupForIRC( $title ); + $title = UDP::cleanupForIRC( $title ); // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26 if ( $rc_type == RC_LOG ) { @@ -645,14 +611,14 @@ class RecentChange $szdiff = ''; } - $user = self::cleanupForIRC( $rc_user_text ); + $user = UDP::cleanupForIRC( $rc_user_text ); if ( $rc_type == RC_LOG ) { $targetText = $this->getTitle()->getPrefixedText(); - $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) ); + $comment = UDP::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) ); $flag = $rc_log_action; } else { - $comment = self::cleanupForIRC( $rc_comment ); + $comment = UDP::cleanupForIRC( $rc_comment ); $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : ""); } # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003, diff --git a/includes/UDP.php b/includes/UDP.php new file mode 100644 index 0000000000..de7dddc9d6 --- /dev/null +++ b/includes/UDP.php @@ -0,0 +1,37 @@ +