session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
if( !defined( 'MW_NO_SESSION' ) ) {
- if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
+ if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || $wgRequest->getCookie( 'Token' ) ) ) {
wfIncrStats( 'request_with_session' );
wfSetupSession();
$wgSessionStarted = true;
function loadDefaults( $name = false ) {
wfProfileIn( __METHOD__ );
- global $wgCookiePrefix;
+ global $wgRequest;
$this->mId = 0;
$this->mName = $name;
$this->mOptionOverrides = null;
$this->mOptionsLoaded = false;
- if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
- $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
+ if( $wgRequest->getCookie( 'LoggedOut' ) ) {
+ $this->mTouched = wfTimestamp( TS_MW, $wgRequest->getCookie( '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 $wgCookiePrefix, $wgExternalAuthType, $wgAutocreatePolicy;
+ global $wgRequest, $wgExternalAuthType, $wgAutocreatePolicy;
$result = null;
wfRunHooks( 'UserLoadFromSession', array( $this, &$result ) );
}
}
- if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
- $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
+ if ( $wgRequest->getCookie( 'UserID' ) ) {
+ $sId = intval( $wgRequest->getCookie( 'UserID' ) );
if( isset( $_SESSION['wsUserID'] ) && $sId != $_SESSION['wsUserID'] ) {
$this->loadDefaults(); // Possible collision!
wfDebugLog( 'loginSessions', "Session user ID ({$_SESSION['wsUserID']}) and
if ( isset( $_SESSION['wsUserName'] ) ) {
$sName = $_SESSION['wsUserName'];
- } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
- $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
+ } else if ( $wgRequest->getCookie('UserName') ) {
+ $sName = $wgRequest->getCookie('UserName');
$_SESSION['wsUserName'] = $sName;
} else {
$this->loadDefaults();
if ( isset( $_SESSION['wsToken'] ) ) {
$passwordCorrect = $_SESSION['wsToken'] == $this->mToken;
$from = 'session';
- } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
- $passwordCorrect = $this->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
+ } else if ( $wgRequest->getCookie( 'Token' ) ) {
+ $passwordCorrect = $this->mToken == $wgRequest->getCookie( 'Token' );
$from = 'cookie';
} else {
# No session or persistent login cookie
* @return Boolean
*/
public function checkSessionCookie() {
- return isset( $_COOKIE[session_name()] );
+ return isset( $_COOKIE[ session_name() ] );
}
/**
* Get a cookie from the $_COOKIE jar
*
* @param $key String: the name of the cookie
- * @param $default Mixed: what to return if the value isn't found
* @param $prefix String: a prefix to use for the cookie name, if not $wgCookiePrefix
+ * @param $default Mixed: what to return if the value isn't found
* @return Mixed: cookie value or $default if the cookie not set
*/
- public function getCookie( $key, $default = null, $prefix = '' ) {
- if( !$prefix ) {
+ public function getCookie( $key, $prefix = null, $default = null ) {
+ if( $prefix === null ) {
global $wgCookiePrefix;
$prefix = $wgCookiePrefix;
}
# Try using the session table. It will only have a row if the user has
# an active session, so it might not always work, but it's a lot easier
# than trying to convince PHP to give us vB's $_SESSION.
- global $wgExternalAuthConf;
+ global $wgExternalAuthConf, $wgRequest;
if ( !isset( $wgExternalAuthConf['cookieprefix'] ) ) {
$prefix = 'bb';
} else {
$prefix = $wgExternalAuthConf['cookieprefix'];
}
- if ( !isset( $_COOKIE["{$prefix}sessionhash"] ) ) {
+ if ( !$wgRequest->getCookie( 'sessionhash', $prefix ) ) {
return false;
}
$this->getFields(),
array(
'session.userid = user.userid',
- 'sessionhash' => $_COOKIE["{$prefix}sessionhash"]
+ 'sessionhash' => $wgRequest->getCookie( 'sessionhash', $prefix ),
),
__METHOD__
);
*/
function mainLoginForm( $msg, $msgtype = 'error' ) {
global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
- global $wgCookiePrefix, $wgLoginLanguageSelector;
+ global $wgRequest, $wgLoginLanguageSelector;
global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
$titleObj = SpecialPage::getTitleFor( 'Userlogin' );
if ( $wgUser->isLoggedIn() ) {
$this->mName = $wgUser->getName();
} else {
- $this->mName = isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : null;
+ $this->mName = $wgRequest->getCookie( 'UserName' );
}
}