Back out r42182 for now "Move UDP stuff to new UDP class"
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 19 Oct 2008 23:59:39 +0000 (23:59 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 19 Oct 2008 23:59:39 +0000 (23:59 +0000)
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.

includes/AutoLoader.php
includes/RecentChange.php
includes/UDP.php [deleted file]

index 0b91aeb..573cb5f 100644 (file)
@@ -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',
index 4eb9bb6..125c5d5 100644 (file)
@@ -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 (file)
index de7dddc..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-
-class UDP {
-       /**
-        * 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);
-       }
-}
\ No newline at end of file