Dr0ptp4kt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/181194

Change subject: Support dynamic HTTPS not free message
......................................................................

Support dynamic HTTPS not free message

Additionally, lighten the background gray color of the banner,
and remove the clickthroughs, per the business team.

Change-Id: I5f8414baaab805715a990ad788111e50171a7fe1
---
M i18n/en.json
M includes/ApiZeroBanner.php
M includes/PageRendering.php
M includes/ZeroSpecialPage.php
M modules/banner.css
5 files changed, 38 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroBanner 
refs/changes/94/181194/1

diff --git a/i18n/en.json b/i18n/en.json
index de4a42e..947856a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -34,6 +34,7 @@
        "zero-dont-ask": "Do not warn me about potential charges in the future",
        "zero-go-back": "Go back",
        "zero-accept": "Accept",
+       "zero-https-not-free": "HTTPS (encrypted) not free",
        "zero-https-http": "HTTPS (encrypted) not free. Tap here for HTTP (less 
secure).",
        "zero-click-to-view-image": "Click to view image of \"$1\"...",
        "zero-dismiss-notification": "dismiss this notification",
diff --git a/includes/ApiZeroBanner.php b/includes/ApiZeroBanner.php
index a54a165..5e8e947 100644
--- a/includes/ApiZeroBanner.php
+++ b/includes/ApiZeroBanner.php
@@ -62,7 +62,6 @@
                                        $result->addValue( $moduleName, 
'showImages', $config->showImages() );
                                        $result->addValue( $moduleName, 
'whitelistedLangs', $config->whitelistedLangs() );
                                        $result->addValue( $moduleName, 
'enableHttps', $config->enableHttps() );
-                                       // TODO: add showHttpsDowngrade here 
when adding JavaScript support for it
                                        $result->addValue( $moduleName, 
'sites', $config->sites() );
                                        $result->addValue( $moduleName, 
'domains', $config->domains() );
                                } else {
diff --git a/includes/PageRendering.php b/includes/PageRendering.php
index 1d4399b..96b970f 100644
--- a/includes/PageRendering.php
+++ b/includes/PageRendering.php
@@ -85,7 +85,6 @@
                        $cfg['showImages'] = $config->showImages();
                        $cfg['whitelistedLangs'] = $config->whitelistedLangs();
                        $cfg['enableHttps'] = $config->enableHttps();
-                       // TODO: add showHttpsDowngrade here when adding 
JavaScript support for it
                        $cfg['sites'] = $config->sites(); // todo: remove this 
value once it's out of cache
                        $cfg['domains'] = $config->domains();
                        $cfg['proxy'] = $config->proxy();
@@ -426,6 +425,8 @@
                //
                // This is simpler than growing the cache per-operator (no!) or 
putting some sort of complicated
                // parameter trying to help us intuit the user's intention
+
+               /* Per business team, no need for clickthrough yet. Hence the 
following if() being commented out
                if ( $isHttps || $isZeroSubdomain ) {
                        // We probably don't need the project from the 
(instance) getWikiInfo() method because
                        // (a) we're not expanding zerodot to sister projects, 
and
@@ -434,6 +435,7 @@
                        // of the clickable banner (e.g., if I click here, it 
gets me to a landing/homepage).
                        return Html::openElement( 'a', array( 'href' => 
'http://zero.wikipedia.org/') ) . $img . Html::closeElement( 'a' );
                }
+               */
                return $img;
        }
 
@@ -505,6 +507,15 @@
                return $banner;
        }
 
