Raise E_USER_WARNING if bad option passed to wfMsgExt()
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index c43a133..301e2a8 100644 (file)
@@ -285,16 +285,50 @@ function wfLogDBError( $text ) {
 }
 
 /**
- * Log to a file without getting "file size exceeded" signals
+ * Log to a file without getting "file size exceeded" signals.
+ * 
+ * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will 
+ * send lines to the specified port, prefixed by the specified prefix and a space.
  */
 function wfErrorLog( $text, $file ) {
-       wfSuppressWarnings();
-       $exists = file_exists( $file );
-       $size = $exists ? filesize( $file ) : false;
-       if ( !$exists || ( $size !== false && $size + strlen( $text ) < 0x7fffffff ) ) {
-               error_log( $text, 3, $file );
+       if ( substr( $file, 0, 4 ) == 'udp:' ) {
+               if ( preg_match( '!^(tcp|udp):(?://)?\[([0-9a-fA-F:]+)\]:(\d+)(?:/(.*))?$!', $file, $m ) ) {
+                       // IPv6 bracketed host
+                       $protocol = $m[1];
+                       $host = $m[2];
+                       $port = $m[3];
+                       $prefix = isset( $m[4] ) ? $m[4] : false;
+               } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) {
+                       $protocol = $m[1];
+                       $host = $m[2];
+                       $port = $m[3];
+                       $prefix = isset( $m[4] ) ? $m[4] : false;
+               } else {
+                       throw new MWException( __METHOD__.": Invalid UDP specification" );
+               }
+               // Clean it up for the multiplexer
+               if ( strval( $prefix ) !== '' ) {
+                       $text = preg_replace( '/^/m', $prefix . ' ', $text );
+                       if ( substr( $text, -1 ) != "\n" ) {
+                               $text .= "\n";
+                       }
+               }
+
+               $sock = fsockopen( "$protocol://$host", $port );
+               if ( !$sock ) {
+                       return;
+               }
+               fwrite( $sock, $text );
+               fclose( $sock );
+       } else {
+               wfSuppressWarnings();
+               $exists = file_exists( $file );
+               $size = $exists ? filesize( $file ) : false;
+               if ( !$exists || ( $size !== false && $size + strlen( $text ) < 0x7fffffff ) ) {
+                       error_log( $text, 3, $file );
+               }
+               wfRestoreWarnings();
        }
-       wfRestoreWarnings();
 }
 
 /**
@@ -655,6 +689,15 @@ function wfMsgExt( $key, $options ) {
                $options = array($options);
        }
 
+       foreach( $options as $option ) {
+               if( !in_array( $option, array( 'parse', 'parseinline', 'escape',
+               'escapenoentities', 'replaceafter', 'parsemag', 'content',
+               'language' ) ) ) {
+                       trigger_error( "wfMsgExt called with incorrect parameter $option",
+                               E_USER_WARNING );
+               }
+       }
+
        if( in_array('content', $options) ) {
                $forContent = true;
                $langCode = true;
@@ -926,12 +969,10 @@ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) {
        } else {
                $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" class=\"mw-nextlink\">{$next}</a>";
        }
-
-       $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
-       $nums = wfNumLink( $offset, 20, $title, $query ) . $separator .
-         wfNumLink( $offset, 50, $title, $query ) . $separator .
-         wfNumLink( $offset, 100, $title, $query ) . $separator .
-         wfNumLink( $offset, 250, $title, $query ) . $separator .
+       $nums = wfNumLink( $offset, 20, $title, $query ) . ' | ' .
+         wfNumLink( $offset, 50, $title, $query ) . ' | ' .
+         wfNumLink( $offset, 100, $title, $query ) . ' | ' .
+         wfNumLink( $offset, 250, $title, $query ) . ' | ' .
          wfNumLink( $offset, 500, $title, $query );
 
        return wfMsg( 'viewprevnext', $plink, $nlink, $nums );
@@ -2646,7 +2687,7 @@ function wfSplitWikiID( $wiki ) {
  * will always return the same object, unless the underlying connection or load
  * balancer is manually destroyed.
  */
-function &wfGetDB( $db = DB_LAST, $groups = array(), $wiki = false ) {
+function &wfGetDB( $db, $groups = array(), $wiki = false ) {
        return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );
 }