https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114576
Revision: 114576 Author: awjrichards Date: 2012-03-28 21:31:56 +0000 (Wed, 28 Mar 2012) Log Message: ----------- Picking up mf_useformat cookie fixes - MFG Change-Id: Iec23d682, Change-Id: I0f6a4405, Change_Id: I45b38d55; Updating minified JS for application.js and banner.js Modified Paths: -------------- branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.php branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.min.js branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.js branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.min.js branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php 2012-03-28 21:31:56 UTC (rev 114576) @@ -1161,7 +1161,7 @@ } public function getApplicationTemplate() { - global $wgAppleTouchIcon, $wgExtensionAssetsPath, $wgScriptPath; + global $wgAppleTouchIcon, $wgExtensionAssetsPath, $wgScriptPath, $wgCookiePath; wfProfileIn( __METHOD__ ); $applicationTemplate = new ApplicationTemplate(); $options = array( @@ -1181,6 +1181,8 @@ 'hideText' => self::$messages[ 'mobile-frontend-hide-button' ], 'useFormatCookieName' => self::$useFormatCookieName, 'useFormatCookieDuration' => $this->getUseFormatCookieDuration(), + 'useFormatCookiePath' => $wgCookiePath, + 'useFormatCookieDomain' => $this->getBaseDomain(), ); $applicationTemplate->setByArray( $options ); wfProfileOut( __METHOD__ ); @@ -1491,15 +1493,15 @@ } public function checkUseFormatCookie() { - global $wgRequest, $wgCookiePrefix, $wgScriptPath; - + global $wgRequest, $wgScriptPath; + if ( !isset( self::$useFormatCookieName )) { - self::$useFormatCookieName = $wgCookiePrefix . 'mf_useformat'; + self::$useFormatCookieName = 'mf_useformat'; } $useFormat = $this->getUseFormat(); - $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' ); - + $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat', '' ); + // fetch format from cookie and set it if one is not otherwise specified if( !strlen( $useFormat ) && !is_null( $useFormatFromCookie ) ) { $this->setUseFormat( $useFormatFromCookie ); @@ -1527,13 +1529,13 @@ * @param string $useFormat The format to store in the cookie */ protected function setUseFormatCookie( $useFormat ) { - global $wgCookiePath, $wgCookieSecure, $wgCookieDomain; + global $wgCookiePath, $wgCookieSecure; $expiry = $this->getUseFormatCookieExpiry(); - + // use regular php setcookie() rather than WebResponse::setCookie // so we can ignore $wgCookieHttpOnly since the protection it provides // is irrelevant for this cookie. - setcookie( self::$useFormatCookieName, $useFormat, $expiry, $wgCookiePath, $wgCookieDomain, $wgCookieSecure ); + setcookie( self::$useFormatCookieName, $useFormat, $expiry, $wgCookiePath, $this->getBaseDomain(), $wgCookieSecure ); wfIncrStats( 'mobile.useformat_' . $useFormat . '_cookie_set' ); } @@ -1552,8 +1554,7 @@ } public function getCacheVaryCookies( $out, &$cookies ) { - global $wgCookiePrefix; - $cookies[] = $wgCookiePrefix . 'mf_useformat'; + $cookies[] = 'mf_useformat'; return true; } Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.php =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.php 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.php 2012-03-28 21:31:56 UTC (rev 114576) @@ -156,6 +156,7 @@ * See $itemsToRemove for more information. */ $wgMFRemovableClasses = array(); + /** * Make the logos configurable. * Key for site. Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js 2012-03-28 21:31:56 UTC (rev 114576) @@ -29,9 +29,14 @@ function desktopViewClick() { var cookieName = MobileFrontend.setting( 'useFormatCookieName' ); var cookieDuration = MobileFrontend.setting( 'useFormatCookieDuration' ); + var cookiePath = MobileFrontend.setting( 'useFormatCookiePath' ); + var cookieDomain = MobileFrontend.setting( 'useFormatCookieDomain' ); + // convert from seconds to days cookieDuration = cookieDuration / ( 24 * 60 * 60 ); - MobileFrontend.banner.writeCookie( cookieName, 'desktop', cookieDuration ); + + // get the top part of the domain to make the cookie work across subdomains + MobileFrontend.banner.writeCookie( cookieName, 'desktop', cookieDuration, cookiePath, cookieDomain ); } utilities( document.getElementById( 'mf-display-toggle' ) ).bind( 'click', desktopViewClick ); Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.min.js =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.min.js 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.min.js 2012-03-28 21:31:56 UTC (rev 114576) @@ -1 +1 @@ -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 +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 j=MobileFrontend.setting("useFormatCookieName");var i=MobileFrontend.setting("useFormatCookieDuration");var h=MobileFrontend.setting("useFormatCookiePath");var g=MobileFrontend.setting("useFormatCookieDomain");i=i/(24*60*60);MobileFrontend.banner.writeCookie(j,"desktop",i,h,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 Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.js =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.js 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.js 2012-03-28 21:31:56 UTC (rev 114576) @@ -21,7 +21,7 @@ } } - function writeCookie( name, value, days ) { + function writeCookie( name, value, days, path, domain ) { var date, expires; if ( days ) { date = new Date(); @@ -30,7 +30,17 @@ } else { expires = ''; } - document.cookie = name + '=' + value + expires + '; path=/'; + + if ( typeof path === 'undefined' ) { + path = "/"; + } + + var cookie = name + '=' + value + expires + '; path=' + path; + + if ( typeof domain !== 'undefined' ) { + cookie = cookie + '; domain=' + domain; + } + document.cookie = cookie; } function readCookie( name ) { Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.min.js =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.min.js 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/banner.min.js 2012-03-28 21:31:56 UTC (rev 114576) @@ -1 +1 @@ -MobileFrontend.banner=(function(){function d(){var f,h,e,g;f=document.getElementById("dismiss-notification");if(f){h="zeroRatedBannerVisibility";e=document.getElementById("zero-rated-banner")||document.getElementById("zero-rated-banner-red");g=c(h);if(g==="off"){e.style.display="none"}f.onclick=function(){if(e){e.style.display="none";a(h,"off",1)}}}}function a(g,h,i){var f,e;if(i){f=new Date();f.setTime(f.getTime()+(i*24*60*60*1000));e="; expires="+f.toGMTString()}else{e=""}document.cookie=g+"="+h+e+"; path=/"}function c(g){var f=g+"=",e=document.cookie.split(";"),j,h;for(h=0;h<e.length;h++){j=e[h];while(j.charAt(0)===" "){j=j.substring(1,j.length)}if(j.indexOf(f)===0){return j.substring(f.length,j.length)}}return null}function b(e){a(e,"",-1);return null}d();return{init:d,readCookie:c,writeCookie:a,removeCookie:b}})(); \ No newline at end of file +MobileFrontend.banner=(function(){function d(){var f,h,e,g;f=document.getElementById("dismiss-notification");if(f){h="zeroRatedBannerVisibility";e=document.getElementById("zero-rated-banner")||document.getElementById("zero-rated-banner-red");g=c(h);if(g==="off"){e.style.display="none"}f.onclick=function(){if(e){e.style.display="none";a(h,"off",1)}}}}function a(g,j,l,k,i){var f,e;if(l){f=new Date();f.setTime(f.getTime()+(l*24*60*60*1000));e="; expires="+f.toGMTString()}else{e=""}if(typeof k==="undefined"){k="/"}var h=g+"="+j+e+"; path="+k;if(typeof i!=="undefined"){h=h+"; domain="+i}document.cookie=h}function c(g){var f=g+"=",e=document.cookie.split(";"),j,h;for(h=0;h<e.length;h++){j=e[h];while(j.charAt(0)===" "){j=j.substring(1,j.length)}if(j.indexOf(f)===0){return j.substring(f.length,j.length)}}return null}function b(e){a(e,"",-1);return null}d();return{init:d,readCookie:c,writeCookie:a,removeCookie:b}})(); \ No newline at end of file Modified: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php =================================================================== --- branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php 2012-03-28 21:31:04 UTC (rev 114575) +++ branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php 2012-03-28 21:31:56 UTC (rev 114576) @@ -53,6 +53,8 @@ 'scriptPath' => ( $this->data['wgScriptPath'] ), 'useFormatCookieName' => ( $this->data['useFormatCookieName'] ), 'useFormatCookieDuration' => ( $this->data['useFormatCookieDuration'] ), + 'useFormatCookieDomain' => ( $this->data['useFormatCookieDomain'] ), + 'useFormatCookiePath' => ( $this->data['useFormatCookiePath'] ), ), ); $configuration = FormatJSON::encode( $jsconfig ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs