r113439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113438‎ | r113439 | r113440 >
Date:00:40, 9 March 2012
Author:awjrichards
Status:resolved (Comments)
Tags:
Comment:
Makes useformat=mobile sticky with a cookie. Changese ExtMobileFrontend::useFormat to protected var accessible with get/set methods. Updated tests to reflect changes
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.body.php (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
@@ -27,7 +27,6 @@
2828 global $wgExtMobileFrontend;
2929 unset( $wgExtMobileFrontend );
3030 unset( $_SERVER[ 'HTTP_X_DEVICE' ] );
31 - ExtMobileFrontend::$useFormat = null;
3231 parent::tearDown();
3332 }
3433
@@ -114,7 +113,7 @@
115114 $testMethod = ( $assert ) ? 'assertTrue' : 'assertFalse';
116115 $url = 'http://en.wikipedia.org/wiki/Article/?something=bananas';
117116 if ( !empty( $useFormat ) ) $url .= "&useformat=" . $useFormat;
118 - ExtMobileFrontend::$useFormat = $useFormat;
 117+ $wgExtMobileFrontend->setUseFormat( $useFormat );
119118
120119 $parsedUrl = wfParseUrl( $url );
121120
@@ -165,7 +164,7 @@
166165
167166 $testMethod = ( $isFauxDevice ) ? 'assertTrue' : 'assertFalse';
168167
169 - ExtMobileFrontend::$useFormat = $useformat;
 168+ $wgExtMobileFrontend->setUseFormat( $useformat );
170169 $this->$testMethod( $isFauxMobileDevice->invokeArgs( $wgExtMobileFrontend, array() ), $msg );
171170 }
172171
@@ -190,7 +189,7 @@
191190 if ( count( $requestVal )) {
192191 foreach ( $requestVal as $key => $val ) {
193192 if ( $key == 'useformat' ) {
194 - ExtMobileFrontend::$useFormat = $val;
 193+ $wgExtMobileFrontend->setUseFormat( $val );
195194 } else {
196195 $wgRequest->setVal( $key, $val );
197196 }
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php
@@ -20,7 +20,6 @@
2121 public static $format;
2222 public static $search;
2323 public static $callback;
24 - public static $useFormat;
2524 public static $disableImages;
2625 public static $enableImages;
2726 public static $isMainPage = false;
@@ -46,6 +45,8 @@
4746 public static $loginHtml;
4847 public static $zeroRatedBanner;
4948
 49+ protected $useFormat;
 50+
5051 /**
5152 * @var string xDevice header information
5253 */
@@ -350,8 +351,9 @@
351352 // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104]
352353
353354 $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 );
356358 $mobileAction = $this->getMobileAction();
357359
358360 if ( !$this->shouldDisplayMobileView() ) {
@@ -1371,12 +1373,12 @@
13721374 if ( !$this->isFauxMobileDevice() ) {
13731375 return;
13741376 }
1375 -
 1377+ $useFormat = $this->getUseFormat();
13761378 if ( !isset( $parsedUrl[ 'query' ] )) {
1377 - $parsedUrl[ 'query' ] = 'useformat=' . urlencode( self::$useFormat );
 1379+ $parsedUrl[ 'query' ] = 'useformat=' . urlencode( $useFormat );
13781380 } else {
13791381 $query = wfCgiToArray( $parsedUrl[ 'query' ] );
1380 - $query[ 'useformat' ] = urlencode( self::$useFormat );
 1382+ $query[ 'useformat' ] = urlencode( $useFormat );
13811383 $parsedUrl[ 'query' ] = wfArrayToCgi( $query );
13821384 }
13831385 }
@@ -1427,7 +1429,8 @@
14281430 }
14291431
14301432 protected function isFauxMobileDevice() {
1431 - if ( self::$useFormat !== 'mobile' && self::$useFormat !== 'mobile-wap') {
 1433+ $useFormat = $this->getUseFormat();
 1434+ if ( $useFormat !== 'mobile' && $useFormat !== 'mobile-wap') {
14321435 return false;
14331436 }
14341437
@@ -1477,6 +1480,47 @@
14781481 return $this->action;
14791482 }
14801483
 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+
14811525 public function getVersion() {
14821526 return __CLASS__ . ': $Id$';
14831527 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r113865* Changing how 'sticky cookies' work as well as how manually switching betwee...awjrichards21:55, 14 March 2012

Comments

#Comment by Awjrichards (talk | contribs)   22:22, 14 March 2012

This is superseded by r113865

Status & tagging log