r100300 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100299‎ | r100300 | r100301 >
Date:00:04, 20 October 2011
Author:aaron
Status:ok
Tags:
Comment:
JOIN to get user_name in Contributions, HistoryPage, RevisionList, RevisionDelete, and MergeHistory
Modified paths:
  • /trunk/phase3/includes/HistoryPage.php (modified) (history)
  • /trunk/phase3/includes/RevisionList.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDelete.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMergeHistory.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/revisiondelete/RevisionDelete.php
@@ -25,14 +25,17 @@
2626 */
2727 public function doQuery( $db ) {
2828 $ids = array_map( 'intval', $this->ids );
29 - $live = $db->select( array('revision','page'), '*',
 29+ $live = $db->select(
 30+ array( 'revision', 'page', 'user' ),
 31+ array_merge( Revision::selectFields(), Revision::selectUserFields() ),
3032 array(
3133 'rev_page' => $this->title->getArticleID(),
3234 'rev_id' => $ids,
33 - 'rev_page = page_id'
3435 ),
3536 __METHOD__,
36 - array( 'ORDER BY' => 'rev_id DESC' )
 37+ array( 'ORDER BY' => 'rev_id DESC' ),
 38+ array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
 39+ 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
3740 );
3841
3942 if ( $live->numRows() >= count( $ids ) ) {
@@ -128,7 +131,7 @@
129132 }
130133
131134 public function getAuthorNameField() {
132 - return 'rev_user_text';
 135+ return 'rev_user_name'; // see Revision::selectUserFields()
133136 }
134137
135138 public function canView() {
Index: trunk/phase3/includes/HistoryPage.php
@@ -342,13 +342,15 @@
343343
344344 function getQueryInfo() {
345345 $queryInfo = array(
346 - 'tables' => array( 'revision' ),
347 - 'fields' => Revision::selectFields(),
 346+ 'tables' => array( 'revision', 'user' ),
 347+ 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
348348 'conds' => array_merge(
349349 array( 'rev_page' => $this->title->getArticleID() ),
350350 $this->conds ),
351351 'options' => array( 'USE INDEX' => array( 'revision' => 'page_timestamp' ) ),
352 - 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
 352+ 'join_conds' => array(
 353+ 'user' => array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' ),
 354+ 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ),
353355 );
354356 ChangeTags::modifyDisplayQuery(
355357 $queryInfo['tables'],
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -470,16 +470,20 @@
471471 $conds[] = $this->mDb->bitAnd('rev_deleted',Revision::SUPPRESSED_USER) .
472472 ' != ' . Revision::SUPPRESSED_USER;
473473 }
474 - $join_cond['page'] = array( 'INNER JOIN', 'page_id=rev_page' );
475474
 475+ # Don't include orphaned revisions
 476+ $join_cond['page'] = array( 'INNER JOIN', 'page_id = rev_page' );
 477+ # Get the current user name for accounts
 478+ $join_cond['user'] = array( 'LEFT JOIN', 'rev_user != 0 AND user_id = rev_user' );
 479+
476480 $queryInfo = array(
477481 'tables' => $tables,
478 - 'fields' => array(
 482+ 'fields' => array_merge( Revision::selectUserFields(), array(
479483 'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'page_is_redirect',
480 - 'page_len','rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
 484+ 'page_len', 'rev_id', 'rev_page', 'rev_text_id', 'rev_timestamp', 'rev_comment',
481485 'rev_minor_edit', 'rev_user', 'rev_user_text', 'rev_parent_id', 'rev_deleted',
482 - 'rev_len', 'rev_parent_id'
483 - ),
 486+ 'rev_len'
 487+ ) ),
484488 'conds' => $conds,
485489 'options' => array( 'USE INDEX' => array('revision' => $index) ),
486490 'join_conds' => $join_cond
@@ -501,8 +505,9 @@
502506 function getUserCond() {
503507 $condition = array();
504508 $join_conds = array();
 509+ $tables = array( 'revision', 'page', 'user' );
505510 if( $this->target == 'newbies' ) {
506 - $tables = array( 'user_groups', 'page', 'revision' );
 511+ $tables[] = 'user_groups';
507512 $max = $this->mDb->selectField( 'user', 'max(user_id)', false, __METHOD__ );
508513 $condition[] = 'rev_user >' . (int)($max - $max / 100);
509514 $condition[] = 'ug_group IS NULL';
@@ -510,9 +515,13 @@
511516 # @todo FIXME: Other groups may have 'bot' rights
512517 $join_conds['user_groups'] = array( 'LEFT JOIN', "ug_user = rev_user AND ug_group = 'bot'" );
513518 } else {
514 - $tables = array( 'page', 'revision' );
515 - $condition['rev_user_text'] = $this->target;
516 - $index = 'usertext_timestamp';
 519+ if ( IP::isIPAddress( $this->target ) ) {
 520+ $condition['rev_user_text'] = $this->target;
 521+ $index = 'usertext_timestamp';
 522+ } else {
 523+ $condition['rev_user'] = User::idFromName( $this->target );
 524+ $index = 'user_timestamp';
 525+ }
517526 }
518527 if( $this->deletedOnly ) {
519528 $condition[] = "rev_deleted != '0'";
@@ -661,9 +670,12 @@
662671 $d = '<span class="history-deleted">' . $d . '</span>';
663672 }
664673
 674+ # Show user names for /newbies as there may be different users.
 675+ # Note that we already excluded rows with hidden user names.
665676 if( $this->target == 'newbies' ) {
666 - $userlink = ' . . ' . Linker::userLink( $row->rev_user, $row->rev_user_text );
667 - $userlink .= ' ' . wfMsg( 'parentheses', Linker::userTalkLink( $row->rev_user, $row->rev_user_text ) ) . ' ';
 677+ $userlink = ' . . ' . Linker::userLink( $rev->getUser(), $rev->getUserText() );
 678+ $userlink .= ' ' . wfMsg( 'parentheses',
 679+ Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) ) . ' ';
668680 } else {
669681 $userlink = '';
670682 }
Index: trunk/phase3/includes/specials/SpecialMergeHistory.php
@@ -479,16 +479,14 @@
480480 function getQueryInfo() {
481481 $conds = $this->mConds;
482482 $conds['rev_page'] = $this->articleID;
483 - $conds[] = 'page_id = rev_page';
484483 $conds[] = "rev_timestamp < {$this->maxTimestamp}";
485484 return array(
486 - 'tables' => array( 'revision', 'page' ),
487 - 'fields' => array(
488 - 'rev_minor_edit', 'rev_timestamp', 'rev_user', 'rev_user_text',
489 - 'rev_comment', 'rev_id', 'rev_page', 'rev_parent_id',
490 - 'rev_text_id', 'rev_len', 'rev_deleted'
491 - ),
492 - 'conds' => $conds
 485+ 'tables' => array( 'revision', 'page', 'user' ),
 486+ 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
 487+ 'conds' => $conds,
 488+ 'join_conds' => array(
 489+ 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
 490+ 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
493491 );
494492 }
495493
Index: trunk/phase3/includes/RevisionList.php
@@ -250,19 +250,18 @@
251251 * @return mixed
252252 */
253253 public function doQuery( $db ) {
254 - $conds = array(
255 - 'rev_page' => $this->title->getArticleID(),
256 - 'rev_page = page_id'
257 - );
 254+ $conds = array( 'rev_page' => $this->title->getArticleID() );
258255 if ( $this->ids !== null ) {
259256 $conds['rev_id'] = array_map( 'intval', $this->ids );
260257 }
261258 return $db->select(
262 - array( 'revision', 'page' ),
263 - '*',
 259+ array( 'revision', 'page', 'user' ),
 260+ array_merge( Revision::selectFields(), Revision::selectUserFields() ),
264261 $conds,
265262 __METHOD__,
266 - array( 'ORDER BY' => 'rev_id DESC' )
 263+ array( 'ORDER BY' => 'rev_id DESC' ),
 264+ array( 'page' => array( 'INNER JOIN', 'rev_page = page_id' ),
 265+ 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) )
267266 );
268267 }
269268
@@ -296,7 +295,7 @@
297296 }
298297
299298 public function getAuthorNameField() {
300 - return 'rev_user_text';
 299+ return 'rev_user_name'; // see Revision::selectUserFields()
301300 }
302301
303302 public function canView() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r100304FU r100300, r100286:...aaron00:41, 20 October 2011

Status & tagging log