* @todo document
*/
class Revision {
+ protected $mId;
+ protected $mPage;
+ protected $mUserText;
+ protected $mOrigUserText;
+ protected $mUser;
+ protected $mMinorEdit;
+ protected $mTimestamp;
+ protected $mDeleted;
+ protected $mSize;
+ protected $mParentId;
+ protected $mComment;
+ protected $mText;
+ protected $mTextRow;
+ protected $mTitle;
+ protected $mCurrent;
+
const DELETED_TEXT = 1;
const DELETED_COMMENT = 2;
const DELETED_USER = 4;
* Return the list of text fields that should be selected to read the
* revision text
*/
- static function selectTextFields() {
+ public static function selectTextFields() {
return array(
'old_text',
'old_flags'
/**
* Return the list of page fields that should be selected from page table
*/
- static function selectPageFields() {
+ public static function selectPageFields() {
return array(
'page_namespace',
'page_title',
/**
* 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' );
+ public static function selectUserFields() {
+ return array( 'user_name' );
}
/**
$this->mDeleted = intval( $row->rev_deleted );
if( !isset( $row->rev_parent_id ) ) {
- $this->mParentId = is_null($row->rev_parent_id) ? null : 0;
+ $this->mParentId = is_null( $row->rev_parent_id ) ? null : 0;
} else {
$this->mParentId = intval( $row->rev_parent_id );
}
$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
+ // Use user_name for users and rev_user_text for IPs...
+ $this->mUserText = null; // lazy load if left null
+ if ( $this->mUser == 0 ) {
+ $this->mUserText = $row->rev_user_text; // IP user
+ } elseif ( isset( $row->user_name ) ) {
+ $this->mUserText = $row->user_name; // logged-in user
}
+ $this->mOrigUserText = $row->rev_user_text;
} elseif( is_array( $row ) ) {
// Build a new revision to be saved...
global $wgUser;
} elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) {
return '';
} else {
- return $this->mUserText;
+ return $this->getRawUserText();
}
}
* @return String
*/
public function getRawUserText() {
+ if ( $this->mUserText === null ) {
+ $this->mUserText = User::whoIs( $this->mUser ); // load on demand
+ if ( $this->mUserText === false ) {
+ # This shouldn't happen, but it can if the wiki was recovered
+ # via importing revs and there is no user table entry yet.
+ $this->mUserText = $this->mOrigUserText;
+ }
+ }
return $this->mUserText;
}