* Always call User::newFromSession(), not only when not in CLI mode
* Removed User::$mSkin, unused and not set
*/
public function getUser() {
if ( !isset($this->user) ) {
*/
public function getUser() {
if ( !isset($this->user) ) {
- global $wgCommandLineMode;
- $this->user = $wgCommandLineMode
- ? new User
- : User::newFromSession( $this->getRequest() );
+ $this->user = User::newFromSession( $this->getRequest() );
public function getSkin() {
return $this->context->getSkin();
}
public function getSkin() {
return $this->context->getSkin();
}
-}
\ No newline at end of file
$mLocked, $mHideName, $mOptions;
/**
$mLocked, $mHideName, $mOptions;
/**
* Create a new user object using data from session or cookies. If the
* login credentials are invalid, the result is an anonymous user.
*
* 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.
- static function newFromSession() {
+ static function newFromSession( WebRequest $request = null ) {
$user = new User;
$user->mFrom = 'session';
$user = new User;
$user->mFrom = 'session';
+ $user->mRequest = $request;
function loadDefaults( $name = false ) {
wfProfileIn( __METHOD__ );
function loadDefaults( $name = false ) {
wfProfileIn( __METHOD__ );
$this->mId = 0;
$this->mName = $name;
$this->mRealName = '';
$this->mId = 0;
$this->mName = $name;
$this->mRealName = '';
$this->mOptionOverrides = null;
$this->mOptionsLoaded = false;
$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
}
} else {
$this->mTouched = '0'; # Allow any pages to be cached
}
* @return Bool True if the user is logged in, false otherwise.
*/
private function loadFromSession() {
* @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 ) );
$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 );
if ( $cookieId !== null ) {
$sId = intval( $cookieId );
cookie user ID ($sId) don't match!" );
return false;
}
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 {
} elseif ( $sessId !== null && $sessId != 0 ) {
$sId = $sessId;
} else {
- 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;
} else {
$this->loadDefaults();
return false;
- if ( $wgRequest->getSessionData( 'wsToken' ) !== null ) {
- $passwordCorrect = $proposedUser->getToken() === $wgRequest->getSessionData( 'wsToken' );
+ if ( $request->getSessionData( 'wsToken' ) !== null ) {
+ $passwordCorrect = $proposedUser->getToken() === $request->getSessionData( 'wsToken' );
- } 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
$from = 'cookie';
} else {
# No session or persistent login cookie
if ( ( $sName === $proposedUser->getName() ) && $passwordCorrect ) {
$this->loadFromUserObject( $proposedUser );
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 {
wfDebug( "User: logged in from $from\n" );
return true;
} else {
$this->mDatePreference = null;
$this->mBlockedby = -1; # Unset
$this->mHash = false;
$this->mDatePreference = null;
$this->mBlockedby = -1; # Unset
$this->mHash = false;
$this->mRights = null;
$this->mEffectiveGroups = null;
$this->mOptions = null;
$this->mRights = null;
$this->mEffectiveGroups = null;
$this->mOptions = null;
$this->load();
$this->loadOptions();
$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] ) ) {
// Explicitly NULL values should refer to defaults
global $wgDefaultUserOptions;
if( is_null( $val ) && isset( $wgDefaultUserOptions[$oname] ) ) {
return( ( $wgUseRCPatrol || $wgUseNPPatrol ) && ( $this->isAllowedAny( 'patrol', 'patrolmarks' ) ) );
}
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
/**
* 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 ) {
* 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 ) {
*/
function setCookies( $request = null ) {
if ( $request === null ) {
- global $wgRequest;
- $request = $wgRequest;
+ $request = $this->getRequest();
* @see logout()
*/
function doLogout() {
* @see logout()
*/
function doLogout() {
$this->clearInstanceCache( 'defaults' );
$this->clearInstanceCache( 'defaults' );
- $wgRequest->setSessionData( 'wsUserID', 0 );
+ $this->getRequest()->setSessionData( 'wsUserID', 0 );
$this->clearCookie( 'UserID' );
$this->clearCookie( 'Token' );
$this->clearCookie( 'UserID' );
$this->clearCookie( 'Token' );
*/
function editToken( $salt = '', $request = null ) {
if ( $request == null ) {
*/
function editToken( $salt = '', $request = null ) {
if ( $request == null ) {
- global $wgRequest;
- $request = $wgRequest;
+ $request = $this->getRequest();
}
if ( $this->isAnon() ) {
}
if ( $this->isAnon() ) {