jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/320861 )

Change subject: Include JS variable for NewPP report
......................................................................


Include JS variable for NewPP report

Adapted from reverted commit b7c4c8717f9.

Bug: T110763
Change-Id: If249b679c534879bfac622592a1d2fa913a0cf9d
---
M RELEASE-NOTES-1.29
M includes/OutputPage.php
M includes/parser/Parser.php
M includes/parser/ParserOutput.php
4 files changed, 64 insertions(+), 5 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29
index 72c82de..b886738 100644
--- a/RELEASE-NOTES-1.29
+++ b/RELEASE-NOTES-1.29
@@ -37,6 +37,8 @@
   dnsbls, are now indicated as such and use a new i18n message when displayed.
 * Added new $wgHTTPImportTimeout setting. Sets timeout for
   downloading the XML dump during a transwiki import in seconds.
+* Parser limit report is now available in machine-readable format to JavaScript
+  via mw.config.get('wgPageParseReport').
 
 === External library changes in 1.29 ===
 
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index f140f54..211f44b 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -299,6 +299,9 @@
         */
        private $copyrightUrl;
 
+       /** @var array Profiling data */
+       private $limitReportJSData = [];
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will 
implicitly create
@@ -1804,9 +1807,14 @@
                        }
                }
 
-               // enable OOUI if requested via ParserOutput
+               // Enable OOUI if requested via ParserOutput
                if ( $parserOutput->getEnableOOUI() ) {
                        $this->enableOOUI();
+               }
+
+               // Include parser limit report
+               if ( !$this->limitReportJSData ) {
+                       $this->limitReportJSData = 
$parserOutput->getLimitReportJSData();
                }
 
                // Link flags are ignored for now, but may in the future be
@@ -3005,6 +3013,14 @@
                        }
                }
 
+               if ( $this->limitReportJSData ) {
+                       $chunks[] = ResourceLoader::makeInlineScript(
+                               ResourceLoader::makeConfigSetScript(
+                                       [ 'wgPageParseReport' => 
$this->limitReportJSData ]
+                               )
+                       );
+               }
+
                return self::combineWrappedStrings( $chunks );
        }
 
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 0e9aa59..157946c 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -547,18 +547,32 @@
                        $limitReport = str_replace( [ '-', '&' ], [ '‐', 
'&' ], $limitReport );
                        $text .= "\n<!-- \n$limitReport-->\n";
 
-                       // Add on template profiling data
+                       // Add on template profiling data in human/machine 
readable way
                        $dataByFunc = $this->mProfiler->getFunctionStats();
                        uasort( $dataByFunc, function ( $a, $b ) {
                                return $a['real'] < $b['real']; // descending 
order
                        } );
-                       $profileReport = "Transclusion expansion time report 
(%,ms,calls,template)\n";
+                       $profileReport = [];
                        foreach ( array_slice( $dataByFunc, 0, 10 ) as $item ) {
-                               $profileReport .= sprintf( "%6.2f%% %8.3f %6d - 
%s\n",
+                               $profileReport[] = sprintf( "%6.2f%% %8.3f %6d 
%s",
                                        $item['%real'], $item['real'], 
$item['calls'],
                                        htmlspecialchars( $item['name'] ) );
                        }
-                       $text .= "\n<!-- \n$profileReport-->\n";
+                       $text .= "<!--\nTransclusion expansion time report 
(%,ms,calls,template)\n";
+                       $text .= implode( "\n", $profileReport ) . "\n-->\n";
+
+                       $this->mOutput->setLimitReportData( 
'limitreport-timingprofile', $profileReport );
+
+                       // Add other cache related metadata
+                       if ( $wgShowHostnames ) {
+                               $this->mOutput->setLimitReportData( 
'cachereport-origin', wfHostname() );
+                       }
+                       $this->mOutput->setLimitReportData( 
'cachereport-timestamp',
+                               $this->mOutput->getCacheTime() );
+                       $this->mOutput->setLimitReportData( 'cachereport-ttl',
+                               $this->mOutput->getCacheExpiry() );
+                       $this->mOutput->setLimitReportData( 
'cachereport-transientcontent',
+                               $this->mOutput->hasDynamicContent() );
 
                        if ( $this->mGeneratedPPNodeCount > 
$this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) {
                                wfDebugLog( 'generated-pp-node-count', 
$this->mGeneratedPPNodeCount . ' ' .
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index bfaa4f7..7bf848f 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -193,6 +193,9 @@
         */
        private $mLimitReportData = [];
 
+       /** @var array Parser limit report data for JSON */
+       private $mLimitReportJSData = [];
+
        /**
         * @var array $mParseStartTime Timestamps for getTimeSinceStart().
         */
@@ -409,6 +412,10 @@
 
        public function getLimitReportData() {
                return $this->mLimitReportData;
+       }
+
+       public function getLimitReportJSData() {
+               return $this->mLimitReportJSData;
        }
 
        public function getTOCEnabled() {
@@ -1010,6 +1017,26 @@
         */
        public function setLimitReportData( $key, $value ) {
                $this->mLimitReportData[$key] = $value;
+
+               if ( is_array( $value ) ) {
+                       if ( array_keys( $value ) === [ 0, 1 ]
+                               && is_numeric( $value[0] )
+                               && is_numeric( $value[1] )
+                       ) {
+                               $data = [ 'value' => $value[0], 'limit' => 
$value[1] ];
+                       } else {
+                               $data = $value;
+                       }
+               } else {
+                       $data = $value;
+               }
+
+               if ( strpos( $key, '-' ) ) {
+                       list( $ns, $name ) = explode( '-', $key, 2 );
+                       $this->mLimitReportJSData[$ns][$name] = $data;
+               } else {
+                       $this->mLimitReportJSData[$key] = $data;
+               }
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/320861
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If249b679c534879bfac622592a1d2fa913a0cf9d
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to