From eac8538cd6e30aae34d1b653a7de43a02f462aa5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 27 Oct 2011 19:55:00 +0000 Subject: [PATCH] * Added pageJoinCond() and userJoinCond() to Revision and exposed them publicly * Removed commented-out code --- includes/Revision.php | 21 +++++++++++++++++++-- includes/RevisionList.php | 5 +++-- includes/WikiPage.php | 4 ---- includes/actions/HistoryAction.php | 2 +- includes/revisiondelete/RevisionDelete.php | 5 +++-- includes/specials/SpecialContributions.php | 4 ++-- includes/specials/SpecialMergeHistory.php | 4 ++-- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index f75442ca05..7136c1b1c5 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -294,11 +294,28 @@ class Revision { $conditions, __METHOD__, array( 'LIMIT' => 1 ), - array( 'page' => array( 'INNER JOIN', 'page_id = rev_page' ), - 'user' => array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ) ) + array( 'page' => self::pageJoinCond(), 'user' => self::userJoinCond() ) ); } + /** + * Return the value of a select() JOIN conds array for the user table. + * This will get user table rows for logged-in users. + * @return Array + */ + public static function userJoinCond() { + return array( 'LEFT JOIN', array( 'rev_user != 0', 'user_id = rev_user' ) ); + } + + /** + * Return the value of a select() page conds array for the paeg table. + * This will assure that the revision(s) are not orphaned from live pages. + * @return Array + */ + public static function pageJoinCond() { + return array( 'INNER JOIN', array( 'page_id = rev_page' ) ); + } + /** * Return the list of revision fields that should be selected to create * a new revision. diff --git a/includes/RevisionList.php b/includes/RevisionList.php index 2781764453..5a9bbad01a 100644 --- a/includes/RevisionList.php +++ b/includes/RevisionList.php @@ -260,8 +260,9 @@ class RevisionList extends RevisionListBase { $conds, __METHOD__, array( 'ORDER BY' => 'rev_id DESC' ), - array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ), - 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) ) + array( + 'page' => Revision::pageJoinCond(), + 'user' => Revision::userJoinCond() ) ); } diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 4bc787370a..8d6d3ebf57 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1529,10 +1529,6 @@ class WikiPage extends Page { */ public function estimateRevisionCount() { $dbr = wfGetDB( DB_SLAVE ); - - // For an exact count... - // return $dbr->selectField( 'revision', 'COUNT(*)', - // array( 'rev_page' => $this->getId() ), __METHOD__ ); return $dbr->estimateRowCount( 'revision', '*', array( 'rev_page' => $this->getId() ), __METHOD__ ); } diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 3775bf1a01..f6d48ea7be 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -351,7 +351,7 @@ class HistoryPager extends ReverseChronologicalPager { $this->conds ), 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ), 'join_conds' => array( - 'user' => array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ), + 'user' => Revision::userJoinCond(), 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ), ); ChangeTags::modifyDisplayQuery( diff --git a/includes/revisiondelete/RevisionDelete.php b/includes/revisiondelete/RevisionDelete.php index b49555293f..0a6566b047 100644 --- a/includes/revisiondelete/RevisionDelete.php +++ b/includes/revisiondelete/RevisionDelete.php @@ -34,8 +34,9 @@ class RevDel_RevisionList extends RevDel_List { ), __METHOD__, array( 'ORDER BY' => 'rev_id DESC' ), - array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ), - 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) ) + array( + 'page' => Revision::pageJoinCond(), + 'user' => Revision::userJoinCond() ) ); if ( $live->numRows() >= count( $ids ) ) { diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index ee9ae08275..df4db79c3e 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -476,9 +476,9 @@ class ContribsPager extends ReverseChronologicalPager { } # Don't include orphaned revisions - $join_cond['page'] = array( 'INNER JOIN', 'page_id = rev_page' ); + $join_cond['page'] = Revision::pageJoinCond(); # Get the current user name for accounts - $join_cond['user'] = array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ); + $join_cond['user'] = Revision::userJoinCond(); $queryInfo = array( 'tables' => $tables, diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 27c5495cf5..658680aeb5 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -483,8 +483,8 @@ class MergeHistoryPager extends ReverseChronologicalPager { 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ), 'conds' => $conds, 'join_conds' => array( - 'page' => array( 'INNER JOIN', 'rev_page = page_id' ), - 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) ) + 'page' => Revision::pageJoinCond(), + 'user' => Revision::userJoinCond() ) ); } -- 2.20.1