From: Aaron Schulz Date: Mon, 22 Sep 2008 12:22:18 +0000 (+0000) Subject: Refactor RC2UDP code some X-Git-Tag: 1.31.0-rc.0~45145 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=9894dfb3635cbf333c3e074dd990a775eca8a849;p=lhc%2Fweb%2Fwiklou.git Refactor RC2UDP code some --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5733c957a5..fcfb249a93 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2873,3 +2873,20 @@ function wfStripIllegalFilenameChars( $name ) { $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name ); return $name; } + +/** + * Send some text to + * @param string $line + */ +function wfRecentChange2UDP( $line ) { + global $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix; + # Notify external application via UDP + if( $wgRC2UDPAddress ) { + $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); + if( $conn ) { + $line = $wgRC2UDPPrefix . $line; + socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort ); + socket_close( $conn ); + } + } +} diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 2fa41828de..b1c70d8d5a 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -140,8 +140,7 @@ class RecentChange # Writes the data in this object to the database function save() { - global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, - $wgRC2UDPPort, $wgRC2UDPPrefix, $wgRC2UDPOmitBots; + global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPOmitBots; $fname = 'RecentChange::save'; $dbw = wfGetDB( DB_MASTER ); @@ -154,7 +153,7 @@ class RecentChange $this->mAttribs['rc_ip'] = ''; } - ## If our database is strict about IP addresses, use NULL instead of an empty string + # If our database is strict about IP addresses, use NULL instead of an empty string if ( $dbw->strictIPs() and $this->mAttribs['rc_ip'] == '' ) { unset( $this->mAttribs['rc_ip'] ); } @@ -211,12 +210,7 @@ class RecentChange # Notify external application via UDP if ( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) { - $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); - if ( $conn ) { - $line = $wgRC2UDPPrefix . $this->getIRCLine(); - socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort ); - socket_close( $conn ); - } + wfRecentChange2UDP( $this->getIRCLine() ); } # E-mail notifications