+       public static function renderHttpsDowngrade() {
+               global $wgLang;
+               return Html::element(
+                       'div',
+                       array( 'class' => 'mw-mf-banner 
mw-mf-banner-undismissable mw-mf-banner-gray' ),
+                       wfMessage( 'zero-https-not-free' )->inLanguage( $wgLang 
)
+               );
+       }
+
        /**
         * If a particular language could cause a charge, send user to an 
interstitial.
         *
diff --git a/includes/ZeroSpecialPage.php b/includes/ZeroSpecialPage.php
index bc3efe9..650ae27 100644
--- a/includes/ZeroSpecialPage.php
+++ b/includes/ZeroSpecialPage.php
@@ -379,6 +379,9 @@
                        //
                        $response->header( 'Content-type: 
application/javascript; charset=UTF-8' );
                        $banner = '';
+                       // Even with Apache/Varnish redirects to HTTPS, this is 
fine, because
+                       // the Special:ZRMA URL grom getStartPageUrl does not 
itself call back
+                       // into this js-banner endpoint, thereby avoiding 
recursive redirects.
                        if ( $state->isZeroSubdomain() && 
!$state->getZeroConfig() ) {
                                // If zerodot isn't supported here and the user 
isn't already on
                                // Special:ZeroRatedMobileAccess, send the user 
to Special:ZeroRatedMobileAccess
@@ -388,15 +391,24 @@
                                $url = $state->getStartPageUrl( $info[0], 
$flags );
                                $banner = 
"window.location='$url?from='+encodeURIComponent(window.location)";
                        } else {
-                               $config = $state->getZeroConfig();
-                               if ( $config && $config->enabled() ) {
-                                       $bannerHtml = 
PageRendering::renderBanner( $state, $config, null, null, $isFilePage );
-                                       $cfg = PageRendering::getJsConfigBlock( 
$this, $id, $config, (bool)$bannerHtml );
+                               $config = $state->getZeroConfig( 
ZeroConfig::ignoreHttps );
+                               // it's handy to have the $isHttps variable 
here for local simulation of HTTPS
+                               $isHttps = $state->isHttps();
+                               // note we set the ZeroConfig::ignoreHttps flag 
above, so we need to take that into account for banners
+                               $httpsCausesCharge = $isHttps && $config && 
!$config->enableHttps();
+                               $configForBanner = $httpsCausesCharge ? null : 
$config;
+                               if ( $configForBanner ) {
+                                       $bannerHtml = 
PageRendering::renderBanner( $state, $configForBanner, null, null, $isFilePage 
);
+                                       $cfg = PageRendering::getJsConfigBlock( 
$this, $id, $configForBanner, (bool)$bannerHtml );
                                        if ( $bannerHtml ) {
                                                $banner = 'document.write(' . 
Xml::encodeJsVar( $bannerHtml ) . ');';
                                        }
                                } else {
-                                       $cfg = PageRendering::getJsConfigBlock( 
$this, $id, $config, false );
+                                       if ( $config && 
$config->showHttpsDowngrade() ) {
+                                               $banner = 'document.write(' . 
Xml::encodeJsVar( PageRendering::renderHttpsDowngrade() ) . ');';
+                                       }
+                                       // Note we use the banner config 
variable instead of the HTTPS-ignoreing one
+                                       $cfg = PageRendering::getJsConfigBlock( 
$this, $id, $configForBanner, false );
                                }
                                $banner = $cfg . $banner;
                        }
@@ -426,7 +438,9 @@
                                // the configuration would have been valid if 
it were on http:// cleartext
                                // TODO: look at the user's cookies to see if 
the user doesn't care about charges?
                                // TODO: replicate for JavaScript devices
-                               $banner = self::createImageBanner( 'gray', 
'black', $this->msg( 'zero-https-http' )->text(), true);
+                               // Per business team, header does not need to 
be tappable. Thus, using zero-https-not-free
+                               // instead of zero-https-http for now
+                               $banner = self::createImageBanner( 'gainsboro', 
'black', $this->msg( 'zero-https-not-free' )->text(), true);
                        } elseif ( $state->isZeroSubdomain() ) {
                                // the configuration only would have been valid 
if it wasn't on zerodot
                                $host = implode( '.', $state->getWikiInfo() );
diff --git a/modules/banner.css b/modules/banner.css
index 704be35..84384fc 100644
--- a/modules/banner.css
+++ b/modules/banner.css
@@ -19,6 +19,11 @@
        white-space: normal !important;
        font-family: Tahoma, sans-serif;
 }
+.mw-mf-banner-gray {
+    color: #000000;
+    background: #DCDCDC;
+    font-weight: normal;
+}
 .mw-mf-banner .mw-mf-message,
 .mw-mf-banner button {
        padding-top: 10px;

-- 
To view, visit https://gerrit.wikimedia.org/r/181194
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f8414baaab805715a990ad788111e50171a7fe1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroBanner
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to