Merge "registration: Don't initialize MWServices super early"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 9bae882..211f44b 100644 (file)
@@ -299,6 +299,9 @@ class OutputPage extends ContextSource {
         */
        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
@@ -1266,10 +1269,12 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                # Add the remaining categories to the skin
                if ( Hooks::run(
                        'OutputPageMakeCategoryLinks',
-                       [ &$this, $categories, &$this->mCategoryLinks ] )
+                       [ &$outputPage, $categories, &$this->mCategoryLinks ] )
                ) {
                        $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                        foreach ( $categories as $category => $type ) {
@@ -1802,16 +1807,23 @@ class OutputPage extends ContextSource {
                        }
                }
 
-               // 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
                // used to mark individual language links.
                $linkFlags = [];
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] );
-               Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] );
+               Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] );
        }
 
        /**
@@ -1839,7 +1851,9 @@ class OutputPage extends ContextSource {
         */
        public function addParserOutputText( $parserOutput ) {
                $text = $parserOutput->getText();
-               Hooks::run( 'OutputPageBeforeHTML', [ &$this, &$text ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
+               Hooks::run( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
                $this->addHTML( $text );
        }
 
@@ -2358,9 +2372,11 @@ class OutputPage extends ContextSource {
                        }
                        MWDebug::addModules( $this );
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $outputPage = $this;
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
-                       Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] );
+                       Hooks::run( 'BeforePageDisplay', [ &$outputPage, &$sk ] );
 
                        try {
                                $sk->outputPage();
@@ -2997,6 +3013,14 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               if ( $this->limitReportJSData ) {
+                       $chunks[] = ResourceLoader::makeInlineScript(
+                               ResourceLoader::makeConfigSetScript(
+                                       [ 'wgPageParseReport' => $this->limitReportJSData ]
+                               )
+                       );
+               }
+
                return self::combineWrappedStrings( $chunks );
        }