* Clean up session checks to better handle the case where the session was
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 5 Feb 2007 21:42:48 +0000 (21:42 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 5 Feb 2007 21:42:48 +0000 (21:42 +0000)
  opened during the current request. May help with some caching corner
  cases.

RELEASE-NOTES
includes/LoadBalancer.php
includes/OutputPage.php
includes/RawPage.php
includes/Setup.php
includes/Skin.php
includes/SkinTemplate.php
includes/SpecialUserlogin.php
includes/WebRequest.php
includes/Wiki.php

index e57f417..8b84ab5 100644 (file)
@@ -175,6 +175,9 @@ lighter making things easier to read.
 * Use faster AlphabeticPager for Special:Categories
 * (bug 8875) Show printable link in MonoBook sidebar for locally nonexistent
   pages; perhaps useful for categories and shared images
+* Clean up session checks to better handle the case where the session was
+  opened during the current request. May help with some caching corner
+  cases.
 
 
 == Languages updated ==
index f256b7e..d3d072e 100644 (file)
@@ -502,8 +502,7 @@ class LoadBalancer {
         * Save master pos to the session and to memcached, if the session exists
         */
        function saveMasterPos() {
-               global $wgSessionStarted;
-               if ( $wgSessionStarted && count( $this->mServers ) > 1 ) {
+               if ( session_id() != '' && count( $this->mServers ) > 1 ) {
                        # If this entire request was served from a slave without opening a connection to the
                        # master (however unlikely that may be), then we can fetch the position from the slave.
                        if ( empty( $this->mConnections[0] ) ) {
index e72e570..3fcef0f 100644 (file)
@@ -489,7 +489,7 @@ class OutputPage {
                # maintain different caches for logged-in users and non-logged in ones
                $wgRequest->response()->header( 'Vary: Accept-Encoding, Cookie' );
                if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache ) {
-                       if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
+                       if( $wgUseSquid && session_id() == '' &&
                          ! $this->isPrintable() && $this->mSquidMaxage != 0 )
                        {
                                if ( $wgUseESI ) {
index 4353e94..0813018 100644 (file)
@@ -20,7 +20,6 @@ class RawPage {
 
        function __construct( &$article, $request = false ) {
                global $wgRequest, $wgInputEncoding, $wgSquidMaxage, $wgJsMimeType;
-               global $wgUser;
 
                $allowedCTypes = array('text/x-wiki', $wgJsMimeType, 'text/css', 'application/x-zope-edit');
                $this->mArticle =& $article;
@@ -83,8 +82,7 @@ class RawPage {
                
                // Output may contain user-specific data; vary for open sessions
                $this->mPrivateCache = ( $this->mSmaxage == 0 ) ||
-                       ( isset( $_COOKIE[ini_get( 'session.name' )] ) ||
-                       $wgUser->isLoggedIn() );
+                       ( session_id() != '' );
                
                if ( $ctype == '' or ! in_array( $ctype, $allowedCTypes ) ) {
                        $this->mContentType = 'text/x-wiki';
index 6ed7c8d..eaffbe1 100644 (file)
@@ -139,7 +139,7 @@ if ( $wgDBprefix ) {
 if( !ini_get( 'session.auto_start' ) )
        session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
 
-if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
+if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
        wfIncrStats( 'request_with_session' );
        wfSetupSession();
        $wgSessionStarted = true;
index 317097e..09099e8 100644 (file)
@@ -845,14 +845,22 @@ END;
                return $subpages;
        }
 
+       /**
+        * Returns true if the IP should be shown in the header
+        */
+       function showIPinHeader() {
+               global $wgShowIPinHeader;
+               return $wgShowIPinHeader && session_id() != '';
+       }
+
        function nameAndLogin() {
-               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
+               global $wgUser, $wgTitle, $wgLang, $wgContLang;
 
                $lo = $wgContLang->specialPage( 'Userlogout' );
 
                $s = '';
                if ( $wgUser->isAnon() ) {
-                       if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
+                       if( $this->showIPinHeader() ) {
                                $n = wfGetIP();
 
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
index ee3daec..382ac1f 100644 (file)
@@ -488,7 +488,7 @@ class SkinTemplate extends Skin {
         * @private
         */
        function buildPersonalUrls() {
-               global $wgTitle, $wgShowIPinHeader;
+               global $wgTitle;
 
                $fname = 'SkinTemplate::buildPersonalUrls';
                $pageurl = $wgTitle->getLocalURL();
@@ -538,7 +538,7 @@ class SkinTemplate extends Skin {
                                'active' => false
                        );
                } else {
-                       if( $wgShowIPinHeader && isset(  $_COOKIE[ini_get("session.name")] ) ) {
+                       if( $this->showIPinHeader() ) {
                                $href = &$this->userpageUrlDetails['href'];
                                $personal_urls['anonuserpage'] = array(
                                        'text' => $this->username,
@@ -574,14 +574,6 @@ class SkinTemplate extends Skin {
                return $personal_urls;
        }
 
-       /**
-        * Returns true if the IP should be shown in the header
-        */
-       function showIPinHeader() {
-               global $wgShowIPinHeader;
-               return $wgShowIPinHeader && isset(  $_COOKIE[ini_get("session.name")] );
-       }
-
        function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
                $classes = array();
                if( $selected ) {
index f14eede..8b652aa 100644 (file)
@@ -10,7 +10,7 @@
 function wfSpecialUserlogin() {
        global $wgCommandLineMode;
        global $wgRequest;
-       if( !$wgCommandLineMode && !isset( $_COOKIE[session_name()] )  ) {
+       if( session_id() == '' ) {
                wfSetupSession();
        }
 
@@ -707,11 +707,17 @@ class LoginForm {
        }
 
        /**
+        * Check if a session cookie is present.
+        *
+        * This will not pick up a cookie set during _this_ request, but is
+        * meant to ensure that the client is returning the cookie which was
+        * set on a previous pass through the system.
+        *
         * @private
         */
        function hasSessionCookie() {
-               global $wgDisableCookieCheck;
-               return ( $wgDisableCookieCheck ) ? true : ( isset( $_COOKIE[session_name()] ) );
+               global $wgDisableCookieCheck, $wgRequest;
+               return $wgDisableCookieCheck ? true : $wgRequest->checkSessionCookie();
        }
 
        /**
index 8dfc846..b08fd4e 100644 (file)
@@ -301,10 +301,15 @@ class WebRequest {
         * Returns true if there is a session cookie set.
         * This does not necessarily mean that the user is logged in!
         *
+        * If you want to check for an open session, use session_id()
+        * instead; that will also tell you if the session was opened
+        * during the current request (in which case the cookie will
+        * be sent back to the client at the end of the script run).
+        *
         * @return bool
         */
        function checkSessionCookie() {
-               return isset( $_COOKIE[ini_get('session.name')] );
+               return isset( $_COOKIE[session_name()] );
        }
 
        /**
index e5849a1..85963f5 100644 (file)
@@ -399,9 +399,9 @@ class MediaWiki {
                                showCreditsPage( $article );
                                break;
                        case 'submit':
-                               if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
+                               if( session_id() == '' ) {
                                        /* Send a cookie so anons get talk message notifications */
-                                       User::SetupSession();
+                                       wfSetupSession();
                                }
                                /* Continue... */
                        case 'edit':