Hard-deprecate hooks APIGetDescription and APIGetParamDescription
[lhc/web/wiklou.git] / includes / EditPage.php
index b3fe660..29abfb1 100644 (file)
@@ -943,7 +943,7 @@ class EditPage {
                        # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is
                        # currently doing double duty as both edit summary and section title. Right now this
                        # is just to allow API edits to work around this limitation, but this should be
-                       # incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312).
+                       # incorporated into the actual edit form when EditPage is rewritten (T20654, T28312).
                        $this->sectiontitle = $request->getText( 'wpSectionTitle' );
                        $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle );
 
@@ -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;
                }
@@ -2688,7 +2716,7 @@ ERROR;
         *
         * @param string|null|bool $text Text to unserialize
         * @return Content|bool|null The content object created from $text. If $text was false
-        *   or null, false resp. null will be  returned instead.
+        *   or null, then false or null will be returned instead.
         *
         * @throws MWException If unserializing the text results in a Content
         *   object that is not an instance of TextContent and
@@ -3999,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;
        }
 
@@ -4014,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 [