r114937 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114936‎ | r114937 | r114938 >
Date:17:18, 17 April 2012
Author:awjrichards
Status:deferred
Tags:
Comment:
Fix for bug 36024, MFG Change-Id: I9676454ebd0c552ade4d375d3b1577c8f1568d7a
Modified paths:
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php
@@ -961,10 +961,13 @@
962962 'wgScriptPath' => $wgScriptPath,
963963 'isFilePage' => $isFilePage,
964964 'zeroRatedBanner' => self::$zeroRatedBanner,
965 - 'useFormatCookieName' => 'stopMobileRedirect',
966 - 'useFormatCookieDuration' => $this->getUseFormatCookieDuration(),
 965+ 'stopMobileRedirectCookieName' => 'stopMobileRedirect',
 966+ 'stopMobileRedirectCookieDuration' => $this->getUseFormatCookieDuration(),
 967+ 'stopMobileRedirectCookieDomain' => $this->getBaseDomain(),
 968+ 'useFormatCookieName' => $this->getUseFormatCookieName(),
 969+ 'useFormatCookieDuration' => -1,
967970 'useFormatCookiePath' => $wgCookiePath,
968 - 'useFormatCookieDomain' => $this->getBaseDomain(),
 971+ 'useFormatCookieDomain' => $_SERVER['HTTP_HOST'],
