From 7458232874986edf20fbd85f45f42295b1689524 Mon Sep 17 00:00:00 2001 From: addshore Date: Thu, 14 Dec 2017 23:14:14 +0000 Subject: [PATCH] [MCR] Use RevisionStore::getArchiveQueryInfo in PageArchive This is needed to allow RevisionStore to be switched to an alternative database schema for MCR. Bug: T174026 Bug: T183509 Change-Id: I51318cb102f6fb8962e608196bee96bde023bcff --- includes/page/PageArchive.php | 80 ++++++---------------- tests/phpunit/includes/PageArchiveTest.php | 12 ++++ 2 files changed, 34 insertions(+), 58 deletions(-) diff --git a/includes/page/PageArchive.php b/includes/page/PageArchive.php index c03d6b21d6..05247cafeb 100644 --- a/includes/page/PageArchive.php +++ b/includes/page/PageArchive.php @@ -176,44 +176,32 @@ class PageArchive { * @return ResultWrapper */ public function listRevisions() { - $dbr = wfGetDB( DB_REPLICA ); - $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin(); - - $tables = [ 'archive' ] + $commentQuery['tables']; - - $fields = [ - 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', - 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1', - 'ar_page_id' - ] + $commentQuery['fields']; - - if ( $this->config->get( 'ContentHandlerUseDB' ) ) { - $fields[] = 'ar_content_format'; - $fields[] = 'ar_content_model'; - } - - $conds = [ 'ar_namespace' => $this->title->getNamespace(), - 'ar_title' => $this->title->getDBkey() ]; + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $queryInfo = $revisionStore->getArchiveQueryInfo(); + $conds = [ + 'ar_namespace' => $this->title->getNamespace(), + 'ar_title' => $this->title->getDBkey(), + ]; $options = [ 'ORDER BY' => 'ar_timestamp DESC' ]; - $join_conds = [] + $commentQuery['joins']; - ChangeTags::modifyDisplayQuery( - $tables, - $fields, + $queryInfo['tables'], + $queryInfo['fields'], $conds, - $join_conds, + $queryInfo['joins'], $options, '' ); - return $dbr->select( $tables, - $fields, + $dbr = wfGetDB( DB_REPLICA ); + return $dbr->select( + $queryInfo['tables'], + $queryInfo['fields'], $conds, __METHOD__, $options, - $join_conds + $queryInfo['joins'] ); } @@ -542,47 +530,23 @@ class PageArchive { $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps ); } - $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin(); - - $tables = [ 'archive', 'revision' ] + $commentQuery['tables']; - - $fields = [ - 'ar_id', - 'ar_rev_id', - 'rev_id', - 'ar_text', - 'ar_user', - 'ar_user_text', - 'ar_timestamp', - 'ar_minor_edit', - 'ar_flags', - 'ar_text_id', - 'ar_deleted', - 'ar_page_id', - 'ar_len', - 'ar_sha1' - ] + $commentQuery['fields']; - - if ( $this->config->get( 'ContentHandlerUseDB' ) ) { - $fields[] = 'ar_content_format'; - $fields[] = 'ar_content_model'; - } - - $join_conds = [ - 'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ], - ] + $commentQuery['joins']; + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $queryInfo = $revisionStore->getArchiveQueryInfo(); + $queryInfo['tables'][] = 'revision'; + $queryInfo['fields'][] = 'rev_id'; + $queryInfo['joins']['revision'] = [ 'LEFT JOIN', 'ar_rev_id=rev_id' ]; /** * Select each archived revision... */ $result = $dbw->select( - $tables, - $fields, + $queryInfo['tables'], + $queryInfo['fields'], $oldWhere, __METHOD__, /* options */ [ 'ORDER BY' => 'ar_timestamp' ], - $join_conds + $queryInfo['joins'] ); $rev_count = $result->numRows(); diff --git a/tests/phpunit/includes/PageArchiveTest.php b/tests/phpunit/includes/PageArchiveTest.php index f33b78eaf2..ffafe3af39 100644 --- a/tests/phpunit/includes/PageArchiveTest.php +++ b/tests/phpunit/includes/PageArchiveTest.php @@ -142,6 +142,12 @@ class PageArchiveTest extends MediaWikiTestCase { 'ar_content_format' => null, 'ar_content_model' => null, 'ts_tags' => null, + 'ar_id' => '2', + 'ar_namespace' => '0', + 'ar_title' => 'PageArchiveTest_thePage', + 'ar_text' => '', + 'ar_text_id' => '3', + 'ar_parent_id' => '2', ], $row1 ); @@ -161,6 +167,12 @@ class PageArchiveTest extends MediaWikiTestCase { 'ar_content_format' => null, 'ar_content_model' => null, 'ts_tags' => null, + 'ar_id' => '1', + 'ar_namespace' => '0', + 'ar_title' => 'PageArchiveTest_thePage', + 'ar_text' => '', + 'ar_text_id' => '2', + 'ar_parent_id' => '0', ], $row2 ); -- 2.20.1