r101878 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101877‎ | r101878 | r101879 >
Date:20:54, 3 November 2011
Author:khorn
Status:ok
Tags:
Comment:
Fix: The squid log caching and the sessions were fighting eachother. Now, they should play nice long with eachother long enough to get that first pageload in, so long as the user has no mediawiki_session cookie set, and no pre-existing session.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/DonationData.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -241,16 +241,24 @@
242242 * @return boolean true if match, else false.
243243 */
244244 public function checkTokens() {
245 - $checkResult = $this->dataObj->token_checkTokens();
 245+ if ( !$this->posted ) {
 246+ //we don't care, because we can't possibly have a good one at this
 247+ //point.
 248+ //Additional: If we try for this before we're posted, the squid log
 249+ //caching won't work.
 250+ return true;
 251+ } else {
 252+ $checkResult = $this->dataObj->token_checkTokens();
246253
247 - if ( $checkResult ) {
248 - $this->debugarray[] = 'Token Match';
249 - } else {
250 - $this->debugarray[] = 'Token MISMATCH';
 254+ if ( $checkResult ) {
 255+ $this->debugarray[] = 'Token Match';
 256+ } else {
 257+ $this->debugarray[] = 'Token MISMATCH';
 258+ }
 259+
 260+ $this->refreshGatewayValueFromSource( 'token' );
 261+ return $checkResult;
251262 }
252 -
253 - $this->refreshGatewayValueFromSource( 'token' );
254 - return $checkResult;
255263 }
256264
257265 /**
Index: trunk/extensions/DonationInterface/gateway_common/DonationData.php
@@ -105,7 +105,7 @@
106106
107107 //if we have saved any donation data to the session, pull them in as well.
108108 $this->integrateDataFromSession();
109 -
 109+
110110 $this->doCacheStuff();
111111
112112 $this->normalizeAndSanitize();
@@ -118,8 +118,7 @@
119119 * are populated, and merge that with the data set we already have.
120120 */
121121 function integrateDataFromSession(){
122 - self::ensureSession();
123 - if ( array_key_exists( 'Donor', $_SESSION ) ) {
 122+ if ( self::sessionExists() && array_key_exists( 'Donor', $_SESSION ) ) {
124123 //if the thing coming in from the session isn't already something,
125124 //replace it.
126125 //if it is: assume that the session data was meant to be replaced
@@ -431,6 +430,16 @@
432431 }
433432 }
434433
 434+ /**
 435+ * This function sets the token to the string 'cache' if we're caching, and
 436+ * then sets the s-maxage header to whatever you specify for the SMaxAge.
 437+ * NOTES: The bit where we setSquidMaxage will not work at all, under two
 438+ * conditions:
 439+ * The user has a session ID.
 440+ * The mediawiki_session cookie is set in the user's browser.
 441+ * @global bool $wgUseSquid
 442+ * @global type $wgOut
 443+ */
435444 function doCacheStuff() {
436445 //TODO: Wow, name.
437446 // if _cache_ is requested by the user, do not set a session/token; dynamic data will be loaded via ajax
@@ -441,7 +450,7 @@
442451 // if we have squid caching enabled, set the maxage
443452 global $wgUseSquid, $wgOut;
444453 $maxAge = $this->getGatewayGlobal( 'SMaxAge' );
445 -
 454+
446455 if ( $wgUseSquid && ( $maxAge !== false ) ) {
447456 self::log( $this->getAnnoyingOrderIDLogLinePrefix() . ' Setting s-max-age: ' . $maxAge, LOG_DEBUG );
448457 $wgOut->setSquidMaxage( $maxAge );
@@ -545,12 +554,22 @@
546555 */
547556 public static function ensureSession() {
548557 // if the session is already started, do nothing
549 - if ( session_id() )
 558+ if ( self::sessionExists() )
550559 return;
551560
552561 // otherwise, fire it up using global mw function wfSetupSession
553562 wfSetupSession();
554563 }
 564+
 565+ /**
 566+ * Checks to see if the session exists without actually creating one.
 567+ * @return bool true if we have a session, otherwise false.
 568+ */
 569+ public static function sessionExists() {
 570+ if ( session_id() )
 571+ return true;
 572+ return false;
 573+ }
555574
556575 public function token_checkTokens() {
557576 global $wgRequest;

Follow-up revisions

RevisionCommit summaryAuthorDate
r101886MFT r101878awjrichards21:48, 3 November 2011
r102836Bugfix for the session tokens and caching: The token was being handed out one...khorn01:12, 12 November 2011

Status & tagging log