Cleanup getCookie() and use it all over the place instead of using $_COOKIE directly
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 6 Aug 2010 15:00:43 +0000 (15:00 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 6 Aug 2010 15:00:43 +0000 (15:00 +0000)
includes/Setup.php
includes/User.php
includes/WebRequest.php
includes/extauth/vB.php
includes/specials/SpecialUserlogin.php

index 133be74..77d13d4 100644 (file)
@@ -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;
index d376da2..1edbb9f 100644 (file)
@@ -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
index c269d19..e39a576 100644 (file)
@@ -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;
                }
index 355a7e6..ac03fa0 100644 (file)
@@ -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__
                );
index d8d35dd..042d05b 100644 (file)
@@ -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' );
                        }
                }