X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=51d0749f0a70bd3a5ff33b00bcb1d6fdefe9a602;hb=98c66071a35d14a1e396e248796295f91bacf7e9;hp=71b135f7adcc2fe5f93dbab6259dd84fc04eb04c;hpb=c2f8e932d8096a5e75d81eebe6d66d6ccde699d2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 71b135f7ad..51d0749f0a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -255,29 +255,30 @@ function wfErrorLog( $text, $file ) { */ function wfLogProfilingData() { global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest; - global $wgProfiling, $wgUser; - if ( $wgProfiling ) { - $now = wfTime(); - $elapsed = $now - $wgRequestTime; - $prof = wfGetProfilingOutput( $wgRequestTime, $elapsed ); - $forward = ''; - if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) - $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR']; - if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) - $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP']; - if( !empty( $_SERVER['HTTP_FROM'] ) ) - $forward .= ' from ' . $_SERVER['HTTP_FROM']; - if( $forward ) - $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})"; - // Don't unstub $wgUser at this late stage just for statistics purposes - if( StubObject::isRealObject($wgUser) && $wgUser->isAnon() ) - $forward .= ' anon'; - $log = sprintf( "%s\t%04.3f\t%s\n", - gmdate( 'YmdHis' ), $elapsed, - urldecode( $wgRequest->getRequestURL() . $forward ) ); - if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' || $wgDebugRawPage ) ) { - wfErrorLog( $log . $prof, $wgDebugLogFile ); - } + global $wgProfiler, $wgUser; + if ( !isset( $wgProfiler ) ) + return; + + $now = wfTime(); + $elapsed = $now - $wgRequestTime; + $prof = wfGetProfilingOutput( $wgRequestTime, $elapsed ); + $forward = ''; + if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) + $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR']; + if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) + $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP']; + if( !empty( $_SERVER['HTTP_FROM'] ) ) + $forward .= ' from ' . $_SERVER['HTTP_FROM']; + if( $forward ) + $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})"; + // Don't unstub $wgUser at this late stage just for statistics purposes + if( StubObject::isRealObject($wgUser) && $wgUser->isAnon() ) + $forward .= ' anon'; + $log = sprintf( "%s\t%04.3f\t%s\n", + gmdate( 'YmdHis' ), $elapsed, + urldecode( $wgRequest->getRequestURL() . $forward ) ); + if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' || $wgDebugRawPage ) ) { + wfErrorLog( $log . $prof, $wgDebugLogFile ); } } @@ -613,7 +614,6 @@ function wfMsgExt( $key, $options ) { * @deprecated Please return control to the caller or throw an exception */ function wfAbruptExit( $error = false ){ - global $wgLoadBalancer; static $called = false; if ( $called ){ exit( -1 ); @@ -634,7 +634,7 @@ function wfAbruptExit( $error = false ){ wfLogProfilingData(); if ( !$error ) { - $wgLoadBalancer->closeAll(); + wfGetLB()->closeAll(); } exit( -1 ); } @@ -2234,7 +2234,9 @@ function wfSetupSession() { } session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain, $wgCookieSecure); session_cache_limiter( 'private, must-revalidate' ); - @session_start(); + wfSuppressWarnings(); + session_start(); + wfRestoreWarnings(); } /** @@ -2317,6 +2319,17 @@ function wfWikiID() { } } +/** + * Split a wiki ID into DB name and table prefix + */ +function wfSplitWikiID( $wiki ) { + $bits = explode( '-', $wiki, 2 ); + if ( count( $bits ) < 2 ) { + $bits[] = ''; + } + return $bits; +} + /* * Get a Database object * @param integer $db Index of the connection to get. May be DB_MASTER for the @@ -2326,11 +2339,29 @@ function wfWikiID() { * @param mixed $groups Query groups. An array of group names that this query * belongs to. May contain a single string if the query is only * in one group. + * + * @param string $wiki The wiki ID, or false for the current wiki */ -function &wfGetDB( $db = DB_LAST, $groups = array() ) { - global $wgLoadBalancer; - $ret = $wgLoadBalancer->getConnection( $db, true, $groups ); - return $ret; +function &wfGetDB( $db = DB_LAST, $groups = array(), $wiki = false ) { + return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki ); +} + +/** + * Get a load balancer object. + * + * @param array $groups List of query groups + * @param string $wiki Wiki ID, or false for the current wiki + * @return LoadBalancer + */ +function wfGetLB( $wiki = false ) { + return wfGetLBFactory()->getMainLB( $wiki ); +} + +/** + * Get the load balancer factory object + */ +function &wfGetLBFactory() { + return LBFactory::singleton(); } /** @@ -2339,7 +2370,7 @@ function &wfGetDB( $db = DB_LAST, $groups = array() ) { * @param mixed $title Title object or string. May be interwiki. * @param mixed $time Requested time for an archived image, or false for the * current version. An image object will be returned which - * existed at the specified time. + * was created at the specified time. * @return File, or false if the file does not exist */ function wfFindFile( $title, $time = false ) { @@ -2437,7 +2468,46 @@ function wfMaxlagError( $host, $lag, $maxLag ) { /** * Throws an E_USER_NOTICE saying that $function is deprecated * @param string $function + * @return null */ function wfDeprecated( $function ) { trigger_error( "Use of $function is deprecated", E_USER_NOTICE ); } + +/** + * Sleep until the worst slave's replication lag is less than or equal to + * $maxLag, in seconds. Use this when updating very large numbers of rows, as + * in maintenance scripts, to avoid causing too much lag. Of course, this is + * a no-op if there are no slaves. + * + * Every time the function has to wait for a slave, it will print a message to + * that effect (and then sleep for a little while), so it's probably not best + * to use this outside maintenance scripts in its present form. + * + * @param int $maxLag + * @return null + */ +function wfWaitForSlaves( $maxLag ) { + if( $maxLag ) { + $lb = wfGetLB(); + list( $host, $lag ) = $lb->getMaxLag(); + while( $lag > $maxLag ) { + $name = @gethostbyaddr( $host ); + if( $name !== false ) { + $host = $name; + } + print "Waiting for $host (lagged $lag seconds)...\n"; + sleep($maxLag); + list( $host, $lag ) = $lb->getMaxLag(); + } + } +} + +/** Generate a random 32-character hexadecimal token. + * @param mixed $salt Some sort of salt, if necessary, to add to random characters before hashing. + */ + function wfGenerateToken( $salt = '' ) { + $salt = serialize($salt); + + return md5( mt_rand( 0, 0x7fffffff ) . $salt ); + } \ No newline at end of file