X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdebug%2FDebug.php;h=10905f2c954add69cb95cf4467504854be3c0fc6;hb=ddcf8cc660c810f1601b61c90aa33cb36ca60cad;hp=d56b65bc2381e3da499098241afde0b39f0c3e78;hpb=0f02086990341197085808a385e1fea6ef339f37;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php index d56b65bc23..10905f2c95 100644 --- a/includes/debug/Debug.php +++ b/includes/debug/Debug.php @@ -3,6 +3,9 @@ /** * New debugger system that outputs a toolbar on page view * + * By default, most methods do nothing ( self::$enabled = false ). You have + * to explicitly call MWDebug::init() to enabled them. + * * @todo Profiler support */ class MWDebug { @@ -28,19 +31,12 @@ class MWDebug { */ protected static $query = array(); - /** - * Request information - * - * @var array - */ - protected static $request = array(); - /** * Is the debugger enabled? * * @var bool */ - protected static $enabled = true; + protected static $enabled = false; /** * Array of functions that have already been warned, formatted @@ -51,18 +47,23 @@ class MWDebug { protected static $deprecationWarnings = array(); /** - * Called in Setup.php, initializes the debugger if it is enabled with - * $wgDebugToolbar + * Enabled the debugger and load resource module. + * This is called by Setup.php when $wgDebugToolbar is true. */ public static function init() { - global $wgDebugToolbar; + self::$enabled = true; + } - if ( !$wgDebugToolbar ) { - self::$enabled = false; - return; + /** + * Add ResourceLoader modules to the OutputPage object if debugging is + * enabled. + * + * @param $out OutputPage + */ + public static function addModules( OutputPage $out ) { + if ( self::$enabled ) { + $out->addModules( 'mediawiki.debug.init' ); } - - RequestContext::getMain()->getOutput()->addModules( 'mediawiki.debug' ); } /** @@ -86,6 +87,7 @@ class MWDebug { /** * Returns internal log array + * @return array */ public static function getLog() { return self::$log; @@ -113,8 +115,9 @@ class MWDebug { // Check to see if there was already a deprecation notice, so not to // get a duplicate warning - if ( count( self::$log ) ) { - $lastLog = self::$log[ count( self::$log ) - 1 ]; + $logCount = count( self::$log ); + if ( $logCount ) { + $lastLog = self::$log[ $logCount - 1 ]; if ( $lastLog['type'] == 'deprecated' && $lastLog['caller'] == wfGetCaller( $callerOffset + 1 ) ) { return; } @@ -197,8 +200,8 @@ class MWDebug { 'sql' => $sql, 'function' => $function, 'master' => (bool) $isMaster, - 'time' > 0.0, - '_start' => wfTime(), + 'time' => 0.0, + '_start' => microtime( true ), ); return count( self::$query ) - 1; @@ -214,28 +217,10 @@ class MWDebug { return; } - self::$query[$id]['time'] = wfTime() - self::$query[$id]['_start']; + self::$query[$id]['time'] = microtime( true ) - self::$query[$id]['_start']; unset( self::$query[$id]['_start'] ); } - /** - * Processes a WebRequest object - * - * @param $request WebRequest - */ - public static function processRequest( WebRequest $request ) { - if ( !self::$enabled ) { - return; - } - - self::$request = array( - 'method' => $_SERVER['REQUEST_METHOD'], - 'url' => $request->getRequestURL(), - 'headers' => $request->getAllHeaders(), - 'params' => $request->getValues(), - ); - } - /** * Returns a list of files included, along with their size * @@ -269,23 +254,35 @@ class MWDebug { global $wgVersion, $wgRequestTime; MWDebug::log( 'MWDebug output complete' ); + $request = $context->getRequest(); $debugInfo = array( 'mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, - 'time' => wfTime() - $wgRequestTime, + 'gitRevision' => GitInfo::headSHA1(), + 'gitBranch' => GitInfo::currentBranch(), + 'gitViewUrl' => GitInfo::headViewUrl(), + 'time' => microtime( true ) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, - 'request' => self::$request, + 'request' => array( + 'method' => $_SERVER['REQUEST_METHOD'], + 'url' => $request->getRequestURL(), + 'headers' => $request->getAllHeaders(), + 'params' => $request->getValues(), + ), 'memory' => $context->getLanguage()->formatSize( memory_get_usage() ), 'memoryPeak' => $context->getLanguage()->formatSize( memory_get_peak_usage() ), 'includes' => self::getFilesIncluded( $context ), ); - // TODO: Clean this up - $html = Html::openElement( 'script' ); - $html .= 'var debugInfo = ' . Xml::encodeJsVar( $debugInfo ) . ';'; - $html .= " $(function() { mw.loader.using( 'mediawiki.debug', function() { mw.Debug.init( debugInfo ) } ); }); "; - $html .= Html::closeElement( 'script' ); + + // Cannot use OutputPage::addJsConfigVars because those are already outputted + // by the time this method is called. + $html = Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( + ResourceLoader::makeConfigSetScript( array( 'debugInfo' => $debugInfo ) ) + ) + ); return $html; }