r12997 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12996‎ | r12997 | r12998 >
Date:07:41, 11 February 2006
Author:timstarling
Status:old
Tags:
Comment:
Allow cookies to be shared between multiple wikis with a shared user database.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -293,7 +293,7 @@
294294 $fname = 'User::loadDefaults' . $n;
295295 wfProfileIn( $fname );
296296
297 - global $wgContLang, $wgDBname;
 297+ global $wgContLang, $wgCookiePrefix;
298298 global $wgNamespacesToBeSearchedDefault;
299299
300300 $this->mId = 0;
@@ -315,8 +315,8 @@
316316 $this->setToken(); # Random
317317 $this->mHash = false;
318318
319 - if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
320 - $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgDBname.'LoggedOut'] );
 319+ if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
 320+ $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
321321 }
322322 else {
323323 $this->mTouched = '0'; # Allow any pages to be cached
@@ -617,7 +617,7 @@
618618 * @static
619619 */
620620 function loadFromSession() {
621 - global $wgMemc, $wgDBname;
 621+ global $wgMemc, $wgDBname, $wgCookiePrefix;
622622
623623 if ( isset( $_SESSION['wsUserID'] ) ) {
624624 if ( 0 != $_SESSION['wsUserID'] ) {
@@ -625,16 +625,16 @@
626626 } else {
627627 return new User();
628628 }
629 - } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
630 - $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
 629+ } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
 630+ $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
631631 $_SESSION['wsUserID'] = $sId;
632632 } else {
633633 return new User();
634634 }
635635 if ( isset( $_SESSION['wsUserName'] ) ) {
636636 $sName = $_SESSION['wsUserName'];
637 - } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
638 - $sName = $_COOKIE["{$wgDBname}UserName"];
 637+ } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
 638+ $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
639639 $_SESSION['wsUserName'] = $sName;
640640 } else {
641641 return new User();
@@ -657,8 +657,8 @@
658658
659659 if ( isset( $_SESSION['wsToken'] ) ) {
660660 $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
661 - } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
662 - $passwordCorrect = $user->mToken == $_COOKIE["{$wgDBname}Token"];
 661+ } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
 662+ $passwordCorrect = $user->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
663663 } else {
664664 return new User(); # Can't log in from session
665665 }
Index: trunk/phase3/includes/SpecialUserlogin.php
@@ -383,7 +383,8 @@
384384 * @access private
385385 */
386386 function mailPasswordInternal( $u ) {
387 - global $wgDBname, $wgCookiePath, $wgCookieDomain, $wgCookieSecure;
 387+ global $wgPasswordSender, $wgIP;
 388+ global $wgCookiePath, $wgCookieDomain, $wgCookiePrefix, $wgCookieSecure;
388389
389390 if ( '' == $u->getEmail() ) {
390391 return wfMsg( 'noemail', $u->getName() );
@@ -392,7 +393,7 @@
393394 $np = $u->randomPassword();
394395 $u->setNewpassword( $np );
395396
396 - setcookie( "{$wgDBname}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 397+ setcookie( "{$wgCookiePrefix}Token", '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
397398
398399 $u->saveSettings();
399400
@@ -444,14 +445,15 @@
445446 */
446447 function mainLoginForm( $msg, $msgtype = 'error' ) {
447448 global $wgUser, $wgOut, $wgLang;
448 - global $wgDBname, $wgAllowRealName, $wgEnableEmail;
 449+ global $wgAllowRealName, $wgEnableEmail;
 450+ global $wgCookiePrefix;
449451 global $wgAuth;
450452
451453 if ( '' == $this->mName ) {
452454 if ( $wgUser->isLoggedIn() ) {
453455 $this->mName = $wgUser->getName();
454456 } else {
455 - $this->mName = @$_COOKIE[$wgDBname.'UserName'];
 457+ $this->mName = @$_COOKIE[$wgCookiePrefix.'UserName'];
456458 }
457459 }
458460
Index: trunk/phase3/includes/Setup.php
@@ -115,18 +115,21 @@
116116 wfProfileOut( $fname.'-memcached' );
117117 wfProfileIn( $fname.'-SetupSession' );
118118
 119+if ( $wgDBprefix ) {
 120+ $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
 121+} elseif ( $wgSharedDB ) {
 122+ $wgCookiePrefix = $wgSharedDB;
 123+} else {
 124+ $wgCookiePrefix = $wgDBname;
 125+}
 126+
119127 # If session.auto_start is there, we can't touch session name
120128 #
121 -
122129 if (!ini_get('session.auto_start')) {
123 - if ( $wgDBprefix ) {
124 - session_name( $wgDBname . '_' . $wgDBprefix . '_session' );
125 - } else {
126 - session_name( $wgDBname . '_session' );
127 - }
 130+ session_name( $wgCookiePrefix . '_session' );
128131 }
129132
130 -if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
 133+if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
131134 wfIncrStats( 'request_with_session' );
132135 User::SetupSession();
133136 $wgSessionStarted = true;
Index: trunk/phase3/RELEASE-NOTES
@@ -608,6 +608,7 @@
609609 * (partial bug 3456) Disable auto redirect to Main Page after account creation
610610 * (bug 4824) Separate out IE7 CSS compat hacks, fix for RTL pages
611611 * Added support for wikidiff2 and similar external diff engines.
 612+* Allow cookies to be shared between multiple wikis with a shared user database
612613
613614
614615 === Caveats ===

Status & tagging log