/**
* Bool Whether the cache variables have been loaded.
*/
- //@{
- var $mOptionsLoaded;
- private $mLoadedItems = array();
- //@}
+ var $mDataLoaded, $mAuthLoaded, $mOptionsLoaded;
/**
- * String Initialization data source if mLoadedItems!==true. May be one of:
+ * String Initialization data source if mDataLoaded==false. May be one of:
* - 'defaults' anonymous user initialised from class defaults
* - 'name' initialise from mName
* - 'id' initialise from mId
* Load the user table data for this object from the source given by mFrom.
*/
function load() {
- if ( $this->mLoadedItems === true ) {
+ if ( $this->mDataLoaded ) {
return;
}
wfProfileIn( __METHOD__ );
# Set it now to avoid infinite recursion in accessors
- $this->mLoadedItems = true;
+ $this->mDataLoaded = true;
switch ( $this->mFrom ) {
case 'defaults':
$u = new User;
$u->mName = $name;
$u->mFrom = 'name';
- $u->setItemLoaded( 'name' );
return $u;
}
}
$u = new User;
$u->mId = $id;
$u->mFrom = 'id';
- $u->setItemLoaded( 'id' );
return $u;
}
/**
* Create a new user object from a user row.
- * The row should have the following fields from the user table in it:
- * - either user_name or user_id to load further data if needed (or both)
- * - user_real_name
- * - all other fields (email, password, etc.)
- * It is useless to provide the remaining fields if either user_id,
- * user_name and user_real_name are not provided because the whole row
- * will be loaded once more from the database when accessing them.
- *
+ * The row should have all fields from the user table in it.
* @param $row Array A row from the user table
* @return User
*/
wfProfileOut( __METHOD__ );
}
- /**
- * Return whether an item has been loaded.
- *
- * @param $item String: item to check. Current possibilities:
- * - 'id'
- * - name
- * - realname
- * @return Boolean
- */
- public function isItemLoaded( $item ) {
- return $this->mLoadedItems === true || ( isset( $this->mLoadedItems[$item] )
- && $this->mLoadedItems[$item] === true );
- }
-
- /**
- * Set that an item has been loaded
- *
- * @param $item String
- */
- private function setItemLoaded( $item ) {
- if ( is_array( $this->mLoadedItems ) ) {
- $this->mLoadedItems[$item] = true;
- }
- }
-
/**
* Load user data from the session or login cookie. If there are no valid
* credentials, initialises the user as an anonymous user.
/**
* Load user and user_group data from the database.
- * $this->mId must be set, this is how the user is identified.
+ * $this::mId must be set, this is how the user is identified.
*
* @return Bool True if the user exists, false if the user is anonymous
* @private
* @param $row Array Row from the user table to load.
*/
function loadFromRow( $row ) {
- $all = true;
-
- if ( isset( $row->user_name ) ) {
- $this->mName = $row->user_name;
- $this->mFrom = 'name';
- $this->setItemLoaded( 'name' );
- } else {
- $all = false;
- }
-
- if ( isset( $row->user_name ) ) {
- $this->mRealName = $row->user_real_name;
- $this->setItemLoaded( 'realname' );
- } else {
- $all = false;
- }
+ $this->mDataLoaded = true;
if ( isset( $row->user_id ) ) {
$this->mId = intval( $row->user_id );
- $this->mFrom = 'id';
- $this->setItemLoaded( 'id' );
- } else {
- $all = false;
- }
-
- if ( isset( $row->user_password ) ) {
- $this->mPassword = $row->user_password;
- $this->mNewpassword = $row->user_newpassword;
- $this->mNewpassTime = wfTimestampOrNull( TS_MW, $row->user_newpass_time );
- $this->mEmail = $row->user_email;
- $this->decodeOptions( $row->user_options );
- $this->mTouched = wfTimestamp(TS_MW,$row->user_touched);
- $this->mToken = $row->user_token;
- $this->mEmailAuthenticated = wfTimestampOrNull( TS_MW, $row->user_email_authenticated );
- $this->mEmailToken = $row->user_email_token;
- $this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $row->user_email_token_expires );
- $this->mRegistration = wfTimestampOrNull( TS_MW, $row->user_registration );
- $this->mEditCount = $row->user_editcount;
- } else {
- $all = false;
- }
-
- if ( $all ) {
- $this->mLoadedItems = true;
}
+ $this->mName = $row->user_name;
+ $this->mRealName = $row->user_real_name;
+ $this->mPassword = $row->user_password;
+ $this->mNewpassword = $row->user_newpassword;
+ $this->mNewpassTime = wfTimestampOrNull( TS_MW, $row->user_newpass_time );
+ $this->mEmail = $row->user_email;
+ $this->decodeOptions( $row->user_options );
+ $this->mTouched = wfTimestamp(TS_MW,$row->user_touched);
+ $this->mToken = $row->user_token;
+ $this->mEmailAuthenticated = wfTimestampOrNull( TS_MW, $row->user_email_authenticated );
+ $this->mEmailToken = $row->user_email_token;
+ $this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $row->user_email_token_expires );
+ $this->mRegistration = wfTimestampOrNull( TS_MW, $row->user_registration );
+ $this->mEditCount = $row->user_editcount;
}
/**
$this->mOptions = null;
if ( $reloadFrom ) {
- $this->mLoadedItems = array();
+ $this->mDataLoaded = false;
$this->mFrom = $reloadFrom;
}
}
&& User::isIP( $this->mName ) ) {
// Special case, we know the user is anonymous
return 0;
- } elseif( !$this->isItemLoaded( 'id' ) ) {
+ } elseif( $this->mId === null ) {
// Don't load if this was initialized from an ID
$this->load();
}
* @return String User's name or IP address
*/
function getName() {
- if ( $this->isItemLoaded( 'name' ) ) {
+ if ( !$this->mDataLoaded && $this->mFrom == 'name' ) {
# Special case optimisation
return $this->mName;
} else {
* @return String User's real name
*/
function getRealName() {
- if ( !$this->isItemLoaded( 'realname' ) ) {
- $this->load();
- }
-
+ $this->load();
return $this->mRealName;
}
*/
function checkTemporaryPassword( $plaintext ) {
global $wgNewPasswordExpiry;
-
- $this->load();
if( self::comparePasswords( $this->mNewpassword, $plaintext, $this->getId() ) ) {
if ( is_null( $this->mNewpassTime ) ) {
return true;
* non-existent/anonymous user accounts.
*/
public function getRegistration() {
- if ( $this->isAnon() ) {
- return false;
- }
- $this->load();
- return $this->mRegistration;
+ return $this->getId() > 0
+ ? $this->mRegistration
+ : false;
}
/**