Merge "Allow filtering by username on Special:NewFiles"
[lhc/web/wiklou.git] / includes / EditPage.php
index a45c889..ac62e3f 100644 (file)
@@ -363,8 +363,8 @@ class EditPage {
        /** @var bool */
        public $bot = true;
 
-       /** @var null|string */
-       public $contentModel = null;
+       /** @var string */
+       public $contentModel;
 
        /** @var null|string */
        public $contentFormat = null;
@@ -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.
@@ -1255,11 +1255,7 @@ class EditPage {
                }
                $revision = $this->mArticle->getRevisionFetched();
                if ( $revision === null ) {
-                       if ( !$this->contentModel ) {
-                               throw new RuntimeException( 'EditPage contentModel was false' );
-                       }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
-
                        return $handler->makeEmptyContent();
                }
                $content = $revision->getContent( Revision::FOR_THIS_USER, $user );
@@ -1299,11 +1295,7 @@ class EditPage {
                $content = $rev ? $rev->getContent( Revision::RAW ) : null;
 
                if ( $content === false || $content === null ) {
-                       if ( !$this->contentModel ) {
-                               throw new RuntimeException( 'EditPage contentModel was false' );
-                       }
                        $handler = ContentHandler::getForModelID( $this->contentModel );
-
                        return $handler->makeEmptyContent();
                } elseif ( !$this->undidRev ) {
                        // Content models should always be the same since we error
@@ -1911,7 +1903,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;
@@ -2326,12 +2318,9 @@ class EditPage {
        }
 
        public function setHeaders() {
-               global $wgOut, $wgUser, $wgAjaxEditStash, $wgCookieSetOnAutoblock;
+               global $wgOut, $wgUser, $wgAjaxEditStash;
 
                $wgOut->addModules( 'mediawiki.action.edit' );
-               if ( $wgCookieSetOnAutoblock === true ) {
-                       $wgOut->addModules( 'mediawiki.user.blockcookie' );
-               }
                $wgOut->addModuleStyles( 'mediawiki.action.edit.styles' );
 
                if ( $wgUser->getOption( 'showtoolbar' ) ) {
@@ -2483,11 +2472,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 +2607,7 @@ class EditPage {
                        return;
                }
 
-               $this->showHeader();
+               $this->showHeader();
 
                $wgOut->addHTML( $this->editFormPageTop );
 
@@ -2729,7 +2720,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( '' );
                }
 
@@ -3067,6 +3058,7 @@ class EditPage {
         */
        protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
                global $wgOut;
+
                # Add a class if 'missingsummary' is triggered to allow styling of the summary line
                $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
                if ( $isSubjectPreview ) {
@@ -3515,12 +3507,12 @@ HTML
 
                $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
                $edithelpurl = Skin::makeInternalOrExternalUrl( $message );
-               $attrs = [
-                       'target' => 'helpwindow',
-                       'href' => $edithelpurl,
-               ];
-               $edithelp = Html::linkButton( $this->context->msg( 'edithelp' )->text(),
-                       $attrs, [ 'mw-ui-quiet' ] ) .
+               $edithelp =
+                       Html::linkButton(
+                               $this->context->msg( 'edithelp' )->text(),
+                               [ 'target' => 'helpwindow', 'href' => $edithelpurl ],
+                               [ 'mw-ui-quiet' ]
+                       ) .
                        $this->context->msg( 'word-separator' )->escaped() .
                        $this->context->msg( 'newwindow' )->parse();
 
@@ -3563,7 +3555,7 @@ HTML
                }
        }
 
-       private function incrementConflictStats() {
+       protected function incrementConflictStats() {
                $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
                $stats->increment( 'edit.failures.conflict' );
                // Only include 'standard' namespaces to avoid creating unknown numbers of statsd metrics
@@ -3580,18 +3572,16 @@ HTML
         */
        public function getCancelLink() {
                $cancelParams = [];
-               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                if ( !$this->isConflict && $this->oldid > 0 ) {
                        $cancelParams['oldid'] = $this->oldid;
                } elseif ( $this->getContextTitle()->isRedirect() ) {
                        $cancelParams['redirect'] = 'no';
                }
-               $attrs = [ 'id' => 'mw-editform-cancel' ];
 
-               return $linkRenderer->makeKnownLink(
+               return MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
                        $this->getContextTitle(),
                        new HtmlArmor( $this->context->msg( 'cancel' )->parse() ),
-                       Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ),
+                       Html::buttonAttributes( [ 'id' => 'mw-editform-cancel' ], [ 'mw-ui-quiet' ] ),
                        $cancelParams
                );
        }
@@ -4047,9 +4037,8 @@ HTML
                                        ">{$minorLabel}</label>";
 
                                if ( $wgUseMediaWikiUIEverywhere ) {
-                                       $checkboxes['minor'] = Html::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) .
-                                               $minorEditHtml .
-                                       Html::closeElement( 'div' );
+                                       $checkboxes['minor'] =
+                                               Html::rawElement( 'div', [ 'class' => 'mw-ui-checkbox' ], $minorEditHtml );
                                } else {
                                        $checkboxes['minor'] = $minorEditHtml;
                                }
@@ -4070,9 +4059,8 @@ HTML
                                Xml::expandAttributes( [ 'title' => Linker::titleAttrib( 'watch', 'withaccess' ) ] ) .
                                ">{$watchLabel}</label>";
                        if ( $wgUseMediaWikiUIEverywhere ) {
-                               $checkboxes['watch'] = Html::openElement( 'div', [ 'class' => 'mw-ui-checkbox' ] ) .
-                                       $watchThisHtml .
-                                       Html::closeElement( 'div' );
+                               $checkboxes['watch'] =
+                                       Html::rawElement( 'div', [ 'class' => 'mw-ui-checkbox' ], $watchThisHtml );
                        } else {
                                $checkboxes['watch'] = $watchThisHtml;
                        }
@@ -4104,34 +4092,41 @@ HTML
                } else {
                        $buttonLabelKey = !$this->mTitle->exists() ? 'savearticle' : 'savechanges';
                }
-               $buttonLabel = $this->context->msg( $buttonLabelKey )->text();
                $attribs = [
                        'id' => 'wpSave',
                        'name' => 'wpSave',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'save' );
-               $buttons['save'] = Html::submitButton( $buttonLabel, $attribs, [ 'mw-ui-progressive' ] );
+               $buttons['save'] = Html::submitButton(
+                       $this->context->msg( $buttonLabelKey )->text(),
+                       $attribs,
+                       [ 'mw-ui-progressive' ]
+               );
 
-               ++$tabindex; // use the same for preview and live preview
                $attribs = [
                        'id' => 'wpPreview',
                        'name' => 'wpPreview',
-                       'tabindex' => $tabindex,
+                       'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'preview' );
-               $buttons['preview'] = Html::submitButton( $this->context->msg( 'showpreview' )->text(),
-                       $attribs );
+               $buttons['preview'] = Html::submitButton(
+                       $this->context->msg( 'showpreview' )->text(),
+                       $attribs
+               );
 
                $attribs = [
                        'id' => 'wpDiff',
                        'name' => 'wpDiff',
                        'tabindex' => ++$tabindex,
                ] + Linker::tooltipAndAccesskeyAttribs( 'diff' );
-               $buttons['diff'] = Html::submitButton( $this->context->msg( 'showdiff' )->text(),
-                       $attribs );
+               $buttons['diff'] = Html::submitButton(
+                       $this->context->msg( 'showdiff' )->text(),
+                       $attribs
+               );
 
                // Avoid PHP 7.1 warning of passing $this by reference
                $editPage = $this;
                Hooks::run( 'EditPageBeforeEditButtons', [ &$editPage, &$buttons, &$tabindex ] );
+
                return $buttons;
        }