use Liuggio\StatsdClient\StatsdClient;
use Liuggio\StatsdClient\Sender\SocketSender;
+use MediaWiki\Logger\LoggerFactory;
// Hide compatibility functions from Doxygen
/// @cond
/**
* Load an extension
*
- * This is the closest equivalent to:
- * require_once "$IP/extensions/$name/$name.php";
- * as it will process and load the extension immediately.
- *
- * However, batch loading with wfLoadExtensions will
- * be more performant.
+ * This queues an extension to be loaded through
+ * the ExtensionRegistry system.
*
* @param string $name Name of the extension to load
* @param string|null $path Absolute path of where to find the extension.json file
global $IP;
$path = "$IP/extensions/$name/extension.json";
}
- ExtensionRegistry::getInstance()->load( $path );
+ ExtensionRegistry::getInstance()->queue( $path );
}
/**
foreach ( $exts as $ext ) {
$registry->queue( "$IP/extensions/$ext/extension.json" );
}
-
- $registry->loadFromQueue();
}
/**
global $IP;
$path = "$IP/skins/$name/skin.json";
}
- ExtensionRegistry::getInstance()->load( $path );
+ ExtensionRegistry::getInstance()->queue( $path );
}
/**
foreach ( $skins as $skin ) {
$registry->queue( "$IP/skins/$skin/skin.json" );
}
-
- $registry->loadFromQueue();
}
/**
$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.
+ if ( $wgReadOnly === false && wfGetLB()->getLaggedSlaveMode() ) {
+ $wgReadOnly = 'The database has been automatically locked ' .
+ 'while the slave database servers catch up to the master';
+ }
}
return $wgReadOnly;
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 {
/**
* Returns unified plain-text diff of two texts.
- * Useful for machine processing of diffs.
+ * "Useful" for machine processing of diffs.
+ *
+ * @deprecated since 1.25, use DiffEngine/UnifiedDiffFormatter directly
*
* @param string $before The text before the changes.
* @param string $after The text after the changes.
$cmd = "$wgDiff " . $params . ' ' . wfEscapeShellArg( $oldtextName, $newtextName );
$h = popen( $cmd, 'r' );
+ if ( !$h ) {
+ unlink( $oldtextName );
+ unlink( $newtextName );
+ throw new Exception( __METHOD__ . '(): popen() failed' );
+ }
$diff = '';