http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100300

Revision: 100300
Author:   aaron
Date:     2011-10-20 00:04:14 +0000 (Thu, 20 Oct 2011)
Log Message:
-----------
JOIN to get user_name in Contributions, HistoryPage, RevisionList, 
RevisionDelete, and MergeHistory

Modified Paths:
--------------
    trunk/phase3/includes/HistoryPage.php
    trunk/phase3/includes/RevisionList.php
    trunk/phase3/includes/revisiondelete/RevisionDelete.php
    trunk/phase3/includes/specials/SpecialContributions.php
    trunk/phase3/includes/specials/SpecialMergeHistory.php

Modified: trunk/phase3/includes/HistoryPage.php
===================================================================
--- trunk/phase3/includes/HistoryPage.php       2011-10-19 23:56:48 UTC (rev 
100299)
+++ trunk/phase3/includes/HistoryPage.php       2011-10-20 00:04:14 UTC (rev 
100300)
@@ -342,13 +342,15 @@
 
        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'],

Modified: trunk/phase3/includes/RevisionList.php
===================================================================
--- trunk/phase3/includes/RevisionList.php      2011-10-19 23:56:48 UTC (rev 
100299)
+++ trunk/phase3/includes/RevisionList.php      2011-10-20 00:04:14 UTC (rev 
100300)
@@ -250,19 +250,18 @@
         * @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 @@
        }
 
        public function getAuthorNameField() {
-               return 'rev_user_text';
+               return 'rev_user_name'; // see Revision::selectUserFields()
        }
 
        public function canView() {

Modified: trunk/phase3/includes/revisiondelete/RevisionDelete.php
===================================================================
--- trunk/phase3/includes/revisiondelete/RevisionDelete.php     2011-10-19 
23:56:48 UTC (rev 100299)
+++ trunk/phase3/includes/revisiondelete/RevisionDelete.php     2011-10-20 
00:04:14 UTC (rev 100300)
@@ -25,14 +25,17 @@
         */
        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 @@
        }
 
        public function getAuthorNameField() {
-               return 'rev_user_text';
+               return 'rev_user_name'; // see Revision::selectUserFields()
        }
 
        public function canView() {

Modified: trunk/phase3/includes/specials/SpecialContributions.php
===================================================================
--- trunk/phase3/includes/specials/SpecialContributions.php     2011-10-19 
23:56:48 UTC (rev 100299)
+++ trunk/phase3/includes/specials/SpecialContributions.php     2011-10-20 
00:04:14 UTC (rev 100300)
@@ -470,16 +470,20 @@
                        $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 @@
        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 @@
                        # @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 @@
                        $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 = '';
                }

Modified: trunk/phase3/includes/specials/SpecialMergeHistory.php
===================================================================
--- trunk/phase3/includes/specials/SpecialMergeHistory.php      2011-10-19 
23:56:48 UTC (rev 100299)
+++ trunk/phase3/includes/specials/SpecialMergeHistory.php      2011-10-20 
00:04:14 UTC (rev 100300)
@@ -479,16 +479,14 @@
        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' ) )
                );
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to