+ /**
+ * Send some text to UDP.
+ * @see RecentChange::cleanupForIRC
+ * @param $line String: text to send
+ * @param $address String: defaults to $wgRC2UDPAddress.
+ * @param $prefix String: defaults to $wgRC2UDPPrefix.
+ * @param $port Int: defaults to $wgRC2UDPPort. (Since 1.17)
+ * @return Boolean: success
+ */
+ public static function sendToUDP( $line, $address = '', $prefix = '', $port = '' ) {
+ global $wgRC2UDPAddress, $wgRC2UDPPrefix, $wgRC2UDPPort;
+ # Assume default for standard RC case
+ $address = $address ? $address : $wgRC2UDPAddress;
+ $prefix = $prefix ? $prefix : $wgRC2UDPPrefix;
+ $port = $port ? $port : $wgRC2UDPPort;
+ # Notify external application via UDP
+ if( $address ) {
+ $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
+ if( $conn ) {
+ $line = $prefix . $line;
+ wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
+ socket_sendto( $conn, $line, strlen($line), 0, $address, $port );
+ socket_close( $conn );
+ return true;
+ } else {
+ wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove newlines, carriage returns and decode html entites
+ * @param $text String
+ * @return String
+ */
+ public static function cleanupForIRC( $text ) {
+ return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );