From: Brion Vibber Date: Sun, 19 Oct 2008 23:59:39 +0000 (+0000) Subject: Back out r42182 for now "Move UDP stuff to new UDP class" X-Git-Tag: 1.31.0-rc.0~44678 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=90e12d48c74b71f3e9f2708ab82d5b7a4b9f724f;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 0b91aebdfc..573cb5f7a9 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -507,9 +507,6 @@ $wgAutoloadLocalClasses = array( 'WikiRevision' => 'includes/Import.php', 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php', - # UDP logging - 'UDP' => 'includes/UDP.php', - # includes/templates 'UsercreateTemplate' => 'includes/templates/Userlogin.php', 'UserloginTemplate' => 'includes/templates/Userlogin.php', diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 4eb9bb672d..125c5d590b 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -169,7 +169,7 @@ class RecentChange # Notify external application via UDP if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) { - UDP::sendToUDP( $this->getIRCLine() ); + self::sendToUDP( $this->getIRCLine() ); } # E-mail notifications @@ -198,6 +198,40 @@ 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 * @@ -568,7 +602,7 @@ class RecentChange $titleObj =& $this->getTitle(); } $title = $titleObj->getPrefixedText(); - $title = UDP::cleanupForIRC( $title ); + $title = self::cleanupForIRC( $title ); // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26 if( $rc_type == RC_LOG ) { @@ -595,14 +629,14 @@ class RecentChange $szdiff = ''; } - $user = UDP::cleanupForIRC( $rc_user_text ); + $user = self::cleanupForIRC( $rc_user_text ); if( $rc_type == RC_LOG ) { $targetText = $this->getTitle()->getPrefixedText(); - $comment = UDP::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) ); + $comment = self::cleanupForIRC( str_replace("[[$targetText]]","[[\00302$targetText\00310]]",$actionComment) ); $flag = $rc_log_action; } else { - $comment = UDP::cleanupForIRC( $rc_comment ); + $comment = self::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 deleted file mode 100644 index de7dddc9d6..0000000000 --- a/includes/UDP.php +++ /dev/null @@ -1,37 +0,0 @@ -