Merge "Disable warning about direct text table access for now"
[lhc/web/wiklou.git] / includes / Storage / RevisionStore.php
index 81b675e..14b1820 100644 (file)
@@ -56,7 +56,7 @@ use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\DBConnRef;
 use Wikimedia\Rdbms\IDatabase;
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\ILoadBalancer;
 
 /**
  * Service for looking up page revisions.
@@ -88,7 +88,7 @@ class RevisionStore
        private $contentHandlerUseDB = true;
 
        /**
-        * @var LoadBalancer
+        * @var ILoadBalancer
         */
        private $loadBalancer;
 
@@ -128,9 +128,14 @@ class RevisionStore
        /**
         * @todo $blobStore should be allowed to be any BlobStore!
         *
-        * @param LoadBalancer $loadBalancer
+        * @param ILoadBalancer $loadBalancer
         * @param SqlBlobStore $blobStore
-        * @param WANObjectCache $cache
+        * @param WANObjectCache $cache A cache for caching revision rows. This can be the local
+        *        wiki's default instance even if $wikiId refers to a different wiki, since
+        *        makeGlobalKey() is used to constructed a key that allows cached revision rows from
+        *        the same database to be re-used between wikis. For example, enwiki and frwiki will
+        *        use the same cache keys for revision rows from the wikidatawiki database, regardless
+        *        of the cache's default key space.
         * @param CommentStore $commentStore
         * @param NameTableStore $contentModelStore
         * @param NameTableStore $slotRoleStore
@@ -141,7 +146,7 @@ class RevisionStore
         * @throws MWException if $mcrMigrationStage or $wikiId is invalid.
         */
        public function __construct(
-               LoadBalancer $loadBalancer,
+               ILoadBalancer $loadBalancer,
                SqlBlobStore $blobStore,
                WANObjectCache $cache,
                CommentStore $commentStore,
@@ -202,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;
        }
@@ -239,7 +258,7 @@ class RevisionStore
        }
 
        /**
-        * @return LoadBalancer
+        * @return ILoadBalancer
         */
        private function getDBLoadBalancer() {
                return $this->loadBalancer;
@@ -775,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();
 
@@ -883,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();
@@ -1202,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 );