r114205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114204‎ | r114205 | r114206 >
Date:22:25, 19 March 2012
Author:awjrichards
Status:reverted
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/Makefile (modified) (history)
  • /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/javascripts/application.min.js (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/references.js (added) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/beta_common.css (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/DisableTemplate.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/FooterTemplate.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/MobileFrontend.body.php
@@ -43,6 +43,7 @@
4444 public static $logoutHtml;
4545 public static $loginHtml;
4646 public static $zeroRatedBanner;
 47+ public static $useFormatCookieName;
4748
4849 protected $useFormat;
4950
@@ -190,7 +191,7 @@
191192 * @return bool
192193 */
193194 public function addMobileFooter( &$obj, &$tpl ) {
194 - global $wgRequest;
 195+ global $wgRequest, $wgServer;
195196 wfProfileIn( __METHOD__ );
196197
197198 $title = $obj->getTitle();
@@ -202,6 +203,7 @@
203204 $this->removeQueryStringParameter( $wgRequest->appendQuery( 'useformat=mobile' ), 'mobileaction' )
204205 );
205206
 207+ $mobileViewUrl = $this->getMobileUrl( $wgServer . $mobileViewUrl );
206208 $tpl->set( 'mobileview', "<a href='{$mobileViewUrl}' class='noprint'>" . wfMsg( 'mobile-frontend-view' ) . "</a>" );
207209 $footerlinks['places'][] = 'mobileview';
208210 $tpl->set( 'footerlinks', $footerlinks );
@@ -1163,6 +1165,8 @@
11641166 'zeroRatedBanner' => self::$zeroRatedBanner,
11651167 'showText' => self::$messages[ 'mobile-frontend-show-button' ],
11661168 'hideText' => self::$messages[ 'mobile-frontend-hide-button' ],
 1169+ 'useFormatCookieName' => self::$useFormatCookieName,
 1170+ 'useFormatCookieDuration' => $this->getUseFormatCookieDuration(),
11671171 );
11681172 $applicationTemplate->setByArray( $options );
11691173 wfProfileOut( __METHOD__ );
@@ -1445,8 +1449,12 @@
14461450 }
14471451
14481452 public function checkUseFormatCookie() {
1449 - global $wgRequest;
 1453+ global $wgRequest, $wgCookiePrefix;
14501454
 1455+ if ( !isset( self::$useFormatCookieName )) {
 1456+ self::$useFormatCookieName = $wgCookiePrefix . 'mf_useformat';
 1457+ }
 1458+
14511459 $useFormat = $this->getUseFormat();
14521460 $useFormatFromCookie = $wgRequest->getCookie( 'mf_useformat' );
14531461
@@ -1471,27 +1479,44 @@
14721480 * @param string The format to store in the cookie
14731481 */
14741482 protected function setUseFormatCookie( $useFormat ) {
1475 - global $wgRequest;
 1483+ global $wgRequest, $wgCookiePath, $wgCookieSecure, $wgCookieDomain;
14761484 $expiry = $this->getUseFormatCookieExpiry();
1477 - $wgRequest->response()->setCookie( 'mf_useformat', $useFormat, $expiry );
 1485+
 1486+ // use regular php setcookie() rather than WebResponse::setCookie
 1487+ // so we can ignore $wgCookieHttpOnly since the protection it provides
 1488+ // is irrelevant for this cookie.
 1489+ setcookie( self::$useFormatCookieName, $useFormat, $expiry, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
14781490 }
14791491
14801492 /**
14811493 * Get the expiration time for the mf_useformat cookie
14821494 *
1483 - * If $wgMobileFrontendFormatCookieExpiry as a non-0 value,
14841495 * @param int The base time (in seconds since Epoch) from which to calculate
14851496 * cookie expiration. If null, time() is used.
 1497+ * @return int The time (in seconds since Epoch) that the cookie should expire
14861498 */
14871499 protected function getUseFormatCookieExpiry( $startTime=null ) {
1488 - global $wgCookieExpiration, $wgMobileFrontendFormatCookieExpiry;
1489 - $cookieDuration = ( abs( intval( $wgMobileFrontendFormatCookieExpiry ) ) > 0 ) ?
1490 - $wgMobileFrontendFormatCookieExpiry : $wgCookieExpiration;
 1500+ $cookieDuration = $this->getUseFormatCookieDuration();
14911501 if ( intval( $startTime ) === 0 ) $startTime = time();
14921502 $expiry = $startTime + $cookieDuration;
14931503 return $expiry;
14941504 }
14951505
 1506+ /**
 1507+ * Determine the duration the cookie should last.
 1508+ *
 1509+ * If $wgMobileFrontendFormatcookieExpiry has a non-0 value, use that
 1510+ * for the duration. Otherwise, fall back to $wgCookieExpiration.
 1511+ *
 1512+ * @return int The number of seconds for which the cookie should last.
 1513+ */
 1514+ protected function getUseFormatCookieDuration() {
 1515+ global $wgMobileFrontendFormatCookieExpiry, $wgCookieExpiration;
 1516+ $cookieDuration = ( abs( intval( $wgMobileFrontendFormatCookieExpiry ) ) > 0 ) ?
 1517+ $wgMobileFrontendFormatCookieExpiry : $wgCookieExpiration;
 1518+ return $cookieDuration;
 1519+ }
 1520+
14961521 public function getVersion() {
14971522 return __CLASS__ . ': $Id$';
14981523 }
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/application.js
@@ -26,6 +26,15 @@
2727 }
2828 utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick );
2929
 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+
3039 // Try to scroll and hide URL bar
3140 window.scrollTo( 0, 1 );
3241 }
Index: branches/wmf/1.19wmf1/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: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/references.js
@@ -0,0 +1,57 @@
 2+if( typeof jQuery !== 'undefined' ) {
 3+ MobileFrontend.references = (function($) {
 4+ var calculatePosition;
 5+
 6+ function collect() {
 7+ var references = {};
 8+ $( 'ol.references li' ).each(function(i, el) {
 9+ references[ $(el).attr( 'id' ) ] = {
 10+ html: $(el).html(),
 11+ label: i + 1
 12+ };
 13+ });
 14+ return references;
 15+ }
 16+
 17+ // TODO: only apply to places that need it
 18+ // http://www.quirksmode.org/blog/archives/2010/12/the_fifth_posit.html
 19+ // https://github.com/Modernizr/Modernizr/issues/167
 20+ calculatePosition = function() {
 21+ var h = $( '#mf-references' ).outerHeight();
 22+ $( '#mf-references' ).css( {
 23+ top: ( window.innerHeight + window.pageYOffset ) - h,
 24+ bottom: 'auto',
 25+ position: 'absolute'
 26+ } );
 27+ };
 28+ $( document ).scroll(calculatePosition);
 29+
 30+ function init() {
 31+ $( '<div id="mf-references"><div></div></div>' ).hide().appendTo( document.body );
 32+ var close = function( ev ) {
 33+ $( '#mf-references' ).fadeOut( 500 );
 34+ };
 35+ $( '<button>close</button>' ).click( close ).appendTo( '#mf-references' );
 36+ $( '.mw-cite-backlink a' ).click( close );
 37+
 38+ var data, html, href, references = collect();
 39+ $( 'sup a' ).click( function(ev) {
 40+ href = $(this).attr( 'href' );
 41+ data = href && href.charAt(0) === '#' ?
 42+ references[ href.substr( 1, href.length ) ] : null;
 43+
 44+ if( data ) {
 45+ html = '<h3>[' + data.label + ']</h3>' + data.html;
 46+ } else {
 47+ html = $( '<a />' ).text( $(this).text() ).
 48+ attr( 'href', href ).appendTo('<div />').parent().html();
 49+ }
 50+ $( '#mf-references div' ).html( html );
 51+ $( '#mf-references' ).fadeIn( 1000 );
 52+ calculatePosition();
 53+ ev.preventDefault();
 54+ });
 55+ }
 56+ init();
 57+ })(jQuery);
 58+}