969972 );
970973 $applicationTemplate->setByArray( $options );
971974 wfProfileOut( __METHOD__ );
@@ -1280,8 +1283,8 @@
12811284 }
12821285
12831286 // check cookies for what to display
1284 - $useFormatCookie = $this->getUseFormatCookie();
1285 - if ( $useFormatCookie == 'mobile' ) {
 1287+ $useMobileFormat = $this->getUseFormatCookie();
 1288+ if ( $useMobileFormat == 'true' ) {
12861289 return true;
12871290 }
12881291 $stopMobileRedirect = $this->getStopMobileRedirectCookie();
@@ -1392,7 +1395,7 @@
13931396 * @param int $string The expiration to set
13941397 * @param bool $force Whether or not to force the cookie getting set
13951398 */
1396 - public function setUseFormatCookie( $cookieFormat, $expiry = null, $force = false ) {
 1399+ public function setUseFormatCookie( $cookieFormat = 'true', $expiry = null, $force = false ) {
13971400 global $wgCookiePath, $wgCookieSecure;
13981401
13991402 // sanity check before setting the cookie
@@ -1404,7 +1407,7 @@
14051408 $expiry = $this->getUseFormatCookieExpiry();
14061409 }
14071410
1408 - setcookie( $this->getUseFormatCookieName(), $cookieFormat, $expiry, $wgCookiePath, $this->getBaseDomain(), $wgCookieSecure );
 1411+ setcookie( $this->getUseFormatCookieName(), $cookieFormat, $expiry, $wgCookiePath, $_SERVER['HTTP_HOST'], $wgCookieSecure );
14091412 wfIncrStats( 'mobile.useformat_' . $cookieFormat . '_cookie_set' );
14101413 }
14111414
@@ -1420,7 +1423,7 @@
14211424
14221425 public function getUseFormatCookieName() {
14231426 if ( !isset( self::$useFormatCookieName ) ) {
1424 - self::$useFormatCookieName = 'mf_useformat';
 1427+ self::$useFormatCookieName = 'mf_mobileFormat';
14251428 }
14261429 return self::$useFormatCookieName;
14271430 }
@@ -1506,7 +1509,7 @@
15071510
15081511 // if no mobileurl template, set mobile cookie
15091512 if ( !strlen( trim( $wgMobileUrlTemplate ) ) ) {
1510 - if ( !$temporary ) $this->setUseFormatCookie( $view );
 1513+ if ( !$temporary ) $this->setUseFormatCookie();
15111514 $this->setUseFormat( $view );
15121515 } else {
15131516 // else redirect to mobile domain
@@ -1517,12 +1520,16 @@
15181521 }
15191522 } elseif ( $view == 'desktop' ) {
15201523 // set stopMobileRedirect cookie
1521 - if ( !$temporary ) $this->setStopMobileRedirectCookie();
 1524+ if ( !$temporary ) {
 1525+ $this->setStopMobileRedirectCookie();
 1526+ // unset useformat cookie
 1527+ if ( $this->getUseFormatCookie() == "true" ) {
 1528+ $this->unsetUseFormatCookie();
 1529+ }
 1530+ }
15221531
15231532 // if no mobileurl template, unset useformat cookie
15241533 if ( !strlen( trim( $wgMobileUrlTemplate ) ) ) {
1525 - // unset useformat cookie
1526 - if ( !$temporary ) $this->unsetUseFormatCookie();
15271534 $this->setUseFormat( $view );
15281535 } else {
15291536 // if mobileurl template, redirect to desktop domain
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js
@@ -36,16 +36,28 @@
3737 utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick );
3838
3939 function desktopViewClick() {
40 - var cookieName = MobileFrontend.setting( 'useFormatCookieName' );
41 - var cookieDuration = MobileFrontend.setting( 'useFormatCookieDuration' );
 40+ // get mf_mobileFormat cookie info
 41+ var formatCookieName = MobileFrontend.setting( 'useFormatCookieName' );
 42+ var formatCookieDuration = MobileFrontend.setting( 'useFormatCookieDuration' );
4243 var cookiePath = MobileFrontend.setting( 'useFormatCookiePath' );
43 - var cookieDomain = MobileFrontend.setting( 'useFormatCookieDomain' );
44 -
 44+ var formatCookieDomain = MobileFrontend.setting( 'useFormatCookieDomain' );
 45+
4546 // convert from seconds to days
46 - cookieDuration = cookieDuration / ( 24 * 60 * 60 );
 47+ formatCookieDuration = formatCookieDuration / ( 24 * 60 * 60 );
4748
48 - // get the top part of the domain to make the cookie work across subdomains
49 - MobileFrontend.banner.writeCookie( cookieName, 'true', cookieDuration, cookiePath, cookieDomain );
 49+ // expire the mf_mobileFormat cookie
 50+ MobileFrontend.banner.writeCookie( formatCookieName, '', formatCookieDuration, cookiePath, formatCookieDomain );
 51+
 52+ // get stopMobileRedirect cookie info
 53+ var stopMobileRedirectCookieName = MobileFrontend.setting( 'stopMobileRedirectCookieName' );
 54+ var stopMobileRedirectCookieDuration = MobileFrontend.setting( 'stopMobileRedirectCookieDuration' );
 55+ var stopMobileRedirectCookieDomain = MobileFrontend.setting( 'stopMobileRedirectCookieDomain' );
 56+
 57+ // convert from seconds to days
 58+ stopMobileRedirectCookieDuration = stopMobileRedirectCookieDuration / ( 24 * 60 *60 );
 59+
 60+ // set the stopMobileRedirect cookie
 61+ MobileFrontend.banner.writeCookie( stopMobileRedirectCookieName, 'true', stopMobileRedirectCookieDuration, cookiePath, stopMobileRedirectCookieDomain );
5062 }
5163 utilities( document.getElementById( 'mf-display-toggle' ) ).bind( 'click', desktopViewClick );
5264
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php
@@ -50,6 +50,9 @@
5151 'useFormatCookieDuration' => ( $this->data['useFormatCookieDuration'] ),
5252 'useFormatCookieDomain' => ( $this->data['useFormatCookieDomain'] ),
5353 'useFormatCookiePath' => ( $this->data['useFormatCookiePath'] ),
 54+ 'stopMobileRedirectCookieName' => ( $this->data['stopMobileRedirectCookieName'] ),
 55+ 'stopMobileRedirectCookieDuration' => ( $this->data['stopMobileRedirectCookieDuration'] ),
 56+ 'stopMobileRedirectCookieDomain' => ( $this->data['stopMobileRedirectCookieDomain'] ),
5457 ),
5558 );
5659 if ( $this->data['title']->isMainPage() ) {

Status & tagging log