* @todo document
*/
function wfLogProfilingData() {
- global $wgRequestTime, $wgDebugLogGroups, $wgDebugRawPage;
- global $wgProfileLimit, $wgUser, $wgRequest;
+ global $wgDebugLogGroups, $wgDebugRawPage, $wgProfileLimit;
$context = RequestContext::getMain();
+ $request = $context->getRequest();
$config = $context->getConfig();
if ( $config->has( 'StatsdServer' ) ) {
$statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
// Get total page request time and only show pages that longer than
// $wgProfileLimit time (default is 0)
- $elapsed = microtime( true ) - $wgRequestTime;
+ $elapsed = $request->getElapsedTime();
if ( $elapsed <= $wgProfileLimit ) {
return;
}
// 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
}
*/
private $ip;
+ /**
+ * The timestamp of the start of the request, with microsecond precision.
+ * @var float
+ */
+ protected $requestTime;
+
/**
* Cached URL protocol
* @var string
protected $protocol;
public function __construct() {
- if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
- throw new MWException( "MediaWiki does not function when magic quotes are enabled." );
- }
+ $this->requestTime = isset( $_SERVER['REQUEST_TIME_FLOAT'] )
+ ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime( true );
// POST overrides GET data
// We don't use $_REQUEST here to avoid interference from cookies...
}
}
+ /**
+ * Get the number of seconds to have elapsed since request start,
+ * in fractional seconds, with microsecond resolution.
+ *
+ * @return float
+ * @since 1.25
+ */
+ public function getElapsedTime() {
+ return microtime( true ) - $this->requestTime;
+ }
+
/**
* Get the current URL protocol (http or https)
* @return string
public function __construct( $data = array(), $wasPosted = false,
$session = null, $protocol = 'http'
) {
+ $this->requestTime = microtime( true );
+
if ( is_array( $data ) ) {
$this->data = $data;
} else {
public function getProtocol() {
return $this->base->getProtocol();
}
+
+ public function getElapsedTime() {
+ return $this->base->getElapsedTime();
+ }
}
. 'for help on how to disable it.' );
}
+if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
+ die( 'MediaWiki does not function when magic quotes are enabled. '
+ . 'Please see the <a href="https://php.net/manual/security.magicquotes.disabling.php">PHP Manual</a> '
+ . 'for help on how to disable magic quotes.' );
+}
+
+
# bug 15461: Make IE8 turn off content sniffing. Everybody else should ignore this
# We're adding it here so that it's *always* set, even for alternate entry
# points and when $wgOut gets disabled or overridden.
header( 'X-Content-Type-Options: nosniff' );
-$wgRequestTime = microtime( true );
+# Approximate $_SERVER['REQUEST_TIME_FLOAT'] for PHP<5.4
+if ( !isset( $_SERVER['REQUEST_TIME_FLOAT'] ) ) {
+ $_SERVER['REQUEST_TIME_FLOAT'] = microtime( true );
+}
+
+/**
+ * @var float Request start time as fractional seconds since epoch
+ * @deprecated since 1.25; use $_SERVER['REQUEST_TIME_FLOAT'] or
+ * WebRequest::getElapsedTime() instead.
+ */
+$wgRequestTime = $_SERVER['REQUEST_TIME_FLOAT'];
+
unset( $IP );
# Valid web server entry point, enable includes.