http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100286
Revision: 100286
Author: aaron
Date: 2011-10-19 22:25:26 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
* Tweaked Revision class to handle loading the current user name instead of
rev_user_text. It still falls back to rev_user_text when building objects from
DB rows for b/c.
* Moved JOIN conds to fetchFromConds() as that's where the tables are
specified. This lets us avoid the same page_id=rev_page join conds plastered
all over the code. Also, we can't mix WHERE and JOIN style join conds.
* Removed duplication in fetchFromConds() by using selectPageFields().
* Removed duplicate rev_parent_id field from contribs SELECT.
Yo make use of these changes, Pagers and lists still need to be updated to use
Revision::selectUserFields() and join on the user table.
Modified Paths:
--------------
trunk/phase3/includes/Revision.php
Modified: trunk/phase3/includes/Revision.php
===================================================================
--- trunk/phase3/includes/Revision.php 2011-10-19 22:13:46 UTC (rev 100285)
+++ trunk/phase3/includes/Revision.php 2011-10-19 22:25:26 UTC (rev 100286)
@@ -23,9 +23,7 @@
* @return Revision or null
*/
public static function newFromId( $id ) {
- return Revision::newFromConds(
- array( 'page_id=rev_page',
- 'rev_id' => intval( $id ) ) );
+ return Revision::newFromConds( array( 'rev_id' => intval( $id )
) );
}
/**
@@ -57,7 +55,6 @@
// Use a join to get the latest revision
$conds[] = 'rev_id=page_latest';
}
- $conds[] = 'page_id=rev_page';
return Revision::newFromConds( $conds );
}
@@ -85,7 +82,6 @@
} else {
$conds[] = 'rev_id = page_latest';
}
- $conds[] = 'page_id=rev_page';
return Revision::newFromConds( $conds );
}
@@ -141,9 +137,7 @@
* @return Revision or null
*/
public static function loadFromId( $db, $id ) {
- return Revision::loadFromConds( $db,
- array( 'page_id=rev_page',
- 'rev_id' => intval( $id ) ) );
+ return Revision::loadFromConds( $db, array( 'rev_id' => intval(
$id ) ) );
}
/**
@@ -157,7 +151,7 @@
* @return Revision or null
*/
public static function loadFromPageId( $db, $pageid, $id = 0 ) {
- $conds = array( 'page_id=rev_page','rev_page' => intval(
$pageid ), 'page_id'=>intval( $pageid ) );
+ $conds = array( 'rev_page' => intval( $pageid ), 'page_id' =>
intval( $pageid ) );
if( $id ) {
$conds['rev_id'] = intval( $id );
} else {
@@ -182,12 +176,11 @@
} else {
$matchId = 'page_latest';
}
- return Revision::loadFromConds(
- $db,
+ return Revision::loadFromConds( $db,
array( "rev_id=$matchId",
- 'page_id=rev_page',
'page_namespace' => $title->getNamespace(),
- 'page_title' => $title->getDBkey() ) );
+ 'page_title' => $title->getDBkey() )
+ );
}
/**
@@ -201,12 +194,11 @@
* @return Revision or null
*/
public static function loadFromTimestamp( $db, $title, $timestamp ) {
- return Revision::loadFromConds(
- $db,
+ return Revision::loadFromConds( $db,
array( 'rev_timestamp' => $db->timestamp( $timestamp ),
- 'page_id=rev_page',
'page_namespace' => $title->getNamespace(),
- 'page_title' => $title->getDBkey() ) );
+ 'page_title' => $title->getDBkey() )
+ );
}
/**
@@ -217,12 +209,12 @@
*/
public static function newFromConds( $conditions ) {
$db = wfGetDB( DB_SLAVE );
- $row = Revision::loadFromConds( $db, $conditions );
- if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
+ $rev = Revision::loadFromConds( $db, $conditions );
+ if( is_null( $rev ) && wfGetLB()->getServerCount() > 1 ) {
$dbw = wfGetDB( DB_MASTER );
- $row = Revision::loadFromConds( $dbw, $conditions );
+ $rev = Revision::loadFromConds( $dbw, $conditions );
}
- return $row;
+ return $rev;
}
/**
@@ -237,7 +229,6 @@
$res = Revision::fetchFromConds( $db, $conditions );
if( $res ) {
$row = $res->fetchObject();
- $res->free();
if( $row ) {
$ret = new Revision( $row );
return $ret;
@@ -260,8 +251,8 @@
wfGetDB( DB_SLAVE ),
array( 'rev_id=page_latest',
'page_namespace' => $title->getNamespace(),
- 'page_title' => $title->getDBkey(),
- 'page_id=rev_page' ) );
+ 'page_title' => $title->getDBkey() )
+ );
}
/**
@@ -274,16 +265,20 @@
* @return ResultWrapper
*/
private static function fetchFromConds( $db, $conditions ) {
- $fields = self::selectFields();
- $fields[] = 'page_namespace';
- $fields[] = 'page_title';
- $fields[] = 'page_latest';
+ $fields = array_merge(
+ self::selectFields(),
+ self::selectPageFields(),
+ self::selectUserFields()
+ );
return $db->select(
- array( 'page', 'revision' ),
+ array( 'revision', 'page', 'user' ),
$fields,
$conditions,
__METHOD__,
- array( 'LIMIT' => 1 ) );
+ array( 'LIMIT' => 1 ),
+ array( 'page' => array( 'INNER JOIN', 'page_id =
rev_page' ),
+ 'user' => array( 'LEFT JOIN', 'user_id =
rev_user' ) )
+ );
}
/**
@@ -329,6 +324,13 @@
}
/**
+ * Return the list of user fields that should be selected from user
table
+ */
+ static function selectUserFields() {
+ return array( 'COALESCE(user_name,rev_user_text) AS
rev_user_name' );
+ }
+
+ /**
* Constructor
*
* @param $row Mixed: either a database row or an array
@@ -340,7 +342,6 @@
$this->mPage = intval( $row->rev_page );
$this->mTextId = intval( $row->rev_text_id );
$this->mComment = $row->rev_comment;
- $this->mUserText = $row->rev_user_text;
$this->mUser = intval( $row->rev_user );
$this->mMinorEdit = intval( $row->rev_minor_edit );
$this->mTimestamp = $row->rev_timestamp;
@@ -374,6 +375,12 @@
// 'text' table row entry will be lazy-loaded
$this->mTextRow = null;
}
+
+ if ( isset( $row->rev_user_name ) ) {
+ $this->mUserText = $row->rev_user_name; //
current user name
+ } else { // fallback to rev_user_text
+ $this->mUserText = $row->rev_user_text; //
de-normalized
+ }
} elseif( is_array( $row ) ) {
// Build a new revision to be saved...
global $wgUser;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs