- function loadFromSession() {
- global $wgMemc, $wgCookiePrefix;
-
- if ( isset( $_SESSION['wsUserID'] ) ) {
- if ( 0 != $_SESSION['wsUserID'] ) {
- $sId = $_SESSION['wsUserID'];
- } else {
- return new User();
- }
- } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
- $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
- $_SESSION['wsUserID'] = $sId;
- } else {
- return new User();
- }
- if ( isset( $_SESSION['wsUserName'] ) ) {
- $sName = $_SESSION['wsUserName'];
- } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
- $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
- $_SESSION['wsUserName'] = $sName;
- } else {
- return new User();
- }
-
- $passwordCorrect = FALSE;
- $user = $wgMemc->get( $key = wfMemcKey( 'user', 'id', $sId ) );
- if( !is_object( $user ) || $user->mVersion < MW_USER_VERSION ) {
- # Expire old serialized objects; they may be corrupt.
- $user = false;
- }
- if($makenew = !$user) {
- wfDebug( "User::loadFromSession() unable to load from memcached\n" );
- $user = new User();
- $user->mId = $sId;
- $user->loadFromDatabase();
- } else {
- wfDebug( "User::loadFromSession() got from cache!\n" );
- # Set block status to unloaded, that should be loaded every time
- $user->mBlockedby = -1;
- }
-
- if ( isset( $_SESSION['wsToken'] ) ) {
- $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
- } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
- $passwordCorrect = $user->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
- } else {
- return new User(); # Can't log in from session
- }
-
- if ( ( $sName == $user->mName ) && $passwordCorrect ) {
- if($makenew) {
- if($wgMemc->set( $key, $user ))
- wfDebug( "User::loadFromSession() successfully saved user\n" );
- else
- wfDebug( "User::loadFromSession() unable to save to memcached\n" );
- }
- return $user;
- }
- return new User(); # Can't log in from session
- }
-
- /**
- * Load a user from the database
- */
- function loadFromDatabase() {
- $fname = "User::loadFromDatabase";
-
- # Counter-intuitive, breaks various things, use User::setLoaded() if you want to suppress
- # loading in a command line script, don't assume all command line scripts need it like this
- #if ( $this->mDataLoaded || $wgCommandLineMode ) {
- if ( $this->mDataLoaded ) {
- return;
- }
-
- # Paranoia
- $this->mId = intval( $this->mId );
-
- /** Anonymous user */
- if( !$this->mId ) {
- /** Get rights */
- $this->mRights = $this->getGroupPermissions( array( '*' ) );
- $this->mDataLoaded = true;
- return;
- } # the following stuff is for non-anonymous users only
-
- $dbr =& wfGetDB( DB_SLAVE );
- $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
- 'user_email_authenticated',
- 'user_real_name','user_options','user_touched', 'user_token', 'user_registration' ),
- array( 'user_id' => $this->mId ), $fname );
-
- if ( $s !== false ) {
- $this->mName = $s->user_name;
- $this->mEmail = $s->user_email;
- $this->mEmailAuthenticated = wfTimestampOrNull( TS_MW, $s->user_email_authenticated );
- $this->mRealName = $s->user_real_name;
- $this->mPassword = $s->user_password;
- $this->mNewpassword = $s->user_newpassword;
- $this->decodeOptions( $s->user_options );
- $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
- $this->mToken = $s->user_token;
- $this->mRegistration = wfTimestampOrNull( TS_MW, $s->user_registration );
-
- $res = $dbr->select( 'user_groups',
- array( 'ug_group' ),
- array( 'ug_user' => $this->mId ),
- $fname );
- $this->mGroups = array();
- while( $row = $dbr->fetchObject( $res ) ) {
- $this->mGroups[] = $row->ug_group;
- }
- $implicitGroups = array( '*', 'user' );
-
- global $wgAutoConfirmAge;
- $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration );
- if( $accountAge >= $wgAutoConfirmAge ) {
- $implicitGroups[] = 'autoconfirmed';
- }
-
- # Implicit group for users whose email addresses are confirmed
- global $wgEmailAuthentication;
- if( $this->isValidEmailAddr( $this->mEmail ) ) {
- if( $wgEmailAuthentication ) {
- if( $this->mEmailAuthenticated )
- $implicitGroups[] = 'emailconfirmed';
- } else {
- $implicitGroups[] = 'emailconfirmed';
- }
- }
-
- $effectiveGroups = array_merge( $implicitGroups, $this->mGroups );
- $this->mRights = $this->getGroupPermissions( $effectiveGroups );
- }
-
- $this->mDataLoaded = true;
- }
-
- function getID() { return $this->mId; }