Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -43,6 +43,7 @@ |
44 | 44 | public static $logoutHtml; |
45 | 45 | public static $loginHtml; |
46 | 46 | public static $zeroRatedBanner; |
| 47 | + public static $useFormatCookieName; |
47 | 48 | |
48 | 49 | protected $useFormat; |
49 | 50 | |
— | — | @@ -190,7 +191,7 @@ |
191 | 192 | * @return bool |
192 | 193 | */ |
193 | 194 | public function addMobileFooter( &$obj, &$tpl ) { |
194 | | - global $wgRequest; |
| 195 | + global $wgRequest, $wgServer; |
195 | 196 | wfProfileIn( __METHOD__ ); |
196 | 197 | |
197 | 198 | $title = $obj->getTitle(); |
— | — | @@ -202,6 +203,7 @@ |
203 | 204 | $this->removeQueryStringParameter( $wgRequest->appendQuery( 'useformat=mobile' ), 'mobileaction' ) |
204 | 205 | ); |
205 | 206 | |
| 207 | + $mobileViewUrl = $this->getMobileUrl( $wgServer . $mobileViewUrl ); |
206 | 208 | $tpl->set( 'mobileview', "<a href='{$mobileViewUrl}' class='noprint'>" . wfMsg( 'mobile-frontend-view' ) . "</a>" ); |
207 | 209 | $footerlinks['places'][] = 'mobileview'; |
208 | 210 | $tpl->set( 'footerlinks', $footerlinks ); |
— | — | @@ -1164,6 +1166,8 @@ |
1165 | 1167 | 'zeroRatedBanner' => self::$zeroRatedBanner, |
1166 | 1168 | 'showText' => self::$messages[ 'mobile-frontend-show-button' ], |
1167 | 1169 | 'hideText' => self::$messages[ 'mobile-frontend-hide-button' ], |
| 1170 | + 'useFormatCookieName' => self::$useFormatCookieName, |
| 1171 | + 'useFormatCookieDuration' => $this->getUseFormatCookieDuration(), |
1168 | 1172 | ); |
1169 | 1173 | $applicationTemplate->setByArray( $options ); |
1170 | 1174 | wfProfileOut( __METHOD__ ); |
— | — | @@ -1446,8 +1450,12 @@ |
1447 | 1451 | } |
1448 | 1452 | |
1449 | 1453 | public function checkUseFormatCookie() { |
1450 | | - global $wgRequest; |
| 1454 | + global $wgRequest, $wgCookiePrefix; |
1451 | 1455 | |
| 1456 | + if ( !isset( self::$useFormatCookieName )) { |
| 1457 | + self::$useFormatCookieName = $wgCookiePrefix . 'mf_useformat'; |
| 1458 | + } |
| 1459 | + |
1452 | 1460 | $useFormat = $this->getUseFormat(); |
1453 | 1461 | $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' ); |
1454 | 1462 | |
— | — | @@ -1472,27 +1480,44 @@ |
1473 | 1481 | * @param string The format to store in the cookie |
1474 | 1482 | */ |
1475 | 1483 | protected function setUseFormatCookie( $useFormat ) { |
1476 | | - global $wgRequest; |
| 1484 | + global $wgRequest, $wgCookiePath, $wgCookieSecure, $wgCookieDomain; |
1477 | 1485 | $expiry = $this->getUseFormatCookieExpiry(); |
1478 | | - $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, $expiry ); |
| 1486 | + |
| 1487 | + // use regular php setcookie() rather than WebResponse::setCookie |
| 1488 | + // so we can ignore $wgCookieHttpOnly since the protection it provides |
| 1489 | + // is irrelevant for this cookie. |
| 1490 | + setcookie( self::$useFormatCookieName, $useFormat, $expiry, $wgCookiePath, $wgCookieDomain, $wgCookieSecure ); |
1479 | 1491 | } |
1480 | 1492 | |
1481 | 1493 | /** |
1482 | 1494 | * Get the expiration time for the mf_useformat cookie |
1483 | 1495 | * |
1484 | | - * If $wgMobileFrontendFormatCookieExpiry as a non-0 value, |
1485 | 1496 | * @param int The base time (in seconds since Epoch) from which to calculate |
1486 | 1497 | * cookie expiration. If null, time() is used. |
| 1498 | + * @return int The time (in seconds since Epoch) that the cookie should expire |
1487 | 1499 | */ |
1488 | 1500 | protected function getUseFormatCookieExpiry( $startTime=null ) { |
1489 | | - global $wgCookieExpiration, $wgMobileFrontendFormatCookieExpiry; |
1490 | | - $cookieDuration = ( abs( intval( $wgMobileFrontendFormatCookieExpiry ) ) > 0 ) ? |
1491 | | - $wgMobileFrontendFormatCookieExpiry : $wgCookieExpiration; |
| 1501 | + $cookieDuration = $this->getUseFormatCookieDuration(); |
1492 | 1502 | if ( intval( $startTime ) === 0 ) $startTime = time(); |
1493 | 1503 | $expiry = $startTime + $cookieDuration; |
1494 | 1504 | return $expiry; |
1495 | 1505 | } |
1496 | 1506 | |
| 1507 | + /** |
| 1508 | + * Determine the duration the cookie should last. |
| 1509 | + * |
| 1510 | + * If $wgMobileFrontendFormatcookieExpiry has a non-0 value, use that |
| 1511 | + * for the duration. Otherwise, fall back to $wgCookieExpiration. |
| 1512 | + * |
| 1513 | + * @return int The number of seconds for which the cookie should last. |
| 1514 | + */ |
| 1515 | + protected function getUseFormatCookieDuration() { |
| 1516 | + global $wgMobileFrontendFormatCookieExpiry, $wgCookieExpiration; |
| 1517 | + $cookieDuration = ( abs( intval( $wgMobileFrontendFormatCookieExpiry ) ) > 0 ) ? |
| 1518 | + $wgMobileFrontendFormatCookieExpiry : $wgCookieExpiration; |
| 1519 | + return $cookieDuration; |
| 1520 | + } |
| 1521 | + |
1497 | 1522 | public function getVersion() { |
1498 | 1523 | return __CLASS__ . ': $Id$'; |
1499 | 1524 | } |
Index: trunk/extensions/MobileFrontend/javascripts/application.min.js |
— | — | @@ -1 +1 @@ |
2 | | -MobileFrontend=(function(){var a;function b(){var e;a(document.body).addClass("jsEnabled");e=document.getElementById("languageselection");function c(){var f;if(e){f=e.options[e.selectedIndex].value;if(f){location.href=f}}}a(e).bind("change",c);function d(){var f=document.getElementById("nav").style;f.display=f.display==="block"?"none":"block"}a(document.getElementById("logo")).bind("click",d);window.scrollTo(0,1)}a=typeof jQuery!=="undefined"?jQuery:function(e){if(typeof(e)==="string"){if(document.querySelectorAll){return[].slice.call(document.querySelectorAll(e))}}function d(i){var j=e.className.split("");return j.indexOf(i)>-1}function f(i){var j=e.className,k=j.split(" ");k.push(i);e.className=k.join(" ")}function g(j){var l=e.className,m=l.split(" "),n=[],k;for(k=0;k<m.length;k++){if(m[k]!==j){n.push(m[k])}}e.className=n.join(" ")}function h(j,i){e.addEventListener(j,i,false)}function c(){e.parentNode.removeChild(e)}return{addClass:f,bind:h,hasClass:d,remove:c,removeClass:g}};a.ajax=a.ajax||function(e){var c,d;if(window.XMLHttpRequest){c=new XMLHttpRequest()}else{c=new ActiveXObject("Microsoft.XMLHTTP")}if(c.overrideMimeType){c.overrideMimeType("text/xml")}c.onreadystatechange=function(){if(c.readyState===4&&c.status===200){e.success(c.responseXML)}};c.open("GET",e.url,true);c.send()};b();return{init:b,message:function(c){return mwMobileFrontendConfig.messages[c]||""},setting:function(c){return mwMobileFrontendConfig.settings[c]||""},utils:a}}()); |
\ No newline at end of file |
| 2 | +MobileFrontend=(function(){var a;function b(){var e;a(document.body).addClass("jsEnabled");e=document.getElementById("languageselection");function c(){var g;if(e){g=e.options[e.selectedIndex].value;if(g){location.href=g}}}a(e).bind("change",c);function d(){var g=document.getElementById("nav").style;g.display=g.display==="block"?"none":"block"}a(document.getElementById("logo")).bind("click",d);function f(){var h=MobileFrontend.setting("useFormatCookieName");var g=MobileFrontend.setting("useFormatCookieDuration");g=g/(24*60*60);MobileFrontend.banner.writeCookie(h,"desktop",g)}a(document.getElementById("mf-display-toggle")).bind("click",f);window.scrollTo(0,1)}a=typeof jQuery!=="undefined"?jQuery:function(e){if(typeof(e)==="string"){if(document.querySelectorAll){return[].slice.call(document.querySelectorAll(e))}}else{if(!e){e=document.createElement("div")}}function d(i){var j=e.className.split(" ");return j.indexOf(i)>-1}function f(i){var j=e.className,k=j.split(" ");k.push(i);e.className=k.join(" ")}function g(j){var l=e.className,m=l.split(" "),n=[],k;for(k=0;k<m.length;k++){if(m[k]!==j){n.push(m[k])}}e.className=n.join(" ")}function h(j,i){e.addEventListener(j,i,false)}function c(){e.parentNode.removeChild(e)}return{addClass:f,bind:h,hasClass:d,remove:c,removeClass:g}};a.ajax=a.ajax||function(e){var c,d;if(window.XMLHttpRequest){c=new XMLHttpRequest()}else{c=new ActiveXObject("Microsoft.XMLHTTP")}if(c.overrideMimeType){c.overrideMimeType("text/xml")}c.onreadystatechange=function(){if(c.readyState===4&&c.status===200){e.success(c.responseXML)}};c.open("GET",e.url,true);c.send()};b();return{init:b,message:function(c){return mwMobileFrontendConfig.messages[c]||""},setting:function(c){return mwMobileFrontendConfig.settings[c]||""},utils:a}}()); |
\ No newline at end of file |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -26,6 +26,15 @@ |
27 | 27 | } |
28 | 28 | utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
29 | 29 | |
| 30 | + function desktopViewClick() { |
| 31 | + var cookieName = MobileFrontend.setting( 'useFormatCookieName' ); |
| 32 | + var cookieDuration = MobileFrontend.setting( 'useFormatCookieDuration' ); |
| 33 | + // convert from seconds to days |
| 34 | + cookieDuration = cookieDuration / ( 24 * 60 * 60 ); |
| 35 | + MobileFrontend.banner.writeCookie( cookieName, 'desktop', cookieDuration ); |
| 36 | + } |
| 37 | + utilities( document.getElementById( 'mf-display-toggle' ) ).bind( 'click', desktopViewClick ); |
| 38 | + |
30 | 39 | // Try to scroll and hide URL bar |
31 | 40 | window.scrollTo( 0, 1 ); |
32 | 41 | } |
Index: trunk/extensions/MobileFrontend/templates/FooterTemplate.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | <div id='footer' {$footerDisplayNone}> |
38 | 38 | <div class='nav' id='footmenu'> |
39 | 39 | <div class='mwm-notice'> |
40 | | - <a href="{$viewNormalSiteURL}">{$regularSite}</a> | <a href="{$imagesURL}">{$imagesToggle}</a> {$feedbackLink} {$logoutLink} |
| 40 | + <a href="{$viewNormalSiteURL}" id="mf-display-toggle">{$regularSite}</a> | <a href="{$imagesURL}">{$imagesToggle}</a> {$feedbackLink} {$logoutLink} |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div id='copyright'>{$copyright}</div> |
Index: trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php |
— | — | @@ -51,6 +51,8 @@ |
52 | 52 | ), |
53 | 53 | 'settings' => array( |
54 | 54 | 'scriptPath' => ( $this->data['wgScriptPath'] ), |
| 55 | + 'useFormatCookieName' => ( $this->data['useFormatCookieName'] ), |
| 56 | + 'useFormatCookieDuration' => ( $this->data['useFormatCookieDuration'] ), |
55 | 57 | ), |
56 | 58 | ); |
57 | 59 | $configuration = FormatJSON::encode( $jsconfig ); |