Index: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php |
— | — | @@ -27,7 +27,6 @@ |
28 | 28 | global $wgExtMobileFrontend; |
29 | 29 | unset( $wgExtMobileFrontend ); |
30 | 30 | unset( $_SERVER[ 'HTTP_X_DEVICE' ] ); |
31 | | - ExtMobileFrontend::$useFormat = null; |
32 | 31 | parent::tearDown(); |
33 | 32 | } |
34 | 33 | |
— | — | @@ -114,7 +113,7 @@ |
115 | 114 | $testMethod = ( $assert ) ? 'assertTrue' : 'assertFalse'; |
116 | 115 | $url = 'http://en.wikipedia.org/wiki/Article/?something=bananas'; |
117 | 116 | if ( !empty( $useFormat ) ) $url .= "&useformat=" . $useFormat; |
118 | | - ExtMobileFrontend::$useFormat = $useFormat; |
| 117 | + $wgExtMobileFrontend->setUseFormat( $useFormat ); |
119 | 118 | |
120 | 119 | $parsedUrl = wfParseUrl( $url ); |
121 | 120 | |
— | — | @@ -165,7 +164,7 @@ |
166 | 165 | |
167 | 166 | $testMethod = ( $isFauxDevice ) ? 'assertTrue' : 'assertFalse'; |
168 | 167 | |
169 | | - ExtMobileFrontend::$useFormat = $useformat; |
| 168 | + $wgExtMobileFrontend->setUseFormat( $useformat ); |
170 | 169 | $this->$testMethod( $isFauxMobileDevice->invokeArgs( $wgExtMobileFrontend, array() ), $msg ); |
171 | 170 | } |
172 | 171 | |
— | — | @@ -190,7 +189,7 @@ |
191 | 190 | if ( count( $requestVal )) { |
192 | 191 | foreach ( $requestVal as $key => $val ) { |
193 | 192 | if ( $key == 'useformat' ) { |
194 | | - ExtMobileFrontend::$useFormat = $val; |
| 193 | + $wgExtMobileFrontend->setUseFormat( $val ); |
195 | 194 | } else { |
196 | 195 | $wgRequest->setVal( $key, $val ); |
197 | 196 | } |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -20,7 +20,6 @@ |
21 | 21 | public static $format; |
22 | 22 | public static $search; |
23 | 23 | public static $callback; |
24 | | - public static $useFormat; |
25 | 24 | public static $disableImages; |
26 | 25 | public static $enableImages; |
27 | 26 | public static $isMainPage = false; |
— | — | @@ -46,6 +45,8 @@ |
47 | 46 | public static $loginHtml; |
48 | 47 | public static $zeroRatedBanner; |
49 | 48 | |
| 49 | + protected $useFormat; |
| 50 | + |
50 | 51 | /** |
51 | 52 | * @var string xDevice header information |
52 | 53 | */ |
— | — | @@ -350,8 +351,9 @@ |
351 | 352 | // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] |
352 | 353 | |
353 | 354 | $xDevice = $this->getXDevice(); |
354 | | - self::$useFormat = $wgRequest->getText( 'useformat' ); |
355 | | - $this->wmlContext->setUseFormat( self::$useFormat ); |
| 355 | + $this->checkUseFormatCookie(); |
| 356 | + $useFormat = $this->getUseFormat(); |
| 357 | + $this->wmlContext->setUseFormat( $useFormat ); |
356 | 358 | $mobileAction = $this->getMobileAction(); |
357 | 359 | |
358 | 360 | if ( !$this->shouldDisplayMobileView() ) { |
— | — | @@ -1371,12 +1373,12 @@ |
1372 | 1374 | if ( !$this->isFauxMobileDevice() ) { |
1373 | 1375 | return; |
1374 | 1376 | } |
1375 | | - |
| 1377 | + $useFormat = $this->getUseFormat(); |
1376 | 1378 | if ( !isset( $parsedUrl[ 'query' ] )) { |
1377 | | - $parsedUrl[ 'query' ] = 'useformat=' . urlencode( self::$useFormat ); |
| 1379 | + $parsedUrl[ 'query' ] = 'useformat=' . urlencode( $useFormat ); |
1378 | 1380 | } else { |
1379 | 1381 | $query = wfCgiToArray( $parsedUrl[ 'query' ] ); |
1380 | | - $query[ 'useformat' ] = urlencode( self::$useFormat ); |
| 1382 | + $query[ 'useformat' ] = urlencode( $useFormat ); |
1381 | 1383 | $parsedUrl[ 'query' ] = wfArrayToCgi( $query ); |
1382 | 1384 | } |
1383 | 1385 | } |
— | — | @@ -1427,7 +1429,8 @@ |
1428 | 1430 | } |
1429 | 1431 | |
1430 | 1432 | protected function isFauxMobileDevice() { |
1431 | | - if ( self::$useFormat !== 'mobile' && self::$useFormat !== 'mobile-wap') { |
| 1433 | + $useFormat = $this->getUseFormat(); |
| 1434 | + if ( $useFormat !== 'mobile' && $useFormat !== 'mobile-wap') { |
1432 | 1435 | return false; |
1433 | 1436 | } |
1434 | 1437 | |
— | — | @@ -1477,6 +1480,47 @@ |
1478 | 1481 | return $this->action; |
1479 | 1482 | } |
1480 | 1483 | |
| 1484 | + public function getUseFormat() { |
| 1485 | + global $wgRequest; |
| 1486 | + if ( !isset( $this->useFormat ) ) { |
| 1487 | + $useFormat = $wgRequest->getText( 'useformat' ); |
| 1488 | + $this->setUseFormat( $useFormat ); |
| 1489 | + } |
| 1490 | + return $this->useFormat; |
| 1491 | + } |
| 1492 | + |
| 1493 | + public function setUseFormat( $useFormat ) { |
| 1494 | + $this->useFormat = $useFormat; |
| 1495 | + } |
| 1496 | + |
| 1497 | + public function checkUseFormatCookie() { |
| 1498 | + global $wgRequest; |
| 1499 | + |
| 1500 | + $useFormat = $this->getUseFormat(); |
| 1501 | + $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' ); |
| 1502 | + if( !strlen( $useFormat ) && !is_null( $useFormatFromCookie ) ) { |
| 1503 | + $this->setUseFormat( $useFormatFromCookie ); |
| 1504 | + } |
| 1505 | + |
| 1506 | + // if we should not be displaying the mobile view, make sure cookies are unset etc. |
| 1507 | + if ( !$this->shouldDisplayMobileView() ) { |
| 1508 | + // make sure cookie is unset for appropriate mobile actions |
| 1509 | + $mobileAction = $this->getMobileAction(); |
| 1510 | + if ( in_array( $mobileAction, array( 'view_normal_site', 'disable_mobile_site' ) ) ) { |
| 1511 | + $wgRequest->response()->setCookie( 'mf_useformat', false, time() - 3600 ); |
| 1512 | + } |
| 1513 | + |
| 1514 | + // make sure useformat is unset |
| 1515 | + $this->setUseFormat( '' ); |
| 1516 | + return; |
| 1517 | + } |
| 1518 | + |
| 1519 | + // if getUseFormat and no cookie set, set the cookie |
| 1520 | + if ( is_null( $useFormatFromCookie ) && strlen( $useFormat ) ) { |
| 1521 | + $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, 0 ); |
| 1522 | + } |
| 1523 | + } |
| 1524 | + |
1481 | 1525 | public function getVersion() { |
1482 | 1526 | return __CLASS__ . ': $Id$'; |
1483 | 1527 | } |