http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94262
Revision: 94262
Author: preilly
Date: 2011-08-11 17:50:34 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
add Opt-In and Opt-Out base domain cookie support
Modified Paths:
--------------
branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
Modified: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
===================================================================
--- branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
2011-08-11 17:44:59 UTC (rev 94261)
+++ branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php
2011-08-11 17:50:34 UTC (rev 94262)
@@ -49,7 +49,7 @@
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend,
'addMobileFooter' );
class ExtMobileFrontend {
- const VERSION = '0.5.15';
+ const VERSION = '0.5.16';
/**
* @var DOMDocument
@@ -277,11 +277,11 @@
}
if ( $mAction == 'opt_in_cookie' ) {
- $wgRequest->response()->setcookie( 'optin', '1' );
+ $this->setOptInOutCookie( '1' );
}
if ( $mAction == 'opt_out_cookie' ) {
- $wgRequest->response()->setcookie( 'optin', '' );
+ $this->setOptInOutCookie( '' );
}
// Note: Temporarily disabling this section for trial deployment
@@ -332,6 +332,26 @@
return true;
}
+
+ private function setOptInOutCookie( $value ) {
+ global $wgCookieDomain;
+ $tempWgCookieDomain = $wgCookieDomain;
+ $wgCookieDomain = $this->getBaseDomain();
+ $wgRequest->response()->setcookie( 'optin', $value );
+ $wgCookieDomain = $tempWgCookieDomain;
+ }
+
+ private function getBaseDomain() {
+ //Validates value as IP address
+ if( !filter_var( $_SERVER['HTTP_HOST'], FILTER_VALIDATE_IP ) ) {
+ $domainParts = explode( '.', $_SERVER['HTTP_HOST'] );
+ $domainParts = array_reverse( $domainParts );
+ //Although some browsers will accept cookies without
the initial ., ยป RFC 2109 requires it to be included.
+ return '.' . $domainParts[1] . '.' . $domainParts[0];
+ } else {
+ return $_SERVER['HTTP_HOST'];
+ }
+ }
private function disableCaching() {
if ( isset( $_SERVER['HTTP_VIA'] ) &&
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs