Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( &$wgExtMobileFrontend, 'addMobileFooter' ); |
51 | 51 | |
52 | 52 | class ExtMobileFrontend { |
53 | | - const VERSION = '0.5.15'; |
| 53 | + const VERSION = '0.5.16'; |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @var DOMDocument |
— | — | @@ -277,11 +277,11 @@ |
278 | 278 | } |
279 | 279 | |
280 | 280 | if ( $mAction == 'opt_in_cookie' ) { |
281 | | - $wgRequest->response()->setcookie( 'optin', '1' ); |
| 281 | + $this->setOptInOutCookie( '1' ); |
282 | 282 | } |
283 | 283 | |
284 | 284 | if ( $mAction == 'opt_out_cookie' ) { |
285 | | - $wgRequest->response()->setcookie( 'optin', '' ); |
| 285 | + $this->setOptInOutCookie( '' ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Note: Temporarily disabling this section for trial deployment |
— | — | @@ -332,6 +332,26 @@ |
333 | 333 | |
334 | 334 | return true; |
335 | 335 | } |
| 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 | + } |
336 | 356 | |
337 | 357 | private function disableCaching() { |
338 | 358 | if ( isset( $_SERVER['HTTP_VIA'] ) && |