From: Chad Horohoe Date: Fri, 6 Aug 2010 15:00:43 +0000 (+0000) Subject: Cleanup getCookie() and use it all over the place instead of using $_COOKIE directly X-Git-Tag: 1.31.0-rc.0~35668 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=aa7b63ce83d750fae0aea00dc3296a248a24bf17;p=lhc%2Fweb%2Fwiklou.git Cleanup getCookie() and use it all over the place instead of using $_COOKIE directly --- diff --git a/includes/Setup.php b/includes/Setup.php index 133be74125..77d13d40fb 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -305,7 +305,7 @@ if( !wfIniGetBool( 'session.auto_start' ) ) 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; diff --git a/includes/User.php b/includes/User.php index d376da27a1..1edbb9fd5f 100644 --- a/includes/User.php +++ b/includes/User.php @@ -816,7 +816,7 @@ class User { function loadDefaults( $name = false ) { wfProfileIn( __METHOD__ ); - global $wgCookiePrefix; + global $wgRequest; $this->mId = 0; $this->mName = $name; @@ -827,8 +827,8 @@ class User { $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 } @@ -859,7 +859,7 @@ class User { * @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 ) ); @@ -875,8 +875,8 @@ class User { } } - 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 @@ -898,8 +898,8 @@ class User { 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(); @@ -923,8 +923,8 @@ class User { 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 diff --git a/includes/WebRequest.php b/includes/WebRequest.php index c269d19d93..e39a576a7a 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -427,19 +427,19 @@ class WebRequest { * @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; } diff --git a/includes/extauth/vB.php b/includes/extauth/vB.php index 355a7e6854..ac03fa06b4 100644 --- a/includes/extauth/vB.php +++ b/includes/extauth/vB.php @@ -50,13 +50,13 @@ class ExternalUser_vB extends ExternalUser { # 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; } @@ -67,7 +67,7 @@ class ExternalUser_vB extends ExternalUser { $this->getFields(), array( 'session.userid = user.userid', - 'sessionhash' => $_COOKIE["{$prefix}sessionhash"] + 'sessionhash' => $wgRequest->getCookie( 'sessionhash', $prefix ), ), __METHOD__ ); diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index d8d35dd92c..042d05b68d 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -936,7 +936,7 @@ class LoginForm { */ function mainLoginForm( $msg, $msgtype = 'error' ) { global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail; - global $wgCookiePrefix, $wgLoginLanguageSelector; + global $wgRequest, $wgLoginLanguageSelector; global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration; $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); @@ -961,7 +961,7 @@ class LoginForm { if ( $wgUser->isLoggedIn() ) { $this->mName = $wgUser->getName(); } else { - $this->mName = isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : null; + $this->mName = $wgRequest->getCookie( 'UserName' ); } }