Re-add human readable parser limit report
[lhc/web/wiklou.git] / includes / EditPage.php
index 406673d..0d8def3 100644 (file)
@@ -1613,8 +1613,9 @@ class EditPage {
        protected function runPostMergeFilters( Content $content, Status $status, User $user ) {
                // Run old style post-section-merge edit filter
                if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged',
-                       [ $this, $content, &$this->hookError, $this->summary ] )
-               ) {
+                       [ $this, $content, &$this->hookError, $this->summary ],
+                       '1.21'
+               ) ) {
                        # Error messages etc. could be handled within the hook...
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR;
@@ -1639,7 +1640,7 @@ class EditPage {
                                // being set. This is used by ConfirmEdit to display a captcha
                                // without any error message cruft.
                        } else {
-                               $this->hookError = $status->getWikiText();
+                               $this->hookError = $this->formatStatusErrors( $status );
                        }
                        // Use the existing $status->value if the hook set it
                        if ( !$status->value ) {
@@ -1649,7 +1650,7 @@ class EditPage {
                } elseif ( !$status->isOK() ) {
                        # ...or the hook could be expecting us to produce an error
                        // FIXME this sucks, we should just use the Status object throughout
-                       $this->hookError = $status->getWikiText();
+                       $this->hookError = $this->formatStatusErrors( $status );
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR_EXPECTED;
                        return false;
@@ -1658,6 +1659,26 @@ class EditPage {
                return true;
        }
 
+       /**
+        * Wrap status errors in an errorbox for increased visiblity
+        *
+        * @param Status $status
+        * @return string
+        */
+       private function formatStatusErrors( Status $status ) {
+               $errmsg = $status->getHTML(
+                       'edit-error-short',
+                       'edit-error-long',
+                       $this->context->getLanguage()
+               );
+               return <<<ERROR
+<div class="errorbox">
+{$errmsg}
+</div>
+<br clear="all" />
+ERROR;
+       }
+
        /**
         * Return the summary to be used for a new section.
         *
@@ -2766,9 +2787,8 @@ class EditPage {
                $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
                        Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
 
-               if ( $this->mParserOutput ) {
-                       $wgOut->setLimitReportData( $this->mParserOutput->getLimitReportData() );
-               }
+               $wgOut->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
+                       self::getPreviewLimitReport( $this->mParserOutput ) ) );
 
                $wgOut->addModules( 'mediawiki.action.edit.collapsibleFooter' );
 
@@ -3305,6 +3325,23 @@ HTML
                        'style' => ''
                ];
 
+               // The following classes can be used here:
+               // * mw-editfont-default
+               // * mw-editfont-monospace
+               // * mw-editfont-sans-serif
+               // * mw-editfont-serif
+               $class = 'mw-editfont-' . $wgUser->getOption( 'editfont' );
+
+               if ( isset( $attribs['class'] ) ) {
+                       if ( is_string( $attribs['class'] ) ) {
+                               $attribs['class'] .= ' ' . $class;
+                       } elseif ( is_array( $attribs['class'] ) ) {
+                               $attribs['class'][] = $class;
+                       }
+               } else {
+                       $attribs['class'] = $class;
+               }
+
                $pageLang = $this->mTitle->getPageLanguage();
                $attribs['lang'] = $pageLang->getHtmlCode();
                $attribs['dir'] = $pageLang->getDir();
@@ -3410,7 +3447,7 @@ HTML
                }
 
                if ( $newContent ) {
-                       ContentHandler::runLegacyHooks( 'EditPageGetDiffText', [ $this, &$newContent ] );
+                       ContentHandler::runLegacyHooks( 'EditPageGetDiffText', [ $this, &$newContent ], '1.21' );
                        Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] );
 
                        $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
@@ -3496,7 +3533,7 @@ HTML
         * @param string $format Output format, valid values are any function of a Message object
         * @return string
         */
-       public static function getCopyrightWarning( $title, $format = 'plain' ) {
+       public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
                global $wgRightsText;
                if ( $wgRightsText ) {
                        $copywarnMsg = [ 'copyrightwarning',
@@ -3509,8 +3546,12 @@ HTML
                // Allow for site and per-namespace customization of contribution/copyright notice.
                Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] );
 
+               $msg = call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title );
+               if ( $langcode ) {
+                       $msg->inLanguage( $langcode );
+               }
                return "<div id=\"editpage-copywarn\">\n" .
-                       call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title )->$format() . "\n</div>";
+                       $msg->$format() . "\n</div>";
        }
 
        /**
@@ -3525,12 +3566,47 @@ HTML
                        return '';
                }
 
-               return ResourceLoader::makeInlineScript(
-                       ResourceLoader::makeConfigSetScript(
-                               [ 'wgPageParseReport' => $output->getLimitReportData() ],
-                               true
-                       )
+               $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
+                       wfMessage( 'limitreport-title' )->parseAsBlock()
                );
+
+               // 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()['limitreport'] as $key => $value ) {
+                       if ( Hooks::run( 'ParserLimitReportFormat',
+                               [ $key, &$value, &$limitReport, true, true ]
+                       ) ) {
+                               $keyMsg = wfMessage( "limitreport-$key" );
+                               $valueMsg = wfMessage(
+                                       [ "limitreport-$key-value-html", "limitreport-$key-value" ]
+                               );
+                               if ( !$valueMsg->exists() ) {
+                                       $valueMsg = new RawMessage( '$1' );
+                               }
+                               if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
+                                       // If it's a value/limit array, convert it for $1/$2
+                                       if ( is_array( $value ) && isset( $value['value'] ) ) {
+                                               $value = [ $value['value'], $value['limit'] ];
+                                       }
+                                       $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 ) {
@@ -3819,7 +3895,7 @@ HTML
                        }
 
                        $hook_args = [ $this, &$content ];
-                       ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args );
+                       ContentHandler::runLegacyHooks( 'EditPageGetPreviewText', $hook_args, '1.25' );
                        Hooks::run( 'EditPageGetPreviewContent', $hook_args );
 
                        $parserResult = $this->doPreviewParse( $content );
@@ -4145,7 +4221,7 @@ HTML
                        'name' => 'wpSave',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'save' );
-               $buttons['save'] = Html::submitButton( $buttonLabel, $attribs, [ 'mw-ui-constructive' ] );
+               $buttons['save'] = Html::submitButton( $buttonLabel, $attribs, [ 'mw-ui-progressive' ] );
 
                ++$tabindex; // use the same for preview and live preview
                $attribs = [
@@ -4263,7 +4339,7 @@ HTML
        protected function safeUnicodeOutput( $text ) {
                return $this->checkUnicodeCompliantBrowser()
                        ? $text
-                       : $this->makesafe( $text );
+                       : $this->makeSafe( $text );
        }
 
        /**