Make LocalFile check early if the revision store is available
[lhc/web/wiklou.git] / includes / Storage / RevisionStore.php
index 42e7933..db06afe 100644 (file)
@@ -92,6 +92,11 @@ class RevisionStore
         */
        private $cache;
 
+       /**
+        * @var CommentStore
+        */
+       private $commentStore;
+
        /**
         * @var LoggerInterface
         */
@@ -103,12 +108,14 @@ class RevisionStore
         * @param LoadBalancer $loadBalancer
         * @param SqlBlobStore $blobStore
         * @param WANObjectCache $cache
+        * @param CommentStore $commentStore
         * @param bool|string $wikiId
         */
        public function __construct(
                LoadBalancer $loadBalancer,
                SqlBlobStore $blobStore,
                WANObjectCache $cache,
+               CommentStore $commentStore,
                $wikiId = false
        ) {
                Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
@@ -116,6 +123,7 @@ class RevisionStore
                $this->loadBalancer = $loadBalancer;
                $this->blobStore = $blobStore;
                $this->cache = $cache;
+               $this->commentStore = $commentStore;
                $this->wikiId = $wikiId;
                $this->logger = new NullLogger();
        }
@@ -124,6 +132,13 @@ class RevisionStore
                $this->logger = $logger;
        }
 
+       /**
+        * @return bool Whether the store is read-only
+        */
+       public function isReadOnly() {
+               return $this->blobStore->isReadOnly();
+       }
+
        /**
         * @return bool
         */
@@ -244,7 +259,7 @@ class RevisionStore
                        if ( $title ) {
                                $this->logger->info(
                                        __METHOD__ . ' fell back to READ_LATEST and got a Title.',
-                                       [ 'trace' => wfDebugBacktrace() ]
+                                       [ 'trace' => wfBacktrace() ]
                                );
                                return $title;
                        }
@@ -290,8 +305,8 @@ class RevisionStore
        }
 
        /**
-        * Insert a new revision into the database, returning the new revision ID
-        * number on success and dies horribly on failure.
+        * Insert a new revision into the database, returning the new revision record
+        * on success and dies horribly on failure.
         *
         * MCR migration note: this replaces Revision::insertOn
         *
@@ -393,7 +408,7 @@ class RevisionStore
                }
 
                list( $commentFields, $commentCallback ) =
-                       CommentStore::newKey( 'rev_comment' )->insertWithTempTable( $dbw, $comment );
+                       $this->commentStore->insertWithTempTable( $dbw, 'rev_comment', $comment );
                $row += $commentFields;
 
                if ( $this->contentHandlerUseDB ) {
@@ -732,8 +747,6 @@ class RevisionStore
 
                        if ( isset( $row->rev_text_id ) && $row->rev_text_id > 0 ) {
                                $mainSlotRow->cont_address = 'tt:' . $row->rev_text_id;
-                       } elseif ( isset( $row->ar_id ) ) {
-                               $mainSlotRow->cont_address = 'ar:' . $row->ar_id;
                        }
 
                        if ( isset( $row->old_text ) ) {
@@ -1069,9 +1082,9 @@ class RevisionStore
 
                $user = $this->getUserIdentityFromRowObject( $row, 'ar_' );
 
-               $comment = CommentStore::newKey( 'ar_comment' )
+               $comment = $this->commentStore
                        // Legacy because $row may have come from self::selectFields()
-                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), $row, true );
+                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'ar_comment', $row, true );
 
                $mainSlot = $this->emulateMainSlot_1_29( $row, $queryFlags, $title );
                $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
@@ -1139,9 +1152,9 @@ class RevisionStore
 
                $user = $this->getUserIdentityFromRowObject( $row );
 
-               $comment = CommentStore::newKey( 'rev_comment' )
+               $comment = $this->commentStore
                        // Legacy because $row may have come from self::selectFields()
-                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), $row, true );
+                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'rev_comment', $row, true );
 
                $mainSlot = $this->emulateMainSlot_1_29( $row, $queryFlags, $title );
                $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
@@ -1614,7 +1627,7 @@ class RevisionStore
                        'rev_sha1',
                ] );
 
-               $commentQuery = CommentStore::newKey( 'rev_comment' )->getJoin();
+               $commentQuery = $this->commentStore->getJoin( 'rev_comment' );
                $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] );
                $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] );
                $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] );
@@ -1671,7 +1684,7 @@ class RevisionStore
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public function getArchiveQueryInfo() {
-               $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin();
+               $commentQuery = $this->commentStore->getJoin( 'ar_comment' );
                $ret = [
                        'tables' => [ 'archive' ] + $commentQuery['tables'],
                        'fields' => [