*/
public static function isValidEmailAddr( $addr ) {
$result = null;
- if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result, $this ) ) ) {
+ if( !wfRunHooks( 'isValidEmailAddr', array( $addr, &$result ) ) ) {
return $result;
}
return $result;
}
- global $wgRateLimits, $wgRateLimitsExcludedGroups;
+ global $wgRateLimits;
if( !isset( $wgRateLimits[$action] ) ) {
return false;
}
/**
* Get the list of implicit group memberships this user has.
- * This includes all explicit groups, plus 'user' if logged in
- * and '*' for all accounts.
+ * This includes all explicit groups, plus 'user' if logged in,
+ * '*' for all accounts and autopromoted groups
* @param boolean $recache Don't use the cache
* @return array of strings
*/
$this->mEffectiveGroups[] = '*';
if( $this->mId ) {
$this->mEffectiveGroups[] = 'user';
-
- global $wgAutoConfirmAge, $wgAutoConfirmCount;
- $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration );
- if( $accountAge >= $wgAutoConfirmAge && $this->getEditCount() >= $wgAutoConfirmCount ) {
- $this->mEffectiveGroups[] = 'autoconfirmed';
- }
- # Implicit group for users whose email addresses are confirmed
- global $wgEmailAuthentication;
- if( self::isValidEmailAddr( $this->mEmail ) ) {
- if( $wgEmailAuthentication ) {
- if( $this->mEmailAuthenticated )
- $this->mEffectiveGroups[] = 'emailconfirmed';
- } else {
- $this->mEffectiveGroups[] = 'emailconfirmed';
- }
- }
+ $this->mEffectiveGroups = array_unique( array_merge(
+ $this->mEffectiveGroups,
+ Autopromote::getAutopromoteGroups( $this )
+ ) );
+
# Hook for additional groups
wfRunHooks( 'UserEffectiveGroups', array( &$this, &$this->mEffectiveGroups ) );
}
* @return bool
*/
function isLoggedIn() {
- if( $this->mId === null and $this->mName !== null ) {
- // Special-case optimization
- return !self::isIP( $this->mName );
- }
return $this->getID() != 0;
}
}
/**
- * Logout user
- * Clears the cookies and session, resets the instance cache
+ * Logout user.
*/
function logout() {
+ global $wgUser;
+ if( wfRunHooks( 'UserLogout', array(&$this) ) ) {
+ $this->doLogout();
+ wfRunHooks( 'UserLogoutComplete', array(&$wgUser) );
+ }
+ }
+
+ /**
+ * Really logout user
+ * Clears the cookies and session, resets the instance cache
+ */
+ function doLogout() {
global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix;
$this->clearInstanceCache( 'defaults' );
/**
- * Checks if a user with the given name exists, returns the ID
+ * Checks if a user with the given name exists, returns the ID.
*/
function idForName() {
$s = trim( $this->getName() );
- if ( 0 == strcmp( '', $s ) ) return 0;
+ if ( $s === '' ) return 0;
$dbr = wfGetDB( DB_SLAVE );
$id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ );
*
* @param string $subject
* @param string $body
- * @param strong $from Optional from address; default $wgPasswordSender will be used otherwise.
+ * @param string $from Optional from address; default $wgPasswordSender will be used otherwise.
* @return mixed True on success, a WikiError object on failure.
*/
- function sendMail( $subject, $body, $from = null ) {
+ function sendMail( $subject, $body, $from = null, $replyto = null ) {
if( is_null( $from ) ) {
global $wgPasswordSender;
$from = $wgPasswordSender;
$to = new MailAddress( $this );
$sender = new MailAddress( $from );
- $error = UserMailer::send( $to, $sender, $subject, $body );
-
- if( $error == '' ) {
- return true;
- } else {
- return new WikiError( $error );
- }
+ return UserMailer::send( $to, $sender, $subject, $body, $replyto );
}
/**
* @return bool
*/
function canSendEmail() {
- return $this->isEmailConfirmed();
+ $canSend = $this->isEmailConfirmed();
+ wfRunHooks( 'UserCanSendEmail', array( &$this, &$canSend ) );
+ return $canSend;
}
/**
* @return bool
*/
function canReceiveEmail() {
- return $this->canSendEmail() && !$this->getOption( 'disablemail' );
+ return $this->isEmailConfirmed() && !$this->getOption( 'disablemail' );
}
/**
* @return array
*/
public static function getImplicitGroups() {
- static $groups = null;
- if( !is_array( $groups ) ) {
- $groups = array( '*', 'user', 'autoconfirmed', 'emailconfirmed' );
- wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) );
- }
+ global $wgImplicitGroups;
+ $groups = $wgImplicitGroups;
+ wfRunHooks( 'UserGetImplicitGroups', array( &$groups ) ); #deprecated, use $wgImplictGroups instead
return $groups;
}