Merge "mediawiki.action.edit: Move collapsibleFooter cookies to localStorage"
[lhc/web/wiklou.git] / includes / EditPage.php
index 2b1bd7b..a02392e 100644 (file)
@@ -993,7 +993,7 @@ class EditPage {
                        $this->recreate = false;
 
                        // When creating a new section, we can preload a section title by passing it as the
-                       // preloadtitle parameter in the URL (Bug 13100)
+                       // preloadtitle parameter in the URL (T15100)
                        if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
                                $this->sectiontitle = $request->getVal( 'preloadtitle' );
                                // Once wpSummary isn't being use for setting section titles, we should delete this.
@@ -1256,7 +1256,7 @@ class EditPage {
                $revision = $this->mArticle->getRevisionFetched();
                if ( $revision === null ) {
                        if ( !$this->contentModel ) {
-                               $this->contentModel = $this->getTitle()->getContentModel();
+                               throw new RuntimeException( 'EditPage contentModel was false' );
                        }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
 
@@ -1300,7 +1300,7 @@ class EditPage {
 
                if ( $content === false || $content === null ) {
                        if ( !$this->contentModel ) {
-                               $this->contentModel = $this->getTitle()->getContentModel();
+                               throw new RuntimeException( 'EditPage contentModel was false' );
                        }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
 
@@ -1911,7 +1911,7 @@ class EditPage {
 
                        // Don't save a new page if it's blank or if it's a MediaWiki:
                        // message with content equivalent to default (allow empty pages
-                       // in this case to disable messages, see bug 50124)
+                       // in this case to disable messages, see T52124)
                        $defaultMessageText = $this->mTitle->getDefaultMessageText();
                        if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
                                $defaultText = $defaultMessageText;
@@ -2483,11 +2483,13 @@ class EditPage {
                }
                # Give a notice if the user is editing a deleted/moved page...
                if ( !$this->mTitle->exists() ) {
+                       $dbr = wfGetDB( DB_REPLICA );
+
                        LogEventsList::showLogExtract( $wgOut, [ 'delete', 'move' ], $this->mTitle,
                                '',
                                [
                                        'lim' => 10,
-                                       'conds' => [ "log_action != 'revision'" ],
+                                       'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
                                        'showIfEmpty' => false,
                                        'msgKey' => [ 'recreate-moveddeleted-warn' ]
                                ]
@@ -2616,7 +2618,7 @@ class EditPage {
                        return;
                }
 
-               $this->showHeader();
+               $this->showHeader();
 
                $wgOut->addHTML( $this->editFormPageTop );
 
@@ -2729,7 +2731,7 @@ class EditPage {
                if ( $this->hasPresetSummary ) {
                        // If a summary has been preset using &summary= we don't want to prompt for
                        // a different summary. Only prompt for a summary if the summary is blanked.
-                       // (Bug 17416)
+                       // (T19416)
                        $this->autoSumm = md5( '' );
                }
 
@@ -3543,15 +3545,7 @@ HTML
                // Avoid PHP 7.1 warning of passing $this by reference
                $editPage = $this;
                if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$wgOut ] ) ) {
-                       $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-                       $stats->increment( 'edit.failures.conflict' );
-                       // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
-                       if (
-                               $this->mTitle->getNamespace() >= NS_MAIN &&
-                               $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
-                       ) {
-                               $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
-                       }
+                       $this->incrementConflictStats();
 
                        $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
 
@@ -3571,6 +3565,18 @@ HTML
                }
        }
 
+       protected function incrementConflictStats() {
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+               $stats->increment( 'edit.failures.conflict' );
+               // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
+               if (
+                       $this->mTitle->getNamespace() >= NS_MAIN &&
+                       $this->mTitle->getNamespace() <= NS_CATEGORY_TALK
+               ) {
+                       $stats->increment( 'edit.failures.conflict.byNamespaceId.' . $this->mTitle->getNamespace() );
+               }
+       }
+
        /**
         * @return string
         */
@@ -3683,8 +3689,6 @@ HTML
                global $wgOut, $wgRawHtml, $wgLang;
                global $wgAllowUserCss, $wgAllowUserJs;
 
-               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
-
                if ( $wgRawHtml && !$this->mTokenOk ) {
                        // Could be an offsite preview attempt. This is very unsafe if
                        // HTML is enabled, as it could be an attack.
@@ -3697,7 +3701,7 @@ HTML
                                        $this->context->msg( 'session_fail_preview_html' )->text() . "</div>",
                                        true, /* interface */true );
                        }
-                       $stats->increment( 'edit.failures.session_loss' );
+                       $this->incrementEditFailureStats( 'session_loss' );
                        return $parsedNote;
                }
 
@@ -3721,15 +3725,15 @@ HTML
                        if ( $this->mTriedSave && !$this->mTokenOk ) {
                                if ( $this->mTokenOkExceptSuffix ) {
                                        $note = $this->context->msg( 'token_suffix_mismatch' )->plain();
-                                       $stats->increment( 'edit.failures.bad_token' );
+                                       $this->incrementEditFailureStats( 'bad_token' );
                                } else {
                                        $note = $this->context->msg( 'session_fail_preview' )->plain();
-                                       $stats->increment( 'edit.failures.session_loss' );
+                                       $this->incrementEditFailureStats( 'session_loss' );
                                }
                        } elseif ( $this->incompleteForm ) {
                                $note = $this->context->msg( 'edit_form_incomplete' )->plain();
                                if ( $this->mTriedSave ) {
-                                       $stats->increment( 'edit.failures.incomplete_form' );
+                                       $this->incrementEditFailureStats( 'incomplete_form' );
                                }
                        } else {
                                $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
@@ -3817,6 +3821,11 @@ HTML
                return $previewhead . $previewHTML . $this->previewTextAfterContent;
        }
 
+       private function incrementEditFailureStats( $failureType ) {
+               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+               $stats->increment( 'edit.failures.' . $failureType );
+       }
+
        /**
         * Get parser options for a preview
         * @return ParserOptions