$mLocked, $mHideName, $mOptions;
/**
- * @var Skin
+ * @var WebRequest
*/
- var $mSkin;
+ private $mRequest;
/**
* @var Block
* Create a new user object using data from session or cookies. If the
* login credentials are invalid, the result is an anonymous user.
*
+ * @param $request WebRequest object to use; $wgRequest will be used if
+ * ommited.
* @return User
*/
- static function newFromSession() {
+ static function newFromSession( WebRequest $request = null ) {
$user = new User;
$user->mFrom = 'session';
+ $user->mRequest = $request;
return $user;
}
function loadDefaults( $name = false ) {
wfProfileIn( __METHOD__ );
- global $wgRequest;
-
$this->mId = 0;
$this->mName = $name;
$this->mRealName = '';
$this->mOptionOverrides = null;
$this->mOptionsLoaded = false;
- if( $wgRequest->getCookie( 'LoggedOut' ) !== null ) {
- $this->mTouched = wfTimestamp( TS_MW, $wgRequest->getCookie( 'LoggedOut' ) );
+ $loggedOut = $this->getRequest()->getCookie( 'LoggedOut' );
+ if( $loggedOut !== null ) {
+ $this->mTouched = wfTimestamp( TS_MW, $loggedOut );
} else {
$this->mTouched = '0'; # Allow any pages to be cached
}
* @return Bool True if the user is logged in, false otherwise.
*/
private function loadFromSession() {
- global $wgRequest, $wgExternalAuthType, $wgAutocreatePolicy;
+ global $wgExternalAuthType, $wgAutocreatePolicy;
$result = null;
wfRunHooks( 'UserLoadFromSession', array( $this, &$result ) );
}
}
- $cookieId = $wgRequest->getCookie( 'UserID' );
- $sessId = $wgRequest->getSessionData( 'wsUserID' );
+ $request = $this->getRequest();
+
+ $cookieId = $request->getCookie( 'UserID' );
+ $sessId = $request->getSessionData( 'wsUserID' );
if ( $cookieId !== null ) {
$sId = intval( $cookieId );
cookie user ID ($sId) don't match!" );
return false;
}
- $wgRequest->setSessionData( 'wsUserID', $sId );
+ $request->setSessionData( 'wsUserID', $sId );
} elseif ( $sessId !== null && $sessId != 0 ) {
$sId = $sessId;
} else {
return false;
}
- if ( $wgRequest->getSessionData( 'wsUserName' ) !== null ) {
- $sName = $wgRequest->getSessionData( 'wsUserName' );
- } elseif ( $wgRequest->getCookie( 'UserName' ) !== null ) {
- $sName = $wgRequest->getCookie( 'UserName' );
- $wgRequest->setSessionData( 'wsUserName', $sName );
+ if ( $request->getSessionData( 'wsUserName' ) !== null ) {
+ $sName = $request->getSessionData( 'wsUserName' );
+ } elseif ( $request->getCookie( 'UserName' ) !== null ) {
+ $sName = $request->getCookie( 'UserName' );
+ $request->setSessionData( 'wsUserName', $sName );
} else {
$this->loadDefaults();
return false;
return false;
}
- if ( $wgRequest->getSessionData( 'wsToken' ) !== null ) {
- $passwordCorrect = $proposedUser->getToken() === $wgRequest->getSessionData( 'wsToken' );
+ if ( $request->getSessionData( 'wsToken' ) !== null ) {
+ $passwordCorrect = $proposedUser->getToken() === $request->getSessionData( 'wsToken' );
$from = 'session';
- } elseif ( $wgRequest->getCookie( 'Token' ) !== null ) {
- $passwordCorrect = $proposedUser->getToken() === $wgRequest->getCookie( 'Token' );
+ } elseif ( $request->getCookie( 'Token' ) !== null ) {
+ $passwordCorrect = $proposedUser->getToken() === $request->getCookie( 'Token' );
$from = 'cookie';
} else {
# No session or persistent login cookie
if ( ( $sName === $proposedUser->getName() ) && $passwordCorrect ) {
$this->loadFromUserObject( $proposedUser );
- $wgRequest->setSessionData( 'wsToken', $this->mToken );
+ $request->setSessionData( 'wsToken', $this->mToken );
wfDebug( "User: logged in from $from\n" );
return true;
} else {
$this->mDatePreference = null;
$this->mBlockedby = -1; # Unset
$this->mHash = false;
- $this->mSkin = null;
$this->mRights = null;
$this->mEffectiveGroups = null;
$this->mOptions = null;
$this->load();
$this->loadOptions();
- if ( $oname == 'skin' ) {
- # Clear cached skin, so the new one displays immediately in Special:Preferences
- $this->mSkin = null;
- }
-
// Explicitly NULL values should refer to defaults
global $wgDefaultUserOptions;
if( is_null( $val ) && isset( $wgDefaultUserOptions[$oname] ) ) {
return( ( $wgUseRCPatrol || $wgUseNPPatrol ) && ( $this->isAllowedAny( 'patrol', 'patrolmarks' ) ) );
}
+ /**
+ * Get the WebRequest object to use with this object
+ *
+ * @return WebRequest
+ */
+ public function getRequest() {
+ if ( $this->mRequest ) {
+ return $this->mRequest;
+ } else {
+ global $wgRequest;
+ return $wgRequest;
+ }
+ }
+
/**
* Get the current skin, loading it if required
* @return Skin The current skin
* if 0 or not specified, use the default $wgCookieExpiration
*/
protected function setCookie( $name, $value, $exp = 0 ) {
- global $wgRequest;
- $wgRequest->response()->setcookie( $name, $value, $exp );
+ $this->getRequest()->response()->setcookie( $name, $value, $exp );
}
/**
*/
function setCookies( $request = null ) {
if ( $request === null ) {
- global $wgRequest;
- $request = $wgRequest;
+ $request = $this->getRequest();
}
$this->load();
* @see logout()
*/
function doLogout() {
- global $wgRequest;
-
$this->clearInstanceCache( 'defaults' );
- $wgRequest->setSessionData( 'wsUserID', 0 );
+ $this->getRequest()->setSessionData( 'wsUserID', 0 );
$this->clearCookie( 'UserID' );
$this->clearCookie( 'Token' );
*/
function editToken( $salt = '', $request = null ) {
if ( $request == null ) {
- global $wgRequest;
- $request = $wgRequest;
+ $request = $this->getRequest();
}
if ( $this->isAnon() ) {