Allow cookies to be shared between multiple wikis with a shared user database.
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 11 Feb 2006 07:41:31 +0000 (07:41 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 11 Feb 2006 07:41:31 +0000 (07:41 +0000)
RELEASE-NOTES
includes/Setup.php
includes/SpecialUserlogin.php
includes/User.php

index ff95420..7d47e9b 100644 (file)
@@ -608,6 +608,7 @@ fully support the editing toolbar, but was found to be too confusing.
 * (partial bug 3456) Disable auto redirect to Main Page after account creation
 * (bug 4824) Separate out IE7 CSS compat hacks, fix for RTL pages
 * Added support for wikidiff2 and similar external diff engines.
+* Allow cookies to be shared between multiple wikis with a shared user database
 
 
 === Caveats ===
index fe4ce1e..d30be72 100644 (file)
@@ -115,18 +115,21 @@ wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
 wfProfileOut( $fname.'-memcached' );
 wfProfileIn( $fname.'-SetupSession' );
 
+if ( $wgDBprefix ) {
+       $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
+} elseif ( $wgSharedDB ) {
+       $wgCookiePrefix = $wgSharedDB;
+} else {
+       $wgCookiePrefix = $wgDBname;
+}
+
 # If session.auto_start is there, we can't touch session name
 #
-
 if (!ini_get('session.auto_start')) {
-    if ( $wgDBprefix ) {
-       session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
-    } else {
-       session_name( $wgDBname . '_session' );
-    }
+       session_name( $wgCookiePrefix . '_session' );
 }
 
-if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
+if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
        wfIncrStats( 'request_with_session' );
        User::SetupSession();
        $wgSessionStarted = true;
index 149dcb4..591fd32 100644 (file)
@@ -383,7 +383,8 @@ class LoginForm {
         * @access private
         */
        function mailPasswordInternal( $u ) {
-               global $wgDBname, $wgCookiePath, $wgCookieDomain, $wgCookieSecure;
+               global $wgPasswordSender, $wgIP;
+               global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
 
                if ( '' == $u->getEmail() ) {
                        return wfMsg( 'noemail', $u->getName() );
@@ -392,7 +393,7 @@ class LoginForm {
                $np = $u->randomPassword();
                $u->setNewpassword( $np );
 
-               setcookie( "{$wgDBname}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
+               setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 
                $u->saveSettings();
 
@@ -444,14 +445,15 @@ class LoginForm {
         */
        function mainLoginForm( $msg, $msgtype = 'error' ) {
                global $wgUser, $wgOut, $wgLang;
-               global $wgDBname, $wgAllowRealName, $wgEnableEmail;
+               global $wgAllowRealName, $wgEnableEmail;
+               global $wgCookiePrefix;
                global $wgAuth;
 
                if ( '' == $this->mName ) {
                        if ( $wgUser->isLoggedIn() ) {
                                $this->mName = $wgUser->getName();
                        } else {
-                               $this->mName = @$_COOKIE[$wgDBname.'UserName'];
+                               $this->mName = @$_COOKIE[$wgCookiePrefix.'UserName'];
                        }
                }
 
index c95e5e8..d1861ac 100644 (file)
@@ -293,7 +293,7 @@ class User {
                $fname = 'User::loadDefaults' . $n;
                wfProfileIn( $fname );
 
-               global $wgContLang, $wgDBname;
+               global $wgContLang, $wgCookiePrefix;
                global $wgNamespacesToBeSearchedDefault;
 
                $this->mId = 0;
@@ -315,8 +315,8 @@ class User {
                $this->setToken(); # Random
                $this->mHash = false;
 
-               if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
-                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgDBname.'LoggedOut'] );
+               if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
+                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
                }
                else {
                        $this->mTouched = '0'; # Allow any pages to be cached
@@ -617,7 +617,7 @@ class User {
         * @static
         */
        function loadFromSession() {
-               global $wgMemc, $wgDBname;
+               global $wgMemc, $wgDBname, $wgCookiePrefix;
 
                if ( isset( $_SESSION['wsUserID'] ) ) {
                        if ( 0 != $_SESSION['wsUserID'] ) {
@@ -625,16 +625,16 @@ class User {
                        } else {
                                return new User();
                        }
-               } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
-                       $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
+                       $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
                        $_SESSION['wsUserID'] = $sId;
                } else {
                        return new User();
                }
                if ( isset( $_SESSION['wsUserName'] ) ) {
                        $sName = $_SESSION['wsUserName'];
-               } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
-                       $sName = $_COOKIE["{$wgDBname}UserName"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
+                       $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
                        $_SESSION['wsUserName'] = $sName;
                } else {
                        return new User();
@@ -657,8 +657,8 @@ class User {
 
                if ( isset( $_SESSION['wsToken'] ) ) {
                        $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
-               } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
-                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgDBname}Token"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
+                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
                } else {
                        return new User(); # Can't log in from session
                }