[search] Remove unused SpecialSearch functions
[lhc/web/wiklou.git] / includes / EditPage.php
index c0c0048..9c5c91a 100644 (file)
@@ -22,6 +22,7 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\ScopedCallback;
 
 /**
  * The edit page/HTML interface (split from Article)
@@ -407,6 +408,11 @@ class EditPage {
         */
        protected $context;
 
+       /**
+        * @var bool Whether an old revision is edited
+        */
+       private $isOldRev = false;
+
        /**
         * @param Article $article
         */
@@ -1038,7 +1044,6 @@ class EditPage {
 
                // Allow extensions to modify form data
                Hooks::run( 'EditPage::importFormData', [ $this, $request ] );
-
        }
 
        /**
@@ -1613,8 +1618,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;
@@ -2230,7 +2236,6 @@ class EditPage {
         * @return bool
         */
        private function mergeChangesIntoContent( &$editContent ) {
-
                $db = wfGetDB( DB_MASTER );
 
                // This is the revision the editor started from
@@ -2766,9 +2771,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' );
 
@@ -2807,7 +2811,6 @@ class EditPage {
                if ( !$wgUser->getOption( 'previewontop' ) ) {
                        $this->displayPreviewArea( $previewOutput, false );
                }
-
        }
 
        /**
@@ -2833,7 +2836,6 @@ class EditPage {
                return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
                        $templateListFormatter->format( $templates, $type )
                );
-
        }
 
        /**
@@ -2859,24 +2861,9 @@ class EditPage {
                global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               if ( $this->mTitle->isTalkPage() ) {
-                       $wgOut->addWikiMsg( 'talkpagetext' );
-               }
+               $this->addTalkPageText();
 
-               // Add edit notices
-               $editNotices = $this->mTitle->getEditNotices( $this->oldid );
-               if ( count( $editNotices ) ) {
-                       $wgOut->addHTML( implode( "\n", $editNotices ) );
-               } else {
-                       $msg = $this->context->msg( 'editnotice-notext' );
-                       if ( !$msg->isDisabled() ) {
-                               $wgOut->addHTML(
-                                       '<div class="mw-editnotice-notext">'
-                                       . $msg->parseAsBlock()
-                                       . '</div>'
-                               );
-                       }
-               }
+               $this->addEditNotices();
 
                if ( $this->isConflict ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
@@ -2947,6 +2934,7 @@ class EditPage {
                                        if ( !$revision->isCurrent() ) {
                                                $this->mArticle->setOldSubtitle( $revision->getId() );
                                                $wgOut->addWikiMsg( 'editingold' );
+                                               $this->isOldRev = true;
                                        }
                                } elseif ( $this->mTitle->exists() ) {
                                        // Something went wrong
@@ -3257,6 +3245,10 @@ HTML
                                        $classes[] = 'mw-textarea-cprotected';
                                }
                        }
+                       # Is an old revision being edited?
+                       if ( $this->isOldRev ) {
+                               $classes[] = 'mw-textarea-oldrev';
+                       }
 
                        $attribs = [ 'tabindex' => 1 ];
 
@@ -3300,17 +3292,28 @@ HTML
                        'id' => $name,
                        'cols' => $wgUser->getIntOption( 'cols' ),
                        'rows' => $wgUser->getIntOption( 'rows' ),
-                       // 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' ),
                        // Avoid PHP notices when appending preferences
                        // (appending allows customAttribs['style'] to still work).
                        '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();
@@ -3416,7 +3419,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 );
@@ -3535,12 +3538,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 ) {
@@ -3829,7 +3867,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 );
@@ -4358,4 +4396,36 @@ HTML
                // reverse the transform that we made for reversibility reasons.
                return strtr( $result, [ "&#x0" => "&#x" ] );
        }
+
+       /**
+        * @since 1.29
+        */
+       protected function addEditNotices() {
+               global $wgOut;
+
+               $editNotices = $this->mTitle->getEditNotices( $this->oldid );
+               if ( count( $editNotices ) ) {
+                       $wgOut->addHTML( implode( "\n", $editNotices ) );
+               } else {
+                       $msg = $this->context->msg( 'editnotice-notext' );
+                       if ( !$msg->isDisabled() ) {
+                               $wgOut->addHTML(
+                                       '<div class="mw-editnotice-notext">'
+                                       . $msg->parseAsBlock()
+                                       . '</div>'
+                               );
+                       }
+               }
+       }
+
+       /**
+        * @since 1.29
+        */
+       protected function addTalkPageText() {
+               global $wgOut;
+
+               if ( $this->mTitle->isTalkPage() ) {
+                       $wgOut->addWikiMsg( 'talkpagetext' );
+               }
+       }
 }