Add safeguard against loading content across wikis.
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 6 Aug 2018 12:31:04 +0000 (14:31 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 6 Aug 2018 13:46:24 +0000 (15:46 +0200)
The new MCR schema enables cross-wiki loading of page content,
but this mechanism doesn't work as long as the new code is reading from
the old schema. This is what caused T201194.

Bug: T201194
Change-Id: I58af7a9e02780c55cd8fab20f19be36a0fa804da

includes/Storage/RevisionStore.php
includes/Storage/RevisionStoreFactory.php

index 65c0361..5769527 100644 (file)
@@ -207,6 +207,20 @@ class RevisionStore
                return ( $this->mcrMigrationStage & $flags ) === $flags;
        }
 
+       /**
+        * Throws a RevisionAccessException if this RevisionStore is configured for cross-wiki loading
+        * and still reading from the old DB schema.
+        *
+        * @throws RevisionAccessException
+        */
+       private function assertCrossWikiContentLoadingIsSafe() {
+               if ( $this->wikiId !== false && $this->hasMcrSchemaFlags( SCHEMA_COMPAT_READ_OLD ) ) {
+                       throw new RevisionAccessException(
+                               "Cross-wiki content loading is not supported by the pre-MCR schema"
+                       );
+               }
+       }
+
        public function setLogger( LoggerInterface $logger ) {
                $this->logger = $logger;
        }
@@ -780,6 +794,8 @@ class RevisionStore
 
                        // MCR migration note: rev_content_model and rev_content_format will go away
                        if ( $this->contentHandlerUseDB ) {
+                               $this->assertCrossWikiContentLoadingIsSafe();
+
                                $defaultModel = ContentHandler::getDefaultModelFor( $title );
                                $defaultFormat = ContentHandler::getForModelID( $defaultModel )->getDefaultFormat();
 
@@ -888,6 +904,8 @@ class RevisionStore
                        // if $wgContentHandlerUseDB is not set,
                        // all revisions must use the default content model and format.
 
+                       $this->assertCrossWikiContentLoadingIsSafe();
+
                        $defaultModel = ContentHandler::getDefaultModelFor( $title );
                        $defaultHandler = ContentHandler::getForModelID( $defaultModel );
                        $defaultFormat = $defaultHandler->getDefaultFormat();
@@ -1207,6 +1225,8 @@ class RevisionStore
 
                if ( $mainSlotRow->model_name === null ) {
                        $mainSlotRow->model_name = function ( SlotRecord $slot ) use ( $title ) {
+                               $this->assertCrossWikiContentLoadingIsSafe();
+
                                // TODO: MCR: consider slot role in getDefaultModelFor()! Use LinkTarget!
                                // TODO: MCR: deprecate $title->getModel().
                                return ContentHandler::getDefaultModelFor( $title );
index cfc5444..9419b40 100644 (file)
@@ -75,7 +75,8 @@ class RevisionStoreFactory {
         * @param ActorMigration $actorMigration
         * @param int $migrationStage
         * @param LoggerSpi $loggerProvider
-        * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}
+        * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
+        *        for all wikis in the cluster. Will go away after MCR migration.
         */
        public function __construct(
                ILBFactory $dbLoadBalancerFactory,