Merge "Simplify HTMLTitleTextField::validate"
[lhc/web/wiklou.git] / includes / EditPage.php
index e087a6e..7384ca2 100644 (file)
@@ -1058,7 +1058,7 @@ class EditPage {
                                $this->sectiontitle = $request->getVal( 'preloadtitle' );
                                // Once wpSummary isn't being use for setting section titles, we should delete this.
                                $this->summary = $request->getVal( 'preloadtitle' );
-                       } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
+                       } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) !== '' ) {
                                $this->summary = $request->getText( 'summary' );
                                if ( $this->summary !== '' ) {
                                        $this->hasPresetSummary = true;
@@ -1222,7 +1222,9 @@ class EditPage {
                                                !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
                                                !$oldrev->isDeleted( Revision::DELETED_TEXT )
                                        ) {
-                                               if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev ) ) {
+                                               if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
+                                                       || !$this->isSupportedContentModel( $oldrev->getContentModel() )
+                                               ) {
                                                        // Hack for undo while EditPage can't handle multi-slot editing
                                                        $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
                                                                'action' => 'mcrundo',
@@ -1304,6 +1306,32 @@ class EditPage {
                                                $this->context->msg( 'undo-' . $undoMsg )->plain() . '</div>', true, /* interface */true );
                                }
 
+                               if ( $content === false ) {
+                                       // Hack for restoring old revisions while EditPage
+                                       // can't handle multi-slot editing.
+
+                                       $curRevision = $this->page->getRevision();
+                                       $oldRevision = $this->mArticle->getRevisionFetched();
+
+                                       if ( $curRevision
+                                               && $oldRevision
+                                               && $curRevision->getId() !== $oldRevision->getId()
+                                               && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision )
+                                                       || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) )
+                                       ) {
+                                               $this->context->getOutput()->redirect(
+                                                       $this->mTitle->getFullURL(
+                                                               [
+                                                                       'action' => 'mcrrestore',
+                                                                       'restore' => $oldRevision->getId(),
+                                                               ]
+                                                       )
+                                               );
+
+                                               return false;
+                                       }
+                               }
+
                                if ( $content === false ) {
                                        $content = $this->getOriginalContent( $user );
                                }
@@ -1689,7 +1717,7 @@ class EditPage {
                                // is if an extension hook aborted from inside ArticleSave.
                                // Render the status object into $this->hookError
                                // FIXME this sucks, we should just use the Status object throughout
-                               $this->hookError = '<div class="error">' ."\n" . $status->getWikiText() .
+                               $this->hookError = '<div class="error">' . "\n" . $status->getWikiText() .
                                        '</div>';
                                return true;
                }
@@ -1782,7 +1810,7 @@ ERROR;
                        if ( $this->summary === '' ) {
                                $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
                                return $this->context->msg( 'newsectionsummary' )
-                                       ->rawParams( $cleanSectionTitle )->inContentLanguage()->text();
+                                       ->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
                        }
                } elseif ( $this->summary !== '' ) {
                        $sectionanchor = $this->guessSectionName( $this->summary );
@@ -1790,7 +1818,7 @@ ERROR;
                        # in the revision summary.
                        $cleanSummary = $wgParser->stripSectionName( $this->summary );
                        return $this->context->msg( 'newsectionsummary' )
-                               ->rawParams( $cleanSummary )->inContentLanguage()->text();
+                               ->plaintextParams( $cleanSummary )->inContentLanguage()->text();
                }
                return $this->summary;
        }
@@ -2490,6 +2518,8 @@ ERROR;
                $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
                if ( $displayTitle === false ) {
                        $displayTitle = $contextTitle->getPrefixedText();
+               } else {
+                       $out->setDisplayTitle( $displayTitle );
                }
                $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
 
@@ -2869,7 +2899,7 @@ ERROR;
                        $this->autoSumm = md5( '' );
                }
 
-               $autosumm = $this->autoSumm ?: md5( $this->summary );
+               $autosumm = $this->autoSumm !== '' ? $this->autoSumm : md5( $this->summary );
                $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) );
 
                $out->addHTML( Html::hidden( 'oldid', $this->oldid ) );
@@ -3786,7 +3816,7 @@ ERROR;
 
        /**
         * Get the last log record of this page being deleted, if ever.  This is
-        * used to detect whether a delete occured during editing.
+        * used to detect whether a delete occurred during editing.
         * @return bool|stdClass
         */
        protected function getLastDelete() {
@@ -3997,6 +4027,12 @@ ERROR;
                $parserOptions->setIsPreview( true );
                $parserOptions->setIsSectionPreview( !is_null( $this->section ) && $this->section !== '' );
                $parserOptions->enableLimitReport();
+
+               // XXX: we could call $parserOptions->setCurrentRevisionCallback here to force the
+               // current revision to be null during PST, until setupFakeRevision is called on
+               // the ParserOptions. Currently, we rely on Parser::getRevisionObject() to ignore
+               // existing revisions in preview mode.
+
                return $parserOptions;
        }
 
@@ -4012,9 +4048,14 @@ ERROR;
        protected function doPreviewParse( Content $content ) {
                $user = $this->context->getUser();
                $parserOptions = $this->getPreviewParserOptions();
+
+               // NOTE: preSaveTransform doesn't have a fake revision to operate on.
+               // Parser::getRevisionObject() will return null in preview mode,
+               // causing the context user to be used for {{subst:REVISIONUSER}}.
+               // XXX: Alternatively, we could also call setupFakeRevision() a second time:
+               // once before PST with $content, and then after PST with $pstContent.
                $pstContent = $content->preSaveTransform( $this->mTitle, $user, $parserOptions );
-               $scopedCallback = $parserOptions->setupFakeRevision(
-                       $this->mTitle, $pstContent, $user );
+               $scopedCallback = $parserOptions->setupFakeRevision( $this->mTitle, $pstContent, $user );
                $parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions );
                ScopedCallback::consume( $scopedCallback );
                return [