From 3e74cd1359f4a5d696de32f7e8c36500a4763231 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 11 Feb 2006 07:41:31 +0000 Subject: [PATCH] Allow cookies to be shared between multiple wikis with a shared user database. --- RELEASE-NOTES | 1 + includes/Setup.php | 17 ++++++++++------- includes/SpecialUserlogin.php | 10 ++++++---- includes/User.php | 20 ++++++++++---------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ff954204f4..7d47e9b036 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/Setup.php b/includes/Setup.php index fe4ce1e060..d30be72b44 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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; diff --git a/includes/SpecialUserlogin.php b/includes/SpecialUserlogin.php index 149dcb479c..591fd32d26 100644 --- a/includes/SpecialUserlogin.php +++ b/includes/SpecialUserlogin.php @@ -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']; } } diff --git a/includes/User.php b/includes/User.php index c95e5e89ba..d1861acbce 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 } -- 2.20.1