JOIN to get user_name in Contributions, HistoryPage, RevisionList, RevisionDelete...
authorAaron Schulz <aaron@users.mediawiki.org>
Thu, 20 Oct 2011 00:04:14 +0000 (00:04 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Thu, 20 Oct 2011 00:04:14 +0000 (00:04 +0000)
includes/HistoryPage.php
includes/RevisionList.php
includes/revisiondelete/RevisionDelete.php
includes/specials/SpecialContributions.php
includes/specials/SpecialMergeHistory.php

index 11315ac..8aa7b2b 100644 (file)
@@ -342,13 +342,15 @@ class HistoryPager extends ReverseChronologicalPager {
 
        function getQueryInfo() {
                $queryInfo = array(
-                       'tables'  => array( 'revision' ),
-                       'fields'  => Revision::selectFields(),
+                       'tables'  => array( 'revision', 'user' ),
+                       'fields'  => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        'conds'   => array_merge(
                                array( 'rev_page' => $this->title->getArticleID() ),
                                $this->conds ),
                        'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
-                       'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
+                       'join_conds' => array(
+                               'user'        => array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ),
+                               'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
                );
                ChangeTags::modifyDisplayQuery(
                        $queryInfo['tables'],
index 8b17578..6022b98 100644 (file)
@@ -250,19 +250,18 @@ class RevisionList extends RevisionListBase {
         * @return mixed
         */
        public function doQuery( $db ) {
-               $conds = array(
-                       'rev_page' => $this->title->getArticleID(),
-                       'rev_page = page_id'
-               );
+               $conds = array( 'rev_page' => $this->title->getArticleID() );
                if ( $this->ids !== null ) {
                        $conds['rev_id'] = array_map( 'intval', $this->ids );
                }
                return $db->select(
-                       array( 'revision', 'page' ),
-                       '*',
+                       array( 'revision', 'page', 'user' ),
+                       array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        $conds,
                        __METHOD__,
-                       array( 'ORDER BY' => 'rev_id DESC' )
+                       array( 'ORDER BY' => 'rev_id DESC' ),
+                       array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
+                               'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
                );
        }
 
@@ -296,7 +295,7 @@ class RevisionItem extends RevisionItemBase {
        }
 
        public function getAuthorNameField() {
-               return 'rev_user_text';
+               return 'rev_user_name'; // see Revision::selectUserFields()
        }
 
        public function canView() {
index ea022fb..1f32079 100644 (file)
@@ -25,14 +25,17 @@ class RevDel_RevisionList extends RevDel_List {
         */
        public function doQuery( $db ) {
                $ids = array_map( 'intval', $this->ids );
-               $live = $db->select( array('revision','page'), '*',
+               $live = $db->select(
+                       array( 'revision', 'page', 'user' ),
+                       array_merge( Revision::selectFields(), Revision::selectUserFields() ),
                        array(
                                'rev_page' => $this->title->getArticleID(),
                                'rev_id'   => $ids,
-                               'rev_page = page_id'
                        ),
                        __METHOD__,
-                       array( 'ORDER BY' => 'rev_id DESC' )
+                       array( 'ORDER BY' => 'rev_id DESC' ),
+                       array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
+                               'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
                );
 
                if ( $live->numRows() >= count( $ids ) ) {
@@ -128,7 +131,7 @@ class RevDel_RevisionItem extends RevDel_Item {
        }
 
        public function getAuthorNameField() {
-               return 'rev_user_text';
+               return 'rev_user_name'; // see Revision::selectUserFields()
        }
 
        public function canView() {
index bc66bc9..922305a 100644 (file)
@@ -470,16 +470,20 @@ class ContribsPager extends ReverseChronologicalPager {
                        $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::SUPPRESSED_USER) .
                                ' != ' . Revision::SUPPRESSED_USER;
                }
-               $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
+
+               # Don't include orphaned revisions
+               $join_cond['page'] = array( 'INNER JOIN', 'page_id = rev_page' );
+               # Get the current user name for accounts
+               $join_cond['user'] = array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' );
 
                $queryInfo = array(
                        'tables' => $tables,
-                       'fields' => array(
+                       'fields' => array_merge( Revision::selectUserFields(), array(
                                'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect',
-                               'page_len','rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
+                               'page_len', 'rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
                                'rev_minor_edit', 'rev_user', 'rev_user_text', 'rev_parent_id', 'rev_deleted',
-                               'rev_len', 'rev_parent_id'
-                       ),
+                               'rev_len'
+                       ) ),
                        'conds' => $conds,
                        'options' => array( 'USE INDEX' => array('revision' => $index) ),
                        'join_conds' => $join_cond
@@ -501,8 +505,9 @@ class ContribsPager extends ReverseChronologicalPager {
        function getUserCond() {
                $condition = array();
                $join_conds = array();
+               $tables = array( 'revision', 'page', 'user' );
                if( $this->target == 'newbies' ) {
-                       $tables = array( 'user_groups', 'page', 'revision' );
+                       $tables[] = 'user_groups';
                        $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
                        $condition[] = 'rev_user >' . (int)($max - $max / 100);
                        $condition[] = 'ug_group IS NULL';
@@ -510,9 +515,13 @@ class ContribsPager extends ReverseChronologicalPager {
                        # @todo FIXME: Other groups may have 'bot' rights
                        $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
                } else {
-                       $tables = array( 'page', 'revision' );
-                       $condition['rev_user_text'] = $this->target;
-                       $index = 'usertext_timestamp';
+                       if ( IP::isIPAddress( $this->target ) ) {
+                               $condition['rev_user_text'] = $this->target;
+                               $index = 'usertext_timestamp';
+                       } else {
+                               $condition['rev_user'] = User::idFromName( $this->target );
+                               $index = 'user_timestamp';
+                       }
                }
                if( $this->deletedOnly ) {
                        $condition[] = "rev_deleted != '0'";
@@ -661,9 +670,12 @@ class ContribsPager extends ReverseChronologicalPager {
                        $d = '<span class="history-deleted">' . $d . '</span>';
                }
 
+               # Show user names for /newbies as there may be different users.
+               # Note that we already excluded rows with hidden user names.
                if( $this->target == 'newbies' ) {
-                       $userlink = ' . . ' . Linker::userLink( $row->rev_user, $row->rev_user_text );
-                       $userlink .= ' ' . wfMsg( 'parentheses', Linker::userTalkLink( $row->rev_user, $row->rev_user_text ) ) . ' ';
+                       $userlink = ' . . ' . Linker::userLink( $rev->getUser(), $rev->getUserText() );
+                       $userlink .= ' ' . wfMsg( 'parentheses',
+                               Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) ) . ' ';
                } else {
                        $userlink = '';
                }
index 31bec0c..1d9960a 100644 (file)
@@ -479,16 +479,14 @@ class MergeHistoryPager extends ReverseChronologicalPager {
        function getQueryInfo() {
                $conds = $this->mConds;
                $conds['rev_page'] = $this->articleID;
-               $conds[] = 'page_id = rev_page';
                $conds[] = "rev_timestamp < {$this->maxTimestamp}";
                return array(
-                       'tables' => array( 'revision', 'page' ),
-                       'fields' => array(
-                               'rev_minor_edit', 'rev_timestamp', 'rev_user', 'rev_user_text',
-                               'rev_comment', 'rev_id', 'rev_page', 'rev_parent_id',
-                               'rev_text_id', 'rev_len', 'rev_deleted'
-                       ),
-                       'conds' => $conds
+                       'tables' => array( 'revision', 'page', 'user' ),
+                       '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' ) )
                );
        }