Small doc fix to JobQueueRedis.
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index e1e1234..0075bf5 100644 (file)
@@ -1093,16 +1093,29 @@ function wfDeprecated( $function, $version = false, $component = false, $callerO
 
 /**
  * Send a warning either to the debug log or in a PHP error depending on
- * $wgDevelopmentWarnings
+ * $wgDevelopmentWarnings. To log warnings in production, use wfLogWarning() instead.
  *
  * @param string $msg message to send
  * @param $callerOffset Integer: number of items to go back in the backtrace to
  *        find the correct caller (1 = function calling wfWarn, ...)
- * @param $level Integer: PHP error level; only used when $wgDevelopmentWarnings
- *        is true
+ * @param $level Integer: PHP error level; defaults to E_USER_NOTICE;
+ *        only used when $wgDevelopmentWarnings is true
  */
 function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
-       MWDebug::warning( $msg, $callerOffset + 1, $level );
+       MWDebug::warning( $msg, $callerOffset + 1, $level, 'auto' );
+}
+
+/**
+ * Send a warning as a PHP error and the debug log. This is intended for logging
+ * warnings in production. For logging development warnings, use WfWarn instead.
+ *
+ * @param $msg String: message to send
+ * @param $callerOffset Integer: number of items to go back in the backtrace to
+ *        find the correct caller (1 = function calling wfLogWarning, ...)
+ * @param $level Integer: PHP error level; defaults to E_USER_WARNING
+ */
+function wfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
+       MWDebug::warning( $msg, $callerOffset + 1, $level, 'production' );
 }
 
 /**
@@ -1177,6 +1190,8 @@ function wfLogProfilingData() {
        global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
        global $wgProfileLimit, $wgUser;
 
+       StatCounter::singleton()->flush();
+
        $profiler = Profiler::instance();
 
        # Profiling must actually be enabled...
@@ -1240,51 +1255,7 @@ function wfLogProfilingData() {
  * @return void
  */
 function wfIncrStats( $key, $count = 1 ) {
-       global $wgStatsMethod;
-
-       $count = intval( $count );
-       if ( $count == 0 ) {
-               return;
-       }
-
-       if( $wgStatsMethod == 'udp' ) {
-               global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgAggregateStatsID;
-               static $socket;
-
-               $id = $wgAggregateStatsID !== false ? $wgAggregateStatsID : wfWikiID();
-
-               if ( !$socket ) {
-                       $socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
-                       $statline = "stats/{$id} - 1 1 1 1 1 -total\n";
-                       socket_sendto(
-                               $socket,
-                               $statline,
-                               strlen( $statline ),
-                               0,
-                               $wgUDPProfilerHost,
-                               $wgUDPProfilerPort
-                       );
-               }
-               $statline = "stats/{$id} - {$count} 1 1 1 1 {$key}\n";
-               wfSuppressWarnings();
-               socket_sendto(
-                       $socket,
-                       $statline,
-                       strlen( $statline ),
-                       0,
-                       $wgUDPProfilerHost,
-                       $wgUDPProfilerPort
-               );
-               wfRestoreWarnings();
-       } elseif( $wgStatsMethod == 'cache' ) {
-               global $wgMemc;
-               $key = wfMemcKey( 'stats', $key );
-               if ( is_null( $wgMemc->incr( $key, $count ) ) ) {
-                       $wgMemc->add( $key, $count );
-               }
-       } else {
-               // Disabled
-       }
+       StatCounter::singleton()->incr( $key, $count );
 }
 
 /**
@@ -2578,8 +2549,7 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
 
        if( !$ok ) {
                // PHP doesn't report the path in its warning message, so add our own to aid in diagnosis.
-               trigger_error( sprintf( "%s: failed to mkdir \"%s\" mode 0%o", __FUNCTION__, $dir, $mode ),
-                       E_USER_WARNING );
+               wfLogWarning( sprintf( "failed to mkdir \"%s\" mode 0%o", $dir, $mode ) );
        }
        return $ok;
 }
@@ -3219,7 +3189,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = t
                return false;
        }
 
-       static $baseChars = array (
+       static $baseChars = array(
                10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f',
                16 => 'g', 17 => 'h', 18 => 'i', 19 => 'j', 20 => 'k', 21 => 'l',
                22 => 'm', 23 => 'n', 24 => 'o', 25 => 'p', 26 => 'q', 27 => 'r',
@@ -3338,7 +3308,7 @@ function wfCheckEntropy() {
  */
 function wfFixSessionID() {
        // If the cookie or session id is already set we already have a session and should abort
-       if ( isset( $_COOKIE[ session_name() ] ) || session_id() ) {
+       if ( isset( $_COOKIE[session_name()] ) || session_id() ) {
                return;
        }
 
@@ -3649,15 +3619,22 @@ function wfGetNull() {
  *
  * @param $maxLag Integer (deprecated)
  * @param $wiki mixed Wiki identifier accepted by wfGetLB
+ * @param $cluster string cluster name accepted by LBFactory
  */
-function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
-       $lb = wfGetLB( $wiki );
+function wfWaitForSlaves( $maxLag = false, $wiki = false, $cluster = false ) {
+       $lb = ( $cluster !== false )
+               ? wfGetLBFactory()->getExternalLB( $cluster )
+               : wfGetLB( $wiki );
        // bug 27975 - Don't try to wait for slaves if there are none
        // Prevents permission error when getting master position
        if ( $lb->getServerCount() > 1 ) {
                $dbw = $lb->getConnection( DB_MASTER, array(), $wiki );
                $pos = $dbw->getMasterPos();
-               $lb->waitForAll( $pos );
+               // The DBMS may not support getMasterPos() or the whole
+               // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
+               if ( $pos !== false ) {
+                       $lb->waitForAll( $pos );
+               }
        }
 }
 
@@ -3897,7 +3874,7 @@ function wfRunHooks( $event, $args = array() ) {
  * @throws MWException if $data not long enough, or if unpack fails
  * @return array Associative array of the extracted data
  */
-function wfUnpack( $format, $data, $length=false ) {
+function wfUnpack( $format, $data, $length = false ) {
        if ( $length !== false ) {
                $realLen = strlen( $data );
                if ( $realLen < $length ) {
@@ -3940,7 +3917,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
        # Handle redirects
        $redirectTitle = RepoGroup::singleton()->checkRedirect( Title::makeTitle( NS_FILE, $name ) );
        if( $redirectTitle ) {
-               $name = $redirectTitle->getDbKey();
+               $name = $redirectTitle->getDBkey();
        }
 
        # Run the extension hook