From b9a6c990322d11a3aca83a19105d37d41ac5da52 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Wed, 29 Sep 2021 14:43:22 +0200 Subject: [PATCH] Use WrappedString to build strings in MWDebug This gives a small performance benefit on developer wikis when the html page is build. Change-Id: Ic90bde09500776ae24952d627e582fbce688e36c --- includes/OutputPage.php | 6 ++--- includes/debug/MWDebug.php | 48 +++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 1df9b2c50c6..3812d951c7f 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -4262,9 +4262,9 @@ class OutputPage extends ContextSource { MWDebug::getDebugHTML( $skin ), $this->getBottomScripts( $extraHtml ), wfReportTime( $this->getCSP()->getNonce() ), - MWDebug::getHTMLDebugLog() - . Html::closeElement( 'body' ) - . Html::closeElement( 'html' ) + MWDebug::getHTMLDebugLog(), + Html::closeElement( 'body' ), + Html::closeElement( 'html' ), ]; return WrappedStringList::join( "\n", $tail ); diff --git a/includes/debug/MWDebug.php b/includes/debug/MWDebug.php index 9e88aab139e..e76e76c1e84 100644 --- a/includes/debug/MWDebug.php +++ b/includes/debug/MWDebug.php @@ -21,6 +21,8 @@ */ use MediaWiki\Logger\LegacyLogger; +use Wikimedia\WrappedString; +use Wikimedia\WrappedStringList; /** * New debugger system that outputs a toolbar on page view. @@ -604,12 +606,12 @@ class MWDebug { * * @since 1.19 * @param IContextSource $context - * @return string + * @return WrappedStringList */ public static function getDebugHTML( IContextSource $context ) { global $wgDebugComments; - $html = ''; + $html = []; if ( self::$enabled ) { self::log( 'MWDebug output complete' ); @@ -617,19 +619,21 @@ class MWDebug { // Cannot use OutputPage::addJsConfigVars because those are already outputted // by the time this method is called. - $html = ResourceLoader::makeInlineScript( + $html[] = ResourceLoader::makeInlineScript( ResourceLoader::makeConfigSetScript( [ 'debugInfo' => $debugInfo ] ), $context->getOutput()->getCSP()->getNonce() ); } if ( $wgDebugComments ) { - $html .= ""; + $html[] = ''; } - return $html; + return WrappedString::join( "\n", $html ); } /** @@ -638,26 +642,26 @@ class MWDebug { * If $wgShowDebug is false, an empty string is always returned. * * @since 1.20 - * @return string HTML fragment + * @return WrappedStringList HTML fragment */ public static function getHTMLDebugLog() { global $wgShowDebug; - if ( !$wgShowDebug ) { - return ''; + $html = []; + if ( $wgShowDebug ) { + $html[] = Html::openElement( 'div', [ 'id' => 'mw-html-debug-log' ] ); + $html[] = "
\nDebug data:'; + $html[] = ''; } - - $ret = "\n
\nDebug data:' . "\n"; - - return Html::rawElement( 'div', [ 'id' => 'mw-html-debug-log' ], $ret ); + return WrappedString::join( "\n", $html ); } /**