\ No newline at end of file
Property changes on: branches/wmf/1.19wmf1/extensions/MobileFrontend/javascripts/references.js
___________________________________________________________________
Added: svn:eol-style
159 + native
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/beta_common.css
@@ -757,7 +757,7 @@
758758 #header,
759759 #search,
760760 #sq,
761 -form,
 761+#header form,
762762 #searchbox {
763763 position: relative;
764764 right: 0;
@@ -843,3 +843,50 @@
844844 .full-screen-search #nav {
845845 display: none !important;
846846 }
 847+
 848+#mf-references {
 849+ -webkit-transition: bottom 0.1s ease-in-out;
 850+ -moz-transition: bottom 0.1s ease-in-out;
 851+ -o-transition: bottom 0.1s ease-in-out;
 852+ transition: bottom 0.1s ease-in-out;
 853+ position: fixed;
 854+ bottom: 0;
 855+ left: 0;
 856+ right: 0;
 857+ background-color: #E4E4E4;
 858+ padding: 22px 34px;
 859+ -webkit-box-shadow: 0px -20px 10px -16px #aaa;
 860+ -moz-box-shadow: 0px -20px 10px -16px #aaa;
 861+ -o-box-shadow: 0px -20px 10px -16px #aaa;
 862+ box-shadow: 0px -20px 10px -16px #aaa;
 863+ word-break: break-word;
 864+ line-height: 1.4em;
 865+ font-size: 0.8em;
 866+}
 867+
 868+#mf-references button {
 869+ top: 22px;
 870+ right: 16px; /* padding of mf-references - width 18 */
 871+ width: 18px;
 872+ height: 12px;
 873+ background: url(images/close-button-beta.png) no-repeat scroll 0 0 transparent;
 874+ margin: 0;
 875+ background-position: right center;
 876+ background-size: auto 12px;
 877+ cursor: pointer;
 878+ position: absolute;
 879+ text-indent: -999px;
 880+ border: none;
 881+}
 882+
 883+#mf-references h3 {
 884+ margin: 0;
 885+ padding-right: 4px;
 886+ line-height: 1em;
 887+ display: inline;
 888+}
 889+
 890+#mf-references a:visited,
 891+#mf-references a {
 892+ color: #3354C0;
 893+}
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/Makefile
@@ -3,4 +3,5 @@
44 java -jar yuicompressor-2.4.6.jar javascripts/banner.js -o javascripts/banner.min.js
55 java -jar yuicompressor-2.4.6.jar javascripts/opensearch.js -o javascripts/opensearch.min.js
66 java -jar yuicompressor-2.4.6.jar javascripts/toggle.js -o javascripts/toggle.min.js
 7+ java -jar yuicompressor-2.4.6.jar javascripts/references.js -o javascripts/references.min.js
78 java -jar yuicompressor-2.4.6.jar javascripts/beta_opensearch.js -o javascripts/beta_opensearch.min.js
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/FooterTemplate.php
@@ -36,7 +36,7 @@
3737 <div id='footer' {$footerDisplayNone}>
3838 <div class='nav' id='footmenu'>
3939 <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}
4141 </div>
4242 </div>
4343 <div id='copyright'>{$copyright}</div>
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/ApplicationTemplate.php
@@ -34,7 +34,8 @@
3535 $endScriptTag = '"></script>';
3636 $javaScriptPath = $this->data['wgExtensionAssetsPath'] . '/MobileFrontend/javascripts/';
3737
38 - $jQueryScript = ( $this->data['device']['supports_jquery'] ) ? $startScriptTag . $javaScriptPath . 'jquery-1.7.1.min.js' . $endScriptTag : '';
 38+ $jQuerySupport = $this->data['device']['supports_jquery'];
 39+ $jQueryScript = $jQuerySupport ? $startScriptTag . $javaScriptPath . 'jquery-1.7.1.min.js' . $endScriptTag : '';
3940 $filePageScript = ( $this->data['isFilePage'] ) ? $startScriptTag . $javaScriptPath . 'filepage.js?version=122920111241' . $endScriptTag : '';
4041
4142 $startLinkTag = "<link href='{$this->data['wgExtensionAssetsPath']}/MobileFrontend/stylesheets/";
@@ -50,10 +51,19 @@
5152 ),
5253 'settings' => array(
5354 'scriptPath' => ( $this->data['wgScriptPath'] ),
 55+ 'useFormatCookieName' => ( $this->data['useFormatCookieName'] ),
 56+ 'useFormatCookieDuration' => ( $this->data['useFormatCookieDuration'] ),
5457 ),
5558 );
5659 $configuration = FormatJSON::encode( $jsconfig );
5760
 61+ if( $this->data['isBetaGroupMember'] && $jQuerySupport ) {
 62+ $betajs = <<<HTML
 63+ {$startScriptTag}{$javaScriptPath}references.{$resourceSuffix}js?version=1331257310{$endScriptTag}
 64+HTML;
 65+ } else {
 66+ $betajs = "";
 67+ }
5868 $applicationHtml = <<<HTML
5969 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
6070 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -84,6 +94,7 @@
8595 {$startScriptTag}{$javaScriptPath}toggle.{$resourceSuffix}js?version=1331257310{$endScriptTag}
8696 {$startScriptTag}{$javaScriptPath}banner.{$resourceSuffix}js?version=1331257310{$endScriptTag}
8797 {$startScriptTag}{$javaScriptPath}{$betaPrefix}opensearch.{$resourceSuffix}js?version=1331250599{$endScriptTag}
 98+ {$betajs}
8899 {$filePageScript}
89100 <!--[endif]-->
90101 </body>
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/templates/DisableTemplate.php
@@ -8,7 +8,9 @@
99
1010 public function getHTML() {
1111
12 - $currentURL = str_replace( '&mobileaction=disable_mobile_site', '', $this->data['currentURL'] ); // TODO: $currentURl is unused
 12+
 13+ $currentURL = str_replace( '&mobileaction=disable_mobile_site', '', $this->data['currentURL'] );
 14+ $currentURL = str_replace( '&useformat=mobile', '', $currentURL );
1315 $mobileRedirectFormAction = $this->data['mobileRedirectFormAction'];
1416
1517 $disableHtml = <<<HTML
@@ -20,7 +22,7 @@
2123 </p>
2224 <div id='disableButtons'>
2325 <form action='{$mobileRedirectFormAction}' method='get'>
24 - <input name='to' type='hidden' value='{$this->data['currentURL']}' />
 26+ <input name='to' type='hidden' value='{$currentURL}' />
2527 <input name='expires_in_days' type='hidden' value='3650' />
2628 <button id='disableButton' type='submit'>{$this->data['disableButton']}</button>
2729 </form>
Property changes on: branches/wmf/1.19wmf1/extensions/MobileFrontend
___________________________________________________________________
Modified: svn:mergeinfo
2830 Merged /trunk/extensions/MobileFrontend:r113942,113971,113987,114005,114025,114100

Follow-up revisions

RevisionCommit summaryAuthorDate
r114223Revert r114221,r114216,r114213,r114207,r114206,r114205,r114203,r114202,r11420...awjrichards00:26, 20 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r113942first version of references reveal...jdlrobson18:05, 15 March 2012
r113971Fix for bug 35249, makes disable mobile version confirmation page properly re...awjrichards23:08, 15 March 2012
r113987* Adds ExtMobileFrontend::$useFormatCookieName property so we can pass full m...awjrichards01:27, 16 March 2012
r114005make form rule more specific...jdlrobson09:41, 16 March 2012
r114025use top for absolute positioning not bottom...jdlrobson17:30, 16 March 2012
r114100svn:eol-style nativeialex16:11, 18 March 2012

Status & tagging log