Drop archive.ar_text and ar_flags
[lhc/web/wiklou.git] / includes / Storage / RevisionStore.php
index e00deef..13aedba 100644 (file)
@@ -455,7 +455,7 @@ class RevisionStore
                        $dbw->insert( 'ip_changes', $ipcRow, __METHOD__ );
                }
 
-               $newSlot = SlotRecord::newSaved( $row['rev_id'], $blobAddress, $slot );
+               $newSlot = SlotRecord::newSaved( $row['rev_id'], $textId, $blobAddress, $slot );
                $slots = new RevisionSlots( [ 'main' => $newSlot ] );
 
                $rev = new RevisionStoreRecord(
@@ -594,16 +594,17 @@ class RevisionStore
 
                if ( $current ) {
                        $fields = [
-                               'page'       => $title->getArticleID(),
-                               'user_text'  => $user->getName(),
-                               'user'       => $user->getId(),
-                               'actor'      => $user->getActorId(),
-                               'comment'    => $comment,
-                               'minor_edit' => $minor,
-                               'text_id'    => $current->rev_text_id,
-                               'parent_id'  => $current->page_latest,
-                               'len'        => $current->rev_len,
-                               'sha1'       => $current->rev_sha1
+                               'page'        => $title->getArticleID(),
+                               'user_text'   => $user->getName(),
+                               'user'        => $user->getId(),
+                               'actor'       => $user->getActorId(),
+                               'comment'     => $comment,
+                               'minor_edit'  => $minor,
+                               'text_id'     => $current->rev_text_id,
+                               'parent_id'   => $current->page_latest,
+                               'slot_origin' => $current->page_latest,
+                               'len'         => $current->rev_len,
+                               'sha1'        => $current->rev_sha1
                        ];
 
                        if ( $this->contentHandlerUseDB ) {
@@ -635,7 +636,7 @@ class RevisionStore
         */
        public function getRcIdIfUnpatrolled( RevisionRecord $rev ) {
                $rc = $this->getRecentChange( $rev );
-               if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) {
+               if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == RecentChange::PRC_UNPATROLLED ) {
                        return $rc->getAttribute( 'rc_id' );
                } else {
                        return 0;
@@ -723,11 +724,6 @@ class RevisionStore
                        'ar_content_model'  => 'rev_content_model',
                ];
 
-               if ( empty( $archiveRow->ar_text_id ) ) {
-                       $fieldMap['ar_text'] = 'old_text';
-                       $fieldMap['ar_flags'] = 'old_flags';
-               }
-
                $revRow = new stdClass();
                foreach ( $fieldMap as $arKey => $revKey ) {
                        if ( property_exists( $archiveRow, $arKey ) ) {
@@ -751,6 +747,10 @@ class RevisionStore
        private function emulateMainSlot_1_29( $row, $queryFlags, Title $title ) {
                $mainSlotRow = new stdClass();
                $mainSlotRow->role_name = 'main';
+               $mainSlotRow->model_name = null;
+               $mainSlotRow->slot_revision_id = null;
+               $mainSlotRow->content_address = null;
+               $mainSlotRow->slot_content_id = null;
 
                $content = null;
                $blobData = null;
@@ -763,9 +763,15 @@ class RevisionStore
                        }
 
                        if ( isset( $row->rev_text_id ) && $row->rev_text_id > 0 ) {
-                               $mainSlotRow->cont_address = 'tt:' . $row->rev_text_id;
+                               $mainSlotRow->slot_content_id = $row->rev_text_id;
+                               $mainSlotRow->content_address = 'tt:' . $row->rev_text_id;
                        }
 
+                       // This is used by null-revisions
+                       $mainSlotRow->slot_origin = isset( $row->slot_origin )
+                               ? intval( $row->slot_origin )
+                               : null;
+
                        if ( isset( $row->old_text ) ) {
                                // this happens when the text-table gets joined directly, in the pre-1.30 schema
                                $blobData = isset( $row->old_text ) ? strval( $row->old_text ) : null;
@@ -776,10 +782,10 @@ class RevisionStore
                                $blobFlags = ( $row->old_flags === null ) ? '' : $row->old_flags;
                        }
 
-                       $mainSlotRow->slot_revision = intval( $row->rev_id );
+                       $mainSlotRow->slot_revision_id = intval( $row->rev_id );
 
-                       $mainSlotRow->cont_size = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
-                       $mainSlotRow->cont_sha1 = isset( $row->rev_sha1 ) ? strval( $row->rev_sha1 ) : null;
+                       $mainSlotRow->content_size = isset( $row->rev_len ) ? intval( $row->rev_len ) : null;
+                       $mainSlotRow->content_sha1 = isset( $row->rev_sha1 ) ? strval( $row->rev_sha1 ) : null;
                        $mainSlotRow->model_name = isset( $row->rev_content_model )
                                ? strval( $row->rev_content_model )
                                : null;
@@ -788,13 +794,19 @@ class RevisionStore
                                ? strval( $row->rev_content_format )
                                : null;
                } elseif ( is_array( $row ) ) {
-                       $mainSlotRow->slot_revision = isset( $row['id'] ) ? intval( $row['id'] ) : null;
+                       $mainSlotRow->slot_revision_id = isset( $row['id'] ) ? intval( $row['id'] ) : null;
 
-                       $mainSlotRow->cont_address = isset( $row['text_id'] )
+                       $mainSlotRow->slot_content_id = isset( $row['text_id'] )
+                               ? intval( $row['text_id'] )
+                               : null;
+                       $mainSlotRow->slot_origin = isset( $row['slot_origin'] )
+                               ? intval( $row['slot_origin'] )
+                               : null;
+                       $mainSlotRow->content_address = isset( $row['text_id'] )
                                ? 'tt:' . intval( $row['text_id'] )
                                : null;
-                       $mainSlotRow->cont_size = isset( $row['len'] ) ? intval( $row['len'] ) : null;
-                       $mainSlotRow->cont_sha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null;
+                       $mainSlotRow->content_size = isset( $row['len'] ) ? intval( $row['len'] ) : null;
+                       $mainSlotRow->content_sha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null;
 
                        $mainSlotRow->model_name = isset( $row['content_model'] )
                                ? strval( $row['content_model'] ) : null;  // XXX: must be a string!
@@ -827,9 +839,11 @@ class RevisionStore
                        throw new MWException( 'Revision constructor passed invalid row format.' );
                }
 
-               // With the old schema, the content changes with every revision.
-               // ...except for null-revisions. Would be nice if we could detect them.
-               $mainSlotRow->slot_inherited = 0;
+               // With the old schema, the content changes with every revision,
+               // except for null-revisions.
+               if ( !isset( $mainSlotRow->slot_origin ) ) {
+                       $mainSlotRow->slot_origin = $mainSlotRow->slot_revision_id;
+               }
 
                if ( $mainSlotRow->model_name === null ) {
                        $mainSlotRow->model_name = function ( SlotRecord $slot ) use ( $title ) {
@@ -853,6 +867,7 @@ class RevisionStore
                        };
                }
 
+               $mainSlotRow->slot_id = $mainSlotRow->slot_revision_id;
                return new SlotRecord( $mainSlotRow, $content );
        }
 
@@ -1035,9 +1050,10 @@ class RevisionStore
         * @return RevisionRecord|null
         */
        public function getRevisionByTimestamp( $title, $timestamp ) {
+               $db = $this->getDBConnection( DB_REPLICA );
                return $this->newRevisionFromConds(
                        [
-                               'rev_timestamp' => $timestamp,
+                               'rev_timestamp' => $db->timestamp( $timestamp ),
                                'page_namespace' => $title->getNamespace(),
                                'page_title' => $title->getDBkey()
                        ],
@@ -1683,7 +1699,6 @@ class RevisionStore
                                        'ar_namespace',
                                        'ar_title',
                                        'ar_rev_id',
-                                       'ar_text',
                                        'ar_text_id',
                                        'ar_timestamp',
                                        'ar_minor_edit',