* @file
*/
-/**
- * Int Number of characters in user_token field.
- * @ingroup Constants
- */
-define( 'USER_TOKEN_LENGTH', 32 );
-
-/**
- * Int Serialized record version.
- * @ingroup Constants
- */
-define( 'MW_USER_VERSION', 10 );
-
/**
* String Some punctuation to prevent editing from broken text-mangling proxies.
* @ingroup Constants
*/
define( 'EDIT_TOKEN_SUFFIX', '+\\' );
-/**
- * Thrown by User::setPassword() on error.
- * @ingroup Exception
- */
-class PasswordError extends MWException {
- // NOP
-}
-
/**
* The User object encapsulates all of the user-specific settings (user_id,
* name, rights, password, email address, options, last login time). Client
*/
class User implements IDBAccessObject {
/**
- * Global constants made accessible as class constants so that autoloader
+ * @const int Number of characters in user_token field.
+ */
+ const TOKEN_LENGTH = 32;
+
+ /**
+ * Global constant made accessible as class constants so that autoloader
* magic can be used.
*/
- const USER_TOKEN_LENGTH = USER_TOKEN_LENGTH;
- const MW_USER_VERSION = MW_USER_VERSION;
const EDIT_TOKEN_SUFFIX = EDIT_TOKEN_SUFFIX;
+ /**
+ * @const int Serialized record version.
+ */
+ const VERSION = 10;
+
/**
* Maximum items in $mWatchedItems
*/
public $mRealName;
+ /**
+ * @todo Make this actually private
+ * @private
+ */
public $mPassword;
+ /**
+ * @todo Make this actually private
+ * @private
+ */
public $mNewpassword;
public $mNewpassTime;
// Try cache
$key = wfMemcKey( 'user', 'id', $this->mId );
$data = $wgMemc->get( $key );
- if ( !is_array( $data ) || $data['mVersion'] != MW_USER_VERSION ) {
+ if ( !is_array( $data ) || $data['mVersion'] != self::VERSION ) {
// Object is expired, load from DB
$data = false;
}
foreach ( self::$mCacheVars as $name ) {
$data[$name] = $this->$name;
}
- $data['mVersion'] = MW_USER_VERSION;
+ $data['mVersion'] = self::VERSION;
$key = wfMemcKey( 'user', 'id', $this->mId );
global $wgMemc;
$wgMemc->set( $key, $data );
return false;
}
- // Clean up name according to title rules
- $t = ( $validate === 'valid' ) ?
+ // Clean up name according to title rules,
+ // but only when validation is requested (bug 12654)
+ $t = ( $validate !== false ) ?
Title::newFromText( $name ) : Title::makeTitle( NS_USER, $name );
// Check for invalid titles
if ( is_null( $t ) ) {
return $this->mTouched;
}
+ /**
+ * @return Password
+ * @since 1.24
+ */
+ public function getPassword() {
+ $this->loadPasswords();
+
+ return $this->mPassword;
+ }
+
+ /**
+ * @return Password
+ * @since 1.24
+ */
+ public function getTemporaryPassword() {
+ $this->loadPasswords();
+
+ return $this->mNewpassword;
+ }
+
/**
* Set the password and reset the random token.
* Calls through to authentication plugin if necessary;
public function setPassword( $str ) {
global $wgAuth;
+ $this->loadPasswords();
+
if ( $str !== null ) {
if ( !$wgAuth->allowPasswordChange() ) {
throw new PasswordError( wfMessage( 'password-change-forbidden' )->text() );
public function setToken( $token = false ) {
$this->load();
if ( !$token ) {
- $this->mToken = MWCryptRand::generateHex( USER_TOKEN_LENGTH );
+ $this->mToken = MWCryptRand::generateHex( self::TOKEN_LENGTH );
} else {
$this->mToken = $token;
}
* @param bool $throttle If true, reset the throttle timestamp to the present
*/
public function setNewpassword( $str, $throttle = true ) {
- $this->load();
+ $this->loadPasswords();
if ( $str === null ) {
$this->mNewpassword = '';
if ( $str == $this->mEmail ) {
return;
}
- $this->mEmail = $str;
$this->invalidateEmail();
+ $this->mEmail = $str;
wfRunHooks( 'UserSetEmail', array( $this, &$this->mEmail ) );
}
foreach ( $columns as $column ) {
foreach ( $rows as $row ) {
- $checkmatrixOptions["$prefix-$column-$row"] = true;
+ $checkmatrixOptions["$prefix$column-$row"] = true;
}
}
global $wgNewPasswordExpiry;
$this->load();
+ $this->loadPasswords();
if ( $this->mNewpassword->equals( $plaintext ) ) {
if ( is_null( $this->mNewpassTime ) ) {
return true;
}
if ( $this->isAnon() ) {
- return EDIT_TOKEN_SUFFIX;
+ return self::EDIT_TOKEN_SUFFIX;
} else {
$token = $request->getSessionData( 'wsEditToken' );
if ( $token === null ) {
if ( is_array( $salt ) ) {
$salt = implode( '|', $salt );
}
- return md5( $token . $salt ) . EDIT_TOKEN_SUFFIX;
+ return md5( $token . $salt ) . self::EDIT_TOKEN_SUFFIX;
}
}
$this->mEmailToken = null;
$this->mEmailTokenExpires = null;
$this->setEmailAuthenticationTimestamp( null );
+ $this->mEmail = '';
wfRunHooks( 'InvalidateEmailComplete', array( $this ) );
return true;
}