r1890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1889‎ | r1890 | r1891 >
Date:02:50, 6 November 2003
Author:vibber
Status:old
Tags:
Comment:
Semi-experimental support for sessions in Memcached
Modified paths:
  • /branches/stable/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/stable/phase3/includes/MemcachedSessions.php (added) (history)
  • /branches/stable/phase3/includes/Setup.php (modified) (history)
  • /branches/stable/phase3/includes/SpecialUserlogin.php (modified) (history)
  • /branches/stable/phase3/includes/User.php (modified) (history)
  • /branches/stable/phase3/wiki.phtml (modified) (history)

Diff [purge]

Index: branches/stable/phase3/wiki.phtml
@@ -3,13 +3,6 @@
44 #
55 $wgRequestTime = microtime();
66
7 -session_cache_limiter( "private, must-revalidate" );
8 -session_start();
9 -session_register( "wsUserID" );
10 -session_register( "wsUserName" );
11 -session_register( "wsUserPassword" );
12 -session_register( "wsUploadFiles" );
13 -
147 global $IP;
158 include_once( "./LocalSettings.php" );
169 include_once( "$IP/Setup.php" );
Index: branches/stable/phase3/includes/User.php
@@ -446,20 +446,20 @@
447447 function setCookies()
448448 {
449449 global $wsUserID, $wsUserName, $wsUserPassword;
450 - global $wgCookieExpiration;
 450+ global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain;
451451 if ( 0 == $this->mId ) return;
452452 $this->loadFromDatabase();
453453 $exp = time() + $wgCookieExpiration;
454454
455455 $wsUserID = $this->mId;
456 - setcookie( "wcUserID", $this->mId, $exp, "/" );
 456+ setcookie( "wcUserID", $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
457457
458458 $wsUserName = $this->mName;
459 - setcookie( "wcUserName", $this->mName, $exp, "/" );
 459+ setcookie( "wcUserName", $this->mName, $exp, $wgCookiePath, $wgCookieDomain );
460460
461461 $wsUserPassword = $this->mPassword;
462462 if ( 1 == $this->getOption( "rememberpassword" ) ) {
463 - setcookie( "wcUserPassword", $this->mCookiePassword, $exp, "/" );
 463+ setcookie( "wcUserPassword", $this->mCookiePassword, $exp, $wgCookiePath, $wgCookieDomain );
464464 } else {
465465 setcookie( "wcUserPassword", "", time() - 3600 );
466466 }
@@ -467,13 +467,13 @@
468468
469469 function logout()
470470 {
471 - global $wsUserID;
 471+ global $wsUserID, $wgCookiePath, $wgCookieDomain;
472472 $this->mId = 0;
473473
474474 $wsUserID = 0;
475475
476 - setcookie( "wcUserID", "", time() - 3600 );
477 - setcookie( "wcUserPassword", "", time() - 3600 );
 476+ setcookie( "wcUserID", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
 477+ setcookie( "wcUserPassword", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
478478 }
479479
480480 function saveSettings()
Index: branches/stable/phase3/includes/DefaultSettings.php
@@ -43,6 +43,7 @@
4444 $wgUseMemCached = false;
4545 $wgMemCachedServers = array( "127.0.0.1:11000" );
4646 $wgMemCachedDebug = false;
 47+$wgSessionsInMemcached = false;
4748
4849 # Language settings
4950 #
@@ -94,6 +95,11 @@
9596
9697 $wgCookieExpiration = 2592000;
9798
 99+# Set to set an explicit domain on the login cookies
 100+# eg, "justthis.domain.org" or ".any.subdomain.net"
 101+$wgCookieDomain = "";
 102+$wgCookiePath = "/";
 103+
98104 $wgAllowExternalImages = true;
99105 $wgMiserMode = false; # Disable database-intensive features
100106 $wgUseTeX = false;
Index: branches/stable/phase3/includes/SpecialUserlogin.php
@@ -103,7 +103,8 @@
104104 /* private */ function mailPassword()
105105 {
106106 global $wgUser, $wpName, $wgDeferredUpdateList, $wgOutputEncoding;
107 -
 107+ global $wgCookiePath, $wgCookieDomain;
 108+
108109 if ( "" == $wpName ) {
109110 mainLoginForm( wfMsg( "noname" ) );
110111 return;
@@ -126,7 +127,7 @@
127128 $np = User::randomPassword();
128129 $u->setNewpassword( $np );
129130
130 - setcookie( "wcUserPassword", "", time() - 3600 );
 131+ setcookie( "wcUserPassword", "", time() - 3600, $wgCookiePath, $wgCookieDomain );
131132 $u->saveSettings();
132133
133134 $ip = getenv( "REMOTE_ADDR" );
Index: branches/stable/phase3/includes/Setup.php
@@ -45,6 +45,17 @@
4646 }
4747 $wgLang = new $wgLangClass();
4848
 49+if( $wgSessionsInMemcached ) {
 50+ include_once( "$IP/MemcachedSessions.php" );
 51+}
 52+session_set_cookie_params( 3600, $wgCookiePath, $wgCookieDomain );
 53+session_cache_limiter( "private, must-revalidate" );
 54+session_start();
 55+session_register( "wsUserID" );
 56+session_register( "wsUserName" );
 57+session_register( "wsUserPassword" );
 58+session_register( "wsUploadFiles" );
 59+
4960 $wgUser = User::loadFromSession();
5061 $wgDeferredUpdateList = array();
5162 $wgLinkCache = new LinkCache();
Index: branches/stable/phase3/includes/MemcachedSessions.php
@@ -0,0 +1,54 @@
 2+<?
 3+
 4+/*
 5+ This file gets included if $wgSessionsInMemcache is set in the config.
 6+ It redirects session handling functions to store their data in memcached
 7+ instead of the local filesystem. Depending on circumstances, it may also
 8+ be necessary to change the cookie settings to work across hostnames.
 9+
 10+ See: http://www.php.net/manual/en/function.session-set-save-handler.php
 11+*/
 12+
 13+
 14+function memsess_key( $id ) {
 15+ global $wgDBname;
 16+ return "$wgDBname:session:$id";
 17+}
 18+
 19+function memsess_open( $save_path, $session_name ) {
 20+ # NOP, $wgMemc should be set up already
 21+ return true;
 22+}
 23+
 24+function memsess_close() {
 25+ # NOP
 26+ return true;
 27+}
 28+
 29+function memsess_read( $id ) {
 30+ global $wgMemc;
 31+ $data = $wgMemc->get( memsess_key( $id ) );
 32+ if( $data === FALSE ) return "";
 33+ return $data;
 34+}
 35+
 36+function memsess_write( $id, $data ) {
 37+ global $wgMemc;
 38+ $wgMemc->set( memsess_key( $id ), $data, 3600 );
 39+ return true;
 40+}
 41+
 42+function memsess_destroy( $id ) {
 43+ global $wgMemc;
 44+ $wgMemc->delete( memsess_key( $id ) );
 45+ return true;
 46+}
 47+
 48+function memsess_gc( $maxlifetime ) {
 49+ # NOP: Memcached performs garbage collection.
 50+ return true;
 51+}
 52+
 53+session_set_save_handler( "memsess_open", "memsess_close", "memsess_read", "memsess_write", "memsess_destroy", "memsess_gc" );
 54+
 55+?>
Property changes on: branches/stable/phase3/includes/MemcachedSessions.php
___________________________________________________________________
Name: svn:eol-style
156 + native
Name: svn:keywords
257 + Author Date Id Revision

Status & tagging log