r108478 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108477‎ | r108478 | r108479 >
Date:23:43, 9 January 2012
Author:preilly
Status:ok
Tags:mobile 
Comment:
mobile frontend changes for zero rated support
Modified paths:
  • /trunk/extensions/MobileFrontend/ApplicationTemplate.php (modified) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/filepage.js (modified) (history)
  • /trunk/extensions/MobileFrontend/stylesheets/beta_common.css (modified) (history)
  • /trunk/extensions/MobileFrontend/stylesheets/common.css (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/ApplicationTemplate.php
@@ -1,7 +1,7 @@
22 <?php
33
44 if( !defined( 'MEDIAWIKI' ) ) {
5 - die( -1 );
 5+ die( -1 );
66 }
77
88 class ApplicationTemplate extends MobileFrontendTemplate {
@@ -13,10 +13,12 @@
1414 } else {
1515 $appleTouchIconTag = '';
1616 }
 17+
 18+ $zeroRatedBanner = ( isset( $this->data['zeroRatedBanner'] ) ) ? str_replace( 'style="display:none;"', '', $this->data['zeroRatedBanner'] ) : '';
1719
1820 $betaPrefix = ( $this->data['isBetaGroupMember'] ) ? 'beta_' : '';
1921
20 - $noticeHtml = empty( $this->data['noticeHtml'] ) ? '' : $this->data['noticeHtml'];
 22+ $noticeHtml = ( isset( $this->data['noticeHtml'] ) ) ? $this->data['noticeHtml'] : '';
2123
2224 $cssFileName = ( isset( $this->data['device']['css_file_name'] ) ) ? $this->data['device']['css_file_name'] : 'default';
2325
@@ -26,7 +28,7 @@
2729
2830 $openSearchScript = $startScriptTag . $javaScriptPath . $betaPrefix . 'opensearch.js?version=12142011129437' . $endScriptTag;
2931 $jQueryScript = ( $this->data['device']['supports_jquery'] ) ? $startScriptTag . $javaScriptPath . 'jquery-1.7.1.min.js' . $endScriptTag : '';
30 - $filePageScript = ( $this->data['isFilePage'] ) ? $startScriptTag . $javaScriptPath . 'filepage.js' . $endScriptTag : '';
 32+ $filePageScript = ( $this->data['isFilePage'] ) ? $startScriptTag . $javaScriptPath . 'filepage.js?version=122920111241' . $endScriptTag : '';
3133
3234 $startLinkTag = "<link href='{$this->data['wgExtensionAssetsPath']}/MobileFrontend/stylesheets/";
3335 $endLinkTag = "' media='all' rel='Stylesheet' type='text/css' />";
@@ -55,6 +57,7 @@
5658 </script>
5759 </head>
5860 <body>
 61+ {$zeroRatedBanner}
5962 {$this->data['searchWebkitHtml']}
6063 <div class='show' id='content_wrapper'>
6164 {$noticeHtml}
Index: trunk/extensions/MobileFrontend/javascripts/filepage.js
@@ -71,15 +71,19 @@
7272 }
7373
7474 function addToggle(id) {
75 - var filetoc = document.getElementById('filetoc'),
76 - items = filetoc.getElementsByTagName('a');
77 - for (var i = 0; i < items.length; i++) {
78 - var item = items[i],
79 - href = item.href,
80 - hashPos = href.search('#'),
81 - hash = href.substr(hashPos + 1);
82 - if (hash == id) {
83 - items[i].onclick = makeToggle(id);
 75+ var filetoc = document.getElementById('filetoc');
 76+ if ( filetoc ) {
 77+ var items = filetoc.getElementsByTagName('a');
 78+ if ( items ) {
 79+ for (var i = 0; i < items.length; i++) {
 80+ var item = items[i],
 81+ href = item.href,
 82+ hashPos = href.search('#'),
 83+ hash = href.substr(hashPos + 1);
 84+ if (hash == id) {
 85+ items[i].onclick = makeToggle(id);
 86+ }
 87+ }
8488 }
8589 }
8690 }
@@ -91,12 +95,14 @@
9296 }
9397
9498 function stopClickThrough() {
95 - var file = document.getElementById('file'),
96 - links = file.getElementsByTagName('a');
97 - if (links.length) {
98 - links[0].onclick = function() {
99 - return false;
100 - };
 99+ var file = document.getElementById('file');
 100+ if ( file ) {
 101+ var links = file.getElementsByTagName('a');
 102+ if (links.length) {
 103+ links[0].onclick = function() {
 104+ return false;
 105+ };
 106+ }
101107 }
102108 }
103109
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -3,6 +3,12 @@
44 var results = document.getElementById( 'results' );
55 var languageSelection = document.getElementById( 'languageselection' );
66
 7+var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
 8+
 9+if ( !zeroRatedBanner ) {
 10+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' );
 11+}
 12+
713 initClearSearchLink();
814
915 function initClearSearchLink() {
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
@@ -41,6 +41,10 @@
4242 search.onfocus = function() {
4343
4444 resetViewPort();
 45+
 46+ if ( zeroRatedBanner ) {
 47+ zeroRatedBanner.style.display = 'none';
 48+ }
4549
4650 if ( !focused ) {
4751 content.style.display = 'none';
@@ -131,6 +135,10 @@
132136 if ( pE ) {
133137 pE.style.display = 'none';
134138 }
 139+
 140+ if ( zeroRatedBanner ) {
 141+ zeroRatedBanner.style.display = 'block';
 142+ }
135143
136144 if ( ol ) {
137145 if ( sq ) {
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -153,6 +153,7 @@
154154 public static $isFilePage;
155155 public static $logoutHtml;
156156 public static $loginHtml;
 157+ public static $zeroRatedBanner;
157158
158159 public static $messageKeys = array(
159160 'mobile-frontend-show-button',
@@ -824,15 +825,14 @@
825826 private function sendApplicationVersionVaryHeader() {
826827 global $wgOut, $wgRequest;
827828 wfProfileIn( __METHOD__ );
 829+ $wgOut->addVaryHeader( 'Application_Version' );
828830 if ( isset( $_SERVER['HTTP_APPLICATION_VERSION'] ) ) {
829831 $wgRequest->response()->header( 'Application_Version: ' . $_SERVER['HTTP_APPLICATION_VERSION'] );
830 - $wgOut->addVaryHeader( 'Application_Version' );
831832 } else {
832833 if ( isset( $_SERVER['HTTP_X_DEVICE'] ) ) {
833834 if ( stripos( $_SERVER['HTTP_X_DEVICE'], 'iphone' ) !== false ||
834835 stripos( $_SERVER['HTTP_X_DEVICE'], 'android' ) !== false ) {
835836 $wgRequest->response()->header( 'Application_Version: ' . $_SERVER['HTTP_X_DEVICE'] );
836 - $wgOut->addVaryHeader( 'Application_Version' );
837837 }
838838 }
839839 }
@@ -1202,6 +1202,7 @@
12031203 $this->mainPage->strictErrorChecking = false;
12041204 $this->mainPage->encoding = 'UTF-8';
12051205
 1206+ $zeroLandingPage = $this->mainPage->getElementById( 'zero-landing-page' );
12061207 $featuredArticle = $this->mainPage->getElementById( 'mp-tfa' );
12071208 $newsItems = $this->mainPage->getElementById( 'mp-itn' );
12081209
@@ -1212,6 +1213,10 @@
12131214
12141215 $content = $this->mainPage->createElement( 'div' );
12151216 $content->setAttribute( 'id', 'content' );
 1217+
 1218+ if ( $zeroLandingPage ) {
 1219+ $content->appendChild( $zeroLandingPage );
 1220+ }
12161221
12171222 if ( $featuredArticle ) {
12181223 $h2FeaturedArticle = $this->mainPage->createElement( 'h2', self::$messages['mobile-frontend-featured-article'] );
@@ -1347,6 +1352,16 @@
13481353
13491354 $itemToRemoveRecords = $this->parseItemsToRemove();
13501355
 1356+ $zeroRatedBannerElement = $this->doc->getElementById( 'zero-rated-banner' );
 1357+
 1358+ if ( !$zeroRatedBannerElement ) {
 1359+ $zeroRatedBannerElement = $this->doc->getElementById( 'zero-rated-banner-red' );
 1360+ }
 1361+
 1362+ if ( $zeroRatedBannerElement ) {
 1363+ self::$zeroRatedBanner = $this->doc->saveXML( $zeroRatedBannerElement, LIBXML_NOEMPTYTAG );
 1364+ }
 1365+
13511366 if ( self::$isBetaGroupMember ) {
13521367 $ptLogout = $this->doc->getElementById( 'pt-logout' );
13531368
@@ -1354,9 +1369,8 @@
13551370 $ptLogoutLink = $ptLogout->firstChild;
13561371 self::$logoutHtml = $this->doc->saveXML( $ptLogoutLink, LIBXML_NOEMPTYTAG );
13571372 }
1358 -
13591373 $ptAnonLogin = $this->doc->getElementById( 'pt-anonlogin' );
1360 -
 1374+
13611375 if ( !$ptAnonLogin ) {
13621376 $ptAnonLogin = $this->doc->getElementById( 'pt-login' );
13631377 }
@@ -1409,14 +1423,22 @@
14101424 $itemToRemoveRecords['CLASS'][] = "thumbcaption";
14111425 $itemToRemoveRecords['CLASS'][] = "gallery";
14121426 }
 1427+
 1428+ $tagToRemoveNodeIdAttributeValues = array( 'zero-language-search' );
14131429
14141430 $domElemsToRemove = array();
14151431 foreach ( $itemToRemoveRecords['TAG'] as $tagToRemove ) {
14161432 $tagToRemoveNodes = $this->doc->getElementsByTagName( $tagToRemove );
1417 -
14181433 foreach ( $tagToRemoveNodes as $tagToRemoveNode ) {
 1434+ $tagToRemoveNodeIdAttributeValue = '';
14191435 if ( $tagToRemoveNode ) {
1420 - $domElemsToRemove[] = $tagToRemoveNode;
 1436+ $tagToRemoveNodeIdAttribute = $tagToRemoveNode->getAttributeNode( 'id' );
 1437+ if ( $tagToRemoveNodeIdAttribute ) {
 1438+ $tagToRemoveNodeIdAttributeValue = $tagToRemoveNodeIdAttribute->value;
 1439+ }
 1440+ if ( !in_array( $tagToRemoveNodeIdAttributeValue, $tagToRemoveNodeIdAttributeValues ) ) {
 1441+ $domElemsToRemove[] = $tagToRemoveNode;
 1442+ }
14211443 }
14221444 }
14231445 }
@@ -1556,7 +1578,7 @@
15571579 }
15581580
15591581 if ( self::$format === 'json' ) {
1560 - header( 'Content-Type: application/json' );
 1582+ header( 'Content-Type: application/javascript' );
15611583 header( 'Content-Disposition: attachment; filename="data.js";' );
15621584 $json_data = array();
15631585 $json_data['title'] = htmlspecialchars ( self::$title->getText() );
@@ -1635,6 +1657,7 @@
16361658 'wgExtensionAssetsPath' => $wgExtensionAssetsPath,
16371659 'wgScriptPath' => $wgScriptPath,
16381660 'isFilePage' => self::$isFilePage,
 1661+ 'zeroRatedBanner' => self::$zeroRatedBanner,
16391662 );
16401663 $applicationTemplate->setByArray( $options );
16411664 wfProfileOut( __METHOD__ );
Index: trunk/extensions/MobileFrontend/stylesheets/common.css
@@ -15,6 +15,32 @@
1616 display: none;
1717 }
1818
 19+#zero-rated-banner {
 20+ position: relative;
 21+ height: 20px;
 22+ width: 100%;
 23+ z-index: 99;
 24+ background: #EE8833;
 25+ display: block;
 26+ border-bottom: 1px solid;
 27+ border-color: #000000;
 28+}
 29+
 30+#zero-rated-banner-red {
 31+ position: relative;
 32+ height: 20px;
 33+ width: 100%;
 34+ z-index: 99;
 35+ background: #FF0000;
 36+ display: block;
 37+ border-bottom: 1px solid;
 38+ border-color: #000000;
 39+}
 40+
 41+#zero-rated-banner-text {
 42+ margin: 0px;
 43+}
 44+
1945 .suggestions-results {
2046 font-size: 1.2em;
2147 cursor: pointer;
Index: trunk/extensions/MobileFrontend/stylesheets/beta_common.css
@@ -21,6 +21,32 @@
2222 display: none;
2323 }
2424
 25+#zero-rated-banner {
 26+ position: relative;
 27+ height: 20px;
 28+ width: 100%;
 29+ z-index: 99;
 30+ background: #EE8833;
 31+ display: block;
 32+ border-bottom: 1px solid;
 33+ border-color: #000000;
 34+}
 35+
 36+#zero-rated-banner-red {
 37+ position: relative;
 38+ height: 20px;
 39+ width: 100%;
 40+ z-index: 99;
 41+ background: #FF0000;
 42+ display: block;
 43+ border-bottom: 1px solid;
 44+ border-color: #000000;
 45+}
 46+
 47+#zero-rated-banner-text {
 48+ margin: 0px;
 49+}
 50+
2551 .suggestions-results {
2652 font-size: 1.4em;
2753 cursor: pointer;

Status & tagging log