r94261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94260‎ | r94261 | r94262 >
Date:17:44, 11 August 2011
Author:preilly
Status:ok
Tags:
Comment:
add Opt-In and Opt-Out base domain cookie support
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -49,7 +49,7 @@
5050 $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' );
5151
5252 class ExtMobileFrontend {
53 - const VERSION = '0.5.15';
 53+ const VERSION = '0.5.16';
5454
5555 /**
5656 * @var DOMDocument
@@ -277,11 +277,11 @@
278278 }
279279
280280 if ( $mAction == 'opt_in_cookie' ) {
281 - $wgRequest->response()->setcookie( 'optin', '1' );
 281+ $this->setOptInOutCookie( '1' );
282282 }
283283
284284 if ( $mAction == 'opt_out_cookie' ) {
285 - $wgRequest->response()->setcookie( 'optin', '' );
 285+ $this->setOptInOutCookie( '' );
286286 }
287287
288288 // Note: Temporarily disabling this section for trial deployment
@@ -332,6 +332,26 @@
333333
334334 return true;
335335 }
 336+
 337+ private function setOptInOutCookie( $value ) {
 338+ global $wgCookieDomain;
 339+ $tempWgCookieDomain = $wgCookieDomain;
 340+ $wgCookieDomain = $this->getBaseDomain();
 341+ $wgRequest->response()->setcookie( 'optin', $value );
 342+ $wgCookieDomain = $tempWgCookieDomain;
 343+ }
 344+
 345+ private function getBaseDomain() {
 346+ //Validates value as IP address
 347+ if( !filter_var( $_SERVER['HTTP_HOST'], FILTER_VALIDATE_IP ) ) {
 348+ $domainParts = explode( '.', $_SERVER['HTTP_HOST'] );
 349+ $domainParts = array_reverse( $domainParts );
 350+ //Although some browsers will accept cookies without the initial ., » RFC 2109 requires it to be included.
 351+ return '.' . $domainParts[1] . '.' . $domainParts[0];
 352+ } else {
 353+ return $_SERVER['HTTP_HOST'];
 354+ }
 355+ }
336356
337357 private function disableCaching() {
338358 if ( isset( $_SERVER['HTTP_VIA'] ) &&

Status & tagging log