http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70571

Revision: 70571
Author:   demon
Date:     2010-08-06 15:00:43 +0000 (Fri, 06 Aug 2010)

Log Message:
-----------
Cleanup getCookie() and use it all over the place instead of using $_COOKIE 
directly

Modified Paths:
--------------
    trunk/phase3/includes/Setup.php
    trunk/phase3/includes/User.php
    trunk/phase3/includes/WebRequest.php
    trunk/phase3/includes/extauth/vB.php
    trunk/phase3/includes/specials/SpecialUserlogin.php

Modified: trunk/phase3/includes/Setup.php
===================================================================
--- trunk/phase3/includes/Setup.php     2010-08-06 14:51:16 UTC (rev 70570)
+++ trunk/phase3/includes/Setup.php     2010-08-06 15:00:43 UTC (rev 70571)
@@ -305,7 +305,7 @@
        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;

Modified: trunk/phase3/includes/User.php
===================================================================
--- trunk/phase3/includes/User.php      2010-08-06 14:51:16 UTC (rev 70570)
+++ trunk/phase3/includes/User.php      2010-08-06 15:00:43 UTC (rev 70571)
@@ -816,7 +816,7 @@
        function loadDefaults( $name = false ) {
                wfProfileIn( __METHOD__ );
 
-               global $wgCookiePrefix;
+               global $wgRequest;
 
                $this->mId = 0;
                $this->mName = $name;
@@ -827,8 +827,8 @@
                $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 @@
         * @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 @@
                        }
                }
 
-               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 @@
 
                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 @@
                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

Modified: trunk/phase3/includes/WebRequest.php
===================================================================
--- trunk/phase3/includes/WebRequest.php        2010-08-06 14:51:16 UTC (rev 
70570)
+++ trunk/phase3/includes/WebRequest.php        2010-08-06 15:00:43 UTC (rev 
70571)
@@ -427,19 +427,19 @@
         * @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 $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
-        * @param $prefix String: a prefix to use for the cookie name, if not 
$wgCookiePrefix
         * @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;
                }

Modified: trunk/phase3/includes/extauth/vB.php
===================================================================
--- trunk/phase3/includes/extauth/vB.php        2010-08-06 14:51:16 UTC (rev 
70570)
+++ trunk/phase3/includes/extauth/vB.php        2010-08-06 15:00:43 UTC (rev 
70571)
@@ -50,13 +50,13 @@
                # 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 @@
                        $this->getFields(),
                        array(
                                'session.userid = user.userid',
-                               'sessionhash' => 
$_COOKIE["{$prefix}sessionhash"]
+                               'sessionhash' => $wgRequest->getCookie( 
'sessionhash', $prefix ),
                        ),
                        __METHOD__
                );

Modified: trunk/phase3/includes/specials/SpecialUserlogin.php
===================================================================
--- trunk/phase3/includes/specials/SpecialUserlogin.php 2010-08-06 14:51:16 UTC 
(rev 70570)
+++ trunk/phase3/includes/specials/SpecialUserlogin.php 2010-08-06 15:00:43 UTC 
(rev 70571)
@@ -936,7 +936,7 @@
         */
        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 @@
                        if ( $wgUser->isLoggedIn() ) {
                                $this->mName = $wgUser->getName();
                        } else {
-                               $this->mName = isset( 
$_COOKIE[$wgCookiePrefix.'UserName'] ) ? $_COOKIE[$wgCookiePrefix.'UserName'] : 
null;
+                               $this->mName = $wgRequest->getCookie( 
'UserName' );
                        }
                }
 



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to