Yurik has uploaded a new change for review.

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


Change subject: Simplified banner rendering and fixed empty partner URL
......................................................................

Simplified banner rendering and fixed empty partner URL

* Greatly simplified the code to generate banner
* Properly handle missing partner URL
* Removed impossible "display:None" style

Change-Id: Icae36b7126e9e08f91785947d0cab7e6ad7c2c00
---
M includes/PageRenderingHooks.php
M includes/ZeroConfigContent.php
2 files changed, 34 insertions(+), 40 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/66/90566/1

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index e400928..4d94f3c 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -450,54 +450,48 @@
         * @return string
         */
        public function renderBanner( $config, $lang = null, $sitename = null, 
$wap = false ) {
-               $bannerText = self::getBannerText( $config, $lang, $sitename );
-               if ( $bannerText !== false ) {
-                       $billingURL = $config['bannerUrl'];
-                       $billingURL = $this->makeRedirect( $billingURL );
-                       $carrierLink = Html::rawElement( 'a', array( 'href' => 
$billingURL ), $bannerText );
-                       if ( !$config['bannerWarning'] ) {
-                               preg_match( '/<a href="(.+)">/', $carrierLink, 
$match );
-                               if ( isset( $match[1] ) ) {
-                                       $originalHref = $match[1];
-                                       $info = parse_url( $originalHref );
-                                       if ( isset( $info['query'] ) ) {
-                                               $query = $info['query'];
-                                               parse_str( html_entity_decode( 
$query ), $queryArray );
-                                               if ( isset( 
$queryArray['returnto'] ) ) {
-                                                       $carrierLink = 
str_replace( $originalHref, $queryArray['returnto'], $carrierLink );
-                                               }
-                                       }
-                               }
+               $banner = self::getBannerText( $config, $lang, $sitename );
+               if ( !$banner ) {
+                       return '';
+               }
+               if ( !$wap ) {
+                       $background = $config['background'];
+                       $foreground = $config['foreground'];
+               }
+               $billingURL = $config['bannerUrl'];
+               if ( $billingURL ) {
+                       if ( $config['bannerWarning'] ) {
+                               $billingURL = $this->makeRedirect( $billingURL 
);
                        }
-               } else {
-                       $carrierLink = '';
+                       $attr = array( 'href' => $billingURL );
+                       if ( !$wap ) {
+                               $attr['style'] = "color:$foreground;";
+                       }
+                       $banner = Html::rawElement( 'a', $attr, $banner );
                }
 
                if ( $wap ) {
-                       $banner = $carrierLink !== '' ? Html::rawElement( 'p', 
null, $carrierLink ) : '';
+                       $banner = $banner !== '' ? Html::rawElement( 'p', null, 
$banner ) : '';
                } else {
-                       $background = $config['background'];
-                       $foreground = $config['foreground'];
-                       $carrierLink = str_replace(
-                               '<a href="',
-                               "<a style=\"color:$foreground;\" href=\"",
-                               $carrierLink );
-
-                       $bannerText = Html::rawElement( 'span',
-                               array(
-                                       'class' => 'mw-mf-message',
-                                       'id' => 'zero-rated-banner-text',
-                                       'style' => $config['fontSize'] !== '' ? 
' font-size:' . $config['fontSize'] . ';' : ''
-                               ),
-                               $carrierLink );
+                       $attr = array(
+                               'class' => 'mw-mf-message',
+                               'id' => 'zero-rated-banner-text',
+                       );
+                       $style = $config['fontSize'] !== '' ? 'font-size:' . 
$config['fontSize'] . ';' : '';
+                       if ( !$billingURL ) {
+                               $style .= "color:$foreground;";
+                       }
+                       if ( $style !== '' ) {
+                               $attr['style'] = $style;
+                       }
+                       $banner = Html::rawElement( 'span', $attr, $banner );
                        $dismissTitle = wfMessage( 
'zero-rated-mobile-access-dismiss-notification' )->escaped();
-                       $displayNone = $carrierLink === '' ? 'display:none;' : 
'';
                        $banner = <<<END
-<div id="zero-rated-banner" class="mw-mf-banner" 
style="background:$background;color:$foreground;$displayNone">
+<div id="zero-rated-banner" class="mw-mf-banner" 
style="background:$background;color:$foreground;">
 <button class="notify-close" style="background:$background;" 
title="$dismissTitle">
 <span class="notify-close-x" 
style="background:$background;border-color:$foreground;color:$foreground;">&#120;</span>
 </button>
-$bannerText
+$banner
 </div>
 END;
                }
diff --git a/includes/ZeroConfigContent.php b/includes/ZeroConfigContent.php
index 8e58619..0cea298 100644
--- a/includes/ZeroConfigContent.php
+++ b/includes/ZeroConfigContent.php
@@ -179,8 +179,8 @@
                        $lang = Language::factory( $langCode );
                        // Get localized "wikipedia" sitename. If null, will 
use default {{SITENAME}}
                        $sitename = $wgConf->get( 'wgSitename', str_replace( 
'-', '_', $langCode ) . 'wiki' );
-                       $td = $td = Xml::tags( 'td', null,
-                               $state->renderBanner( $conf, $lang, $sitename ) 
);
+                       $banner = $state->renderBanner( $conf, $lang, $sitename 
);
+                       $td = $td = Xml::tags( 'td', null, $banner ?: '???' );
                        $rows[] = Xml::tags( 'tr', null, $th . $td );
                }
                $res = Xml::tags( 'table', array( 'class' => 
'mw-zero-config-banners' ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icae36b7126e9e08f91785947d0cab7e6ad7c2c00
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to