use Liuggio\StatsdClient\StatsdClient;
use Liuggio\StatsdClient\Sender\SocketSender;
+use MediaWiki\Logger\LoggerFactory;
// Hide compatibility functions from Doxygen
/// @cond
* This queues an extension to be loaded through
* the ExtensionRegistry system.
*
- * @param string $name Name of the extension to load
+ * @param string $ext Name of the extension to load
* @param string|null $path Absolute path of where to find the extension.json file
*/
-function wfLoadExtension( $name, $path = null ) {
+function wfLoadExtension( $ext, $path = null ) {
if ( !$path ) {
- global $IP;
- $path = "$IP/extensions/$name/extension.json";
+ global $wgExtensionDirectory;
+ $path = "$wgExtensionDirectory/$ext/extension.json";
}
ExtensionRegistry::getInstance()->queue( $path );
}
* @param string[] $exts Array of extension names to load
*/
function wfLoadExtensions( array $exts ) {
- global $IP;
+ global $wgExtensionDirectory;
$registry = ExtensionRegistry::getInstance();
foreach ( $exts as $ext ) {
- $registry->queue( "$IP/extensions/$ext/extension.json" );
+ $registry->queue( "$wgExtensionDirectory/$ext/extension.json" );
}
}
* Load a skin
*
* @see wfLoadExtension
- * @param string $name Name of the extension to load
+ * @param string $skin Name of the extension to load
* @param string|null $path Absolute path of where to find the skin.json file
*/
-function wfLoadSkin( $name, $path = null ) {
+function wfLoadSkin( $skin, $path = null ) {
if ( !$path ) {
- global $IP;
- $path = "$IP/skins/$name/skin.json";
+ global $wgStyleDirectory;
+ $path = "$wgStyleDirectory/$skin/skin.json";
}
ExtensionRegistry::getInstance()->queue( $path );
}
* @param string[] $skins Array of extension names to load
*/
function wfLoadSkins( array $skins ) {
- global $IP;
+ global $wgStyleDirectory;
$registry = ExtensionRegistry::getInstance();
foreach ( $skins as $skin ) {
- $registry->queue( "$IP/skins/$skin/skin.json" );
+ $registry->queue( "$wgStyleDirectory/$skin/skin.json" );
}
}
$context['prefix'] = $wgDebugLogPrefix;
}
- $logger = MWLoggerFactory::getInstance( 'wfDebug' );
+ $logger = LoggerFactory::getInstance( 'wfDebug' );
$logger->debug( $text, $context );
}
$text = trim( $text );
- $logger = MWLoggerFactory::getInstance( $logGroup );
+ $logger = LoggerFactory::getInstance( $logGroup );
$context['private'] = ( $dest === 'private' );
$logger->info( $text, $context );
}
* @param array $context Additional logging context data
*/
function wfLogDBError( $text, array $context = array() ) {
- $logger = MWLoggerFactory::getInstance( 'wfLogDBError' );
+ $logger = LoggerFactory::getInstance( 'wfLogDBError' );
$logger->error( trim( $text ), $context );
}
* @param string $file Filename
* @param array $context Additional logging context data
* @throws MWException
- * @deprecated since 1.25 Use MWLoggerLegacyLogger::emit or UDPTransport
+ * @deprecated since 1.25 Use MediaWiki\Logger\LegacyLogger::emit or UDPTransport
*/
function wfErrorLog( $text, $file, array $context = array() ) {
wfDeprecated( __METHOD__, '1.25' );
- $logger = MWLoggerFactory::getInstance( 'wfErrorLog' );
+ $logger = LoggerFactory::getInstance( 'wfErrorLog' );
$context['destination'] = $file;
$logger->info( trim( $text ), $context );
}
* @todo document
*/
function wfLogProfilingData() {
- global $wgRequestTime, $wgDebugLogGroups, $wgDebugRawPage;
- global $wgProfileLimit, $wgUser, $wgRequest;
+ global $wgDebugLogGroups, $wgDebugRawPage;
$context = RequestContext::getMain();
+ $request = $context->getRequest();
+
+ $profiler = Profiler::instance();
+ $profiler->setContext( $context );
+ $profiler->logData();
+
$config = $context->getConfig();
if ( $config->has( 'StatsdServer' ) ) {
$statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
$statsdClient->send( $context->getStats()->getBuffer() );
}
- $profiler = Profiler::instance();
-
# Profiling must actually be enabled...
if ( $profiler instanceof ProfilerStub ) {
return;
}
- // Get total page request time and only show pages that longer than
- // $wgProfileLimit time (default is 0)
- $elapsed = microtime( true ) - $wgRequestTime;
- if ( $elapsed <= $wgProfileLimit ) {
- return;
- }
-
- $profiler->logData();
-
if ( isset( $wgDebugLogGroups['profileoutput'] )
&& $wgDebugLogGroups['profileoutput'] === false
) {
return;
}
- $ctx = array( 'elapsed' => $elapsed );
+ $ctx = array( 'elapsed' => $request->getElapsedTime() );
if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ctx['forwarded_for'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
// Don't load $wgUser at this late stage just for statistics purposes
// @todo FIXME: We can detect some anons even if it is not loaded.
// See User::getId()
- if ( $wgUser->isItemLoaded( 'id' ) && $wgUser->isAnon() ) {
- $ctx['anon'] = true;
- } else {
- $ctx['anon'] = false;
- }
+ $user = $context->getUser();
+ $ctx['anon'] = $user->isItemLoaded( 'id' ) && $user->isAnon();
// Command line script uses a FauxRequest object which does not have
// any knowledge about an URL and throw an exception instead.
try {
- $ctx['url'] = urldecode( $wgRequest->getRequestURL() );
+ $ctx['url'] = urldecode( $request->getRequestURL() );
} catch ( Exception $ignored ) {
// no-op
}
$ctx['output'] = $profiler->getOutput();
- $log = MWLoggerFactory::getInstance( 'profileoutput' );
+ $log = LoggerFactory::getInstance( 'profileoutput' );
$log->info( "Elapsed: {elapsed}; URL: <{url}>\n{output}", $ctx );
}
} else {
$wgReadOnly = false;
}
+ // Callers use this method to be aware that data presented to a user
+ // may be very stale and thus allowing submissions can be problematic.
+ try {
+ if ( $wgReadOnly === false && wfGetLB()->getLaggedSlaveMode() ) {
+ $wgReadOnly = 'The database has been automatically locked ' .
+ 'while the slave database servers catch up to the master';
+ }
+ } catch ( DBConnectionError $e ) {
+ $wgReadOnly = 'The database has been automatically locked ' .
+ 'until the slave database servers become available';
+ }
}
return $wgReadOnly;
*/
function wfHttpError( $code, $label, $desc ) {
global $wgOut;
- header( "HTTP/1.0 $code $label" );
- header( "Status: $code $label" );
+ HttpStatus::header( $code );
if ( $wgOut ) {
$wgOut->disable();
$wgOut->sendCacheControl();
}
header( 'Content-type: text/html; charset=utf-8' );
- print "<!doctype html>" .
+ print '<!DOCTYPE html>' .
'<html><head><title>' .
htmlspecialchars( $label ) .
'</title></head><body><h1>' .
function wfIsWindows() {
static $isWindows = null;
if ( $isWindows === null ) {
- $isWindows = substr( php_uname(), 0, 7 ) == 'Windows';
+ $isWindows = strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';
}
return $isWindows;
}
return defined( 'HHVM_VERSION' );
}
-/**
- * Swap two variables
- *
- * @deprecated since 1.24
- * @param mixed $x
- * @param mixed $y
- */
-function swap( &$x, &$y ) {
- wfDeprecated( __FUNCTION__, '1.24' );
- $z = $x;
- $x = $y;
- $y = $z;
-}
-
/**
* Tries to get the system directory for temporary files. First
* $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP
wfDebug( "$caller: called wfMkdirParents($dir)\n" );
}
- if ( strval( $dir ) === '' || ( file_exists( $dir ) && is_dir( $dir ) ) ) {
+ if ( strval( $dir ) === '' || is_dir( $dir ) ) {
return true;
}
fclose( $yourtextFile );
# Check for a conflict
- $cmd = wfEscapeShellArg( $wgDiff3, '-a', '--overlap-only', $mytextName, $oldtextName, $yourtextName );
+ $cmd = wfEscapeShellArg( $wgDiff3, '-a', '--overlap-only', $mytextName,
+ $oldtextName, $yourtextName );
$handle = popen( $cmd, 'r' );
if ( fgets( $handle, 1024 ) ) {
pclose( $handle );
# Merge differences
- $cmd = wfEscapeShellArg( $wgDiff3, '-a', '-e', '--merge', $mytextName, $oldtextName, $yourtextName );
+ $cmd = wfEscapeShellArg( $wgDiff3, '-a', '-e', '--merge', $mytextName,
+ $oldtextName, $yourtextName );
$handle = popen( $cmd, 'r' );
$result = '';
do {
// Removing leading zeros works around broken base detection code in
// some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
// <https://bugs.php.net/bug.php?id=55398>).
- $result = gmp_strval( gmp_init( ltrim( $input, '0' ), $sourceBase ), $destBase );
+ $result = gmp_strval( gmp_init( ltrim( $input, '0' ) ?: '0', $sourceBase ), $destBase );
} elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
$decimal = '0';
foreach ( str_split( strtolower( $input ) ) as $char ) {
}
// Figure out which clusters need to be checked
+ /** @var LoadBalancer[] $lbs */
$lbs = array();
if ( $cluster === '*' ) {
wfGetLBFactory()->forEachLB( function ( LoadBalancer $lb ) use ( &$lbs ) {
// time needed to wait on the next clusters.
$masterPositions = array_fill( 0, count( $lbs ), false );
foreach ( $lbs as $i => $lb ) {
- // bug 27975 - Don't try to wait for slaves if there are none
- // Prevents permission error when getting master position
- if ( $lb->getServerCount() > 1 ) {
- if ( $ifWritesSince && !$lb->hasMasterConnection() ) {
- continue; // assume no writes done
- }
- // Use the empty string to not trigger selectDB() since the connection
- // may have been to a server that does not have a DB for the current wiki.
- $dbw = $lb->getConnection( DB_MASTER, array(), '' );
- if ( $ifWritesSince && $dbw->lastDoneWrites() < $ifWritesSince ) {
- continue; // no writes since the last wait
- }
- $masterPositions[$i] = $dbw->getMasterPos();
+ if ( $lb->getServerCount() <= 1 ) {
+ // Bug 27975 - Don't try to wait for slaves if there are none
+ // Prevents permission error when getting master position
+ continue;
+ } elseif ( $ifWritesSince && $lb->lastMasterChangeTimestamp() < $ifWritesSince ) {
+ continue; // no writes since the last wait
}
+ $masterPositions[$i] = $lb->getMasterPos();
}
$ok = true;