Deprecate global function wfReportTime()

Use WebRequest::getElapsedTime in OutputPage::getBottomScripts.
Integrate the rest of wfReportTime in OutputPage::getBottomScripts.
The configuration variable ShowHostnames can now accessed without a
global variable.

The generated HTML doesn't contain a separate mw.config.set() anymore.

The measure of the elapsed time should be at the last possible
position. Therefor the hook onSkinAfterBottomScripts gets fired before.

The time deviation compared to the previous position is about 100 µs
less which sometimes get rounded to 1 ms less in wgBackendResponseTime.

The last usage of wfReportTime() is in the deprecated function
BaseTemplate::getTrail.

Change-Id: Id069f9130344b1a79bf4e954c30502a90b3602b7
This commit is contained in:
Fomafix 2023-03-08 13:25:17 +00:00
parent 87bec9d39e
commit 11e0fba3b0
3 changed files with 19 additions and 10 deletions

View file

@ -435,6 +435,7 @@ because of Phabricator reports.
* SelectQueryBuilder::lockForUpdate() is deprecated. Use ::forUpdate() with
::fetchRowCount() or ::acquireRowLocks() instead.
* ArticleUndelete hook is deprecated. Use PageUndeleteComplete hook instead.
* The global function wfReportTime() is now deprecated.
* …
=== Other changes in 1.40 ===

View file

@ -975,6 +975,7 @@ function wfHostname() {
* If $wgShowHostnames is true, the script will also set 'wgHostname' to the
* hostname of the server handling the request.
*
* @deprecated since 1.40
* @param string|null $nonce Value from OutputPage->getCSP()->getNonce()
* @return string|WrappedString HTML
*/

View file

@ -3506,6 +3506,10 @@ class OutputPage extends ContextSource {
* @return string|WrappedStringList HTML
*/
public function getBottomScripts( $extraHtml = '' ) {
// Keep the hook appendage separate to preserve WrappedString objects.
// This enables BaseTemplate::getTrail() to merge them where possible.
$this->getHookRunner()->onSkinAfterBottomScripts( $this->getSkin(), $extraHtml );
$chunks = [];
$chunks[] = $this->getRlClient()->getBodyHtml();
@ -3516,17 +3520,21 @@ class OutputPage extends ContextSource {
if ( $this->limitReportJSData ) {
$vars['wgPageParseReport'] = $this->limitReportJSData;
}
if ( $vars ) {
$rlContext = $this->getRlClientContext();
$chunks[] = ResourceLoader::makeInlineScript(
'mw.config.set(' . $rlContext->encodeJson( $vars ) . ');',
$this->CSP->getNonce()
);
if ( $this->getConfig()->get( MainConfigNames::ShowHostnames ) ) {
$vars['wgHostname'] = wfHostname();
}
// Keep the hook appendage separate to preserve WrappedString objects.
// This enables BaseTemplate::getTrail() to merge them where possible.
$this->getHookRunner()->onSkinAfterBottomScripts( $this->getSkin(), $extraHtml );
$elapsed = $this->getRequest()->getElapsedTime();
// seconds to milliseconds
$vars['wgBackendResponseTime'] = round( $elapsed * 1000 );
$rlContext = $this->getRlClientContext();
$chunks[] = ResourceLoader::makeInlineScript(
'mw.config.set(' . $rlContext->encodeJson( $vars ) . ');',
$this->CSP->getNonce()
);
$chunks = [ self::combineWrappedStrings( $chunks ) ];
if ( $extraHtml !== '' ) {
$chunks[] = $extraHtml;
@ -4607,7 +4615,6 @@ class OutputPage extends ContextSource {
$tail = [
MWDebug::getDebugHTML( $skin ),
$this->getBottomScripts( $extraHtml ),
wfReportTime( $this->getCSP()->getNonce() ),
MWDebug::getHTMLDebugLog(),
Html::closeElement( 'body' ),
Html::closeElement( 'html' ),