Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / EditPage.php
index ad308b1..f37ce34 100644 (file)
@@ -2326,9 +2326,12 @@ class EditPage {
        }
 
        function setHeaders() {
-               global $wgOut, $wgUser, $wgAjaxEditStash;
+               global $wgOut, $wgUser, $wgAjaxEditStash, $wgCookieSetOnAutoblock;
 
                $wgOut->addModules( 'mediawiki.action.edit' );
+               if ( $wgCookieSetOnAutoblock === true ) {
+                       $wgOut->addModules( 'mediawiki.user.blockcookie' );
+               }
                $wgOut->addModuleStyles( 'mediawiki.action.edit.styles' );
 
                if ( $wgUser->getOption( 'showtoolbar' ) ) {
@@ -2598,10 +2601,21 @@ class EditPage {
 
                $this->setHeaders();
 
-               if ( $this->showHeader() === false ) {
+               $this->addTalkPageText();
+               $this->addEditNotices();
+
+               if ( !$this->isConflict &&
+                       $this->section != '' &&
+                       !$this->isSectionEditSupported() ) {
+                       // We use $this->section to much before this and getVal('wgSection') directly in other places
+                       // at this point we can't reset $this->section to '' to fallback to non-section editing.
+                       // Someone is welcome to try refactoring though
+                       $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
                        return;
                }
 
+               $this->showHeader();
+
                $wgOut->addHTML( $this->editFormPageTop );
 
                if ( $wgUser->getOption( 'previewontop' ) ) {
@@ -2854,29 +2868,14 @@ class EditPage {
                }
        }
 
-       /**
-        * @return bool
-        */
        protected function showHeader() {
-               global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
+               global $wgOut, $wgUser;
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $this->addTalkPageText();
-
-               $this->addEditNotices();
-
                if ( $this->isConflict ) {
-                       $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
+                       $this->addExplainConflictHeader( $wgOut );
                        $this->editRevId = $this->page->getLatest();
                } else {
-                       if ( $this->section != '' && !$this->isSectionEditSupported() ) {
-                               // We use $this->section to much before this and getVal('wgSection') directly in other places
-                               // at this point we can't reset $this->section to '' to fallback to non-section editing.
-                               // Someone is welcome to try refactoring though
-                               $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
-                               return false;
-                       }
-
                        if ( $this->section != '' && $this->section != 'new' ) {
                                if ( !$this->summary && !$this->preview && !$this->diff ) {
                                        $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
@@ -3002,69 +3001,12 @@ class EditPage {
                        }
                }
 
-               if ( $this->mTitle->isProtected( 'edit' ) &&
-                       MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
-               ) {
-                       # Is the title semi-protected?
-                       if ( $this->mTitle->isSemiProtected() ) {
-                               $noticeMsg = 'semiprotectedpagewarning';
-                       } else {
-                               # Then it must be protected based on static groups (regular)
-                               $noticeMsg = 'protectedpagewarning';
-                       }
-                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
-                               [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
-               }
-               if ( $this->mTitle->isCascadeProtected() ) {
-                       # Is this page under cascading protection from some source pages?
-                       /** @var Title[] $cascadeSources */
-                       list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
-                       $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
-                       $cascadeSourcesCount = count( $cascadeSources );
-                       if ( $cascadeSourcesCount > 0 ) {
-                               # Explain, and list the titles responsible
-                               foreach ( $cascadeSources as $page ) {
-                                       $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
-                               }
-                       }
-                       $notice .= '</div>';
-                       $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
-               }
-               if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
-                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
-                               [ 'lim' => 1,
-                                       'showIfEmpty' => false,
-                                       'msgKey' => [ 'titleprotectedwarning' ],
-                                       'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
-               }
+               $this->addPageProtectionWarningHeaders();
 
-               if ( $this->contentLength === false ) {
-                       $this->contentLength = strlen( $this->textbox1 );
-               }
+               $this->addLongPageWarningHeader();
 
-               if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
-                       $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
-                               [
-                                       'longpageerror',
-                                       $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ),
-                                       $wgLang->formatNum( $wgMaxArticleSize )
-                               ]
-                       );
-               } else {
-                       if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
-                               $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
-                                       [
-                                               'longpage-hint',
-                                               $wgLang->formatSize( strlen( $this->textbox1 ) ),
-                                               strlen( $this->textbox1 )
-                                       ]
-                               );
-                       }
-               }
                # Add header copyright warning
                $this->showHeaderCopyrightWarning();
-
-               return true;
        }
 
        /**
@@ -3279,44 +3221,9 @@ HTML
                global $wgOut, $wgUser;
 
                $wikitext = $this->safeUnicodeOutput( $text );
-               if ( strval( $wikitext ) !== '' ) {
-                       // Ensure there's a newline at the end, otherwise adding lines
-                       // is awkward.
-                       // But don't add a newline if the ext is empty, or Firefox in XHTML
-                       // mode will show an extra newline. A bit annoying.
-                       $wikitext .= "\n";
-               }
+               $wikitext = $this->addNewLineAtEnd( $wikitext );
 
-               $attribs = $customAttribs + [
-                       'accesskey' => ',',
-                       'id' => $name,
-                       'cols' => $wgUser->getIntOption( 'cols' ),
-                       'rows' => $wgUser->getIntOption( 'rows' ),
-                       // 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();
+               $attribs = $this->buildTextboxAttribs( $name, $customAttribs, $wgUser );
 
                $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
        }
@@ -3419,7 +3326,6 @@ HTML
                }
 
                if ( $newContent ) {
-                       ContentHandler::runLegacyHooks( 'EditPageGetDiffText', [ $this, &$newContent ], '1.21' );
                        Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] );
 
                        $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
@@ -3503,6 +3409,7 @@ HTML
         *
         * @param Title $title
         * @param string $format Output format, valid values are any function of a Message object
+        * @param Language|string|null $langcode Language code or Language object.
         * @return string
         */
        public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
@@ -3630,7 +3537,7 @@ HTML
                global $wgOut;
 
                if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$this, &$wgOut ] ) ) {
-                       $stats = $wgOut->getContext()->getStats();
+                       $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                        $stats->increment( 'edit.failures.conflict' );
                        // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
                        if (
@@ -3769,7 +3676,7 @@ HTML
                global $wgOut, $wgRawHtml, $wgLang;
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $stats = $wgOut->getContext()->getStats();
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
 
                if ( $wgRawHtml && !$this->mTokenOk ) {
                        // Could be an offsite preview attempt. This is very unsafe if
@@ -4163,7 +4070,7 @@ HTML
 
        /**
         * Returns an array of html code of the following buttons:
-        * save, diff, preview and live
+        * save, diff and preview
         *
         * @param int $tabindex Current tabindex
         *
@@ -4197,7 +4104,6 @@ HTML
                ] + Linker::tooltipAndAccesskeyAttribs( 'preview' );
                $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(),
                        $attribs );
-               $buttons['live'] = '';
 
                $attribs = [
                        'id' => 'wpDiff',
@@ -4422,4 +4328,145 @@ HTML
                        $wgOut->addWikiMsg( 'talkpagetext' );
                }
        }
+
+       /**
+        * @since 1.29
+        */
+       protected function addLongPageWarningHeader() {
+               global $wgMaxArticleSize, $wgOut, $wgLang;
+
+               if ( $this->contentLength === false ) {
+                       $this->contentLength = strlen( $this->textbox1 );
+               }
+
+               if ( $this->tooBig || $this->contentLength > $wgMaxArticleSize * 1024 ) {
+                       $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
+                               [
+                                       'longpageerror',
+                                       $wgLang->formatNum( round( $this->contentLength / 1024, 3 ) ),
+                                       $wgLang->formatNum( $wgMaxArticleSize )
+                               ]
+                       );
+               } else {
+                       if ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
+                               $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
+                                       [
+                                               'longpage-hint',
+                                               $wgLang->formatSize( strlen( $this->textbox1 ) ),
+                                               strlen( $this->textbox1 )
+                                       ]
+                               );
+                       }
+               }
+       }
+
+       /**
+        * @since 1.29
+        */
+       protected function addPageProtectionWarningHeaders() {
+               global $wgOut;
+
+               if ( $this->mTitle->isProtected( 'edit' ) &&
+                       MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
+               ) {
+                       # Is the title semi-protected?
+                       if ( $this->mTitle->isSemiProtected() ) {
+                               $noticeMsg = 'semiprotectedpagewarning';
+                       } else {
+                               # Then it must be protected based on static groups (regular)
+                               $noticeMsg = 'protectedpagewarning';
+                       }
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
+                               [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
+               }
+               if ( $this->mTitle->isCascadeProtected() ) {
+                       # Is this page under cascading protection from some source pages?
+                       /** @var Title[] $cascadeSources */
+                       list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
+                       $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
+                       $cascadeSourcesCount = count( $cascadeSources );
+                       if ( $cascadeSourcesCount > 0 ) {
+                               # Explain, and list the titles responsible
+                               foreach ( $cascadeSources as $page ) {
+                                       $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
+                               }
+                       }
+                       $notice .= '</div>';
+                       $wgOut->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
+               }
+               if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle, '',
+                               [ 'lim' => 1,
+                                       'showIfEmpty' => false,
+                                       'msgKey' => [ 'titleprotectedwarning' ],
+                                       'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
+               }
+       }
+
+       /**
+        * @param OutputPage $out
+        * @since 1.29
+        */
+       protected function addExplainConflictHeader( OutputPage $out ) {
+               $out->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
+       }
+
+       /**
+        * @param string $name
+        * @param mixed[] $customAttribs
+        * @param User $user
+        * @return mixed[]
+        * @since 1.29
+        */
+       protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) {
+               $attribs = $customAttribs + [
+                               'accesskey' => ',',
+                               'id' => $name,
+                               'cols' => $user->getIntOption( 'cols' ),
+                               'rows' => $user->getIntOption( 'rows' ),
+                               // 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-' . $user->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();
+
+               return $attribs;
+       }
+
+       /**
+        * @param string $wikitext
+        * @return string
+        * @since 1.29
+        */
+       protected function addNewLineAtEnd( $wikitext ) {
+               if ( strval( $wikitext ) !== '' ) {
+                       // Ensure there's a newline at the end, otherwise adding lines
+                       // is awkward.
+                       // But don't add a newline if the text is empty, or Firefox in XHTML
+                       // mode will show an extra newline. A bit annoying.
+                       $wikitext .= "\n";
+                       return $wikitext;
+               }
+               return $wikitext;
+       }
 }