Show wgPageParseReport on page previews too
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 5 Aug 2016 21:41:40 +0000 (14:41 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 5 Aug 2016 21:41:47 +0000 (14:41 -0700)
Also make EditPage::getPreviewLimitReport return the same
output instead of using copy-pasted code from the old hook.

Bug: T142210
Bug: T142214
Change-Id: I16c3c2da067fd24bf7ae564cb1d61beaa3be58c1

includes/EditPage.php
includes/OutputPage.php

index 674cf28..ee06993 100644 (file)
@@ -2714,8 +2714,9 @@ class EditPage {
                $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
                        Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
 
-               $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
-                       self::getPreviewLimitReport( $this->mParserOutput ) ) );
+               if ( $this->mParserOutput ) {
+                       $wgOut->setLimitReportData( $this->mParserOutput->getLimitReportData() );
+               }
 
                $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
 
@@ -3442,41 +3443,12 @@ HTML
                        return '';
                }
 
-               $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
-                       wfMessage( 'limitreport-title' )->parseAsBlock()
+               return ResourceLoader::makeInlineScript(
+                       ResourceLoader::makeConfigSetScript(
+                               [ 'wgPageParseReport' => $output->getLimitReportData() ],
+                               true
+                       )
                );
-
-               // Show/hide animation doesn't work correctly on a table, so wrap it in a div.
-               $limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] );
-
-               $limitReport .= Html::openElement( 'table', [
-                       'class' => 'preview-limit-report wikitable'
-               ] ) .
-                       Html::openElement( 'tbody' );
-
-               foreach ( $output->getLimitReportData() as $key => $value ) {
-                       if ( Hooks::run( 'ParserLimitReportFormat',
-                               [ $key, &$value, &$limitReport, true, true ]
-                       ) ) {
-                               $keyMsg = wfMessage( $key );
-                               $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
-                               if ( !$valueMsg->exists() ) {
-                                       $valueMsg = new RawMessage( '$1' );
-                               }
-                               if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
-                                       $limitReport .= Html::openElement( 'tr' ) .
-                                               Html::rawElement( 'th', null, $keyMsg->parse() ) .
-                                               Html::rawElement( 'td', null, $valueMsg->params( $value )->parse() ) .
-                                               Html::closeElement( 'tr' );
-                               }
-                       }
-               }
-
-               $limitReport .= Html::closeElement( 'tbody' ) .
-                       Html::closeElement( 'table' ) .
-                       Html::closeElement( 'div' );
-
-               return $limitReport;
        }
 
        protected function showStandardInputs( &$tabindex = 2 ) {
index b6c48ab..b88db92 100644 (file)
@@ -1773,7 +1773,7 @@ class OutputPage extends ContextSource {
                }
 
                // Include profiling data
-               $this->limitReportData = $parserOutput->getLimitReportData();
+               $this->setLimitReportData( $parserOutput->getLimitReportData() );
 
                // Link flags are ignored for now, but may in the future be
                // used to mark individual language links.
@@ -4051,4 +4051,12 @@ class OutputPage extends ContextSource {
                // public API or you'll be severely disappointed when T87871 is fixed and it disappears.
                $this->addMeta( 'X-OOUI-PHP', '1' );
        }
+
+       /**
+        * @param array $data Data from ParserOutput::getLimitReportData()
+        * @since 1.28
+        */
+       public function setLimitReportData( array $data ) {
+               $this->limitReportData = $data;
+       }
 }