Yurik has uploaded a new change for review.

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


Change subject: Refactored two confirmation funds into one
......................................................................

Refactored two confirmation funds into one

* renderChargeConfirmation & renderZeroRedirect() merged
* two Html::openElement + closeElement converted to rawElement

Change-Id: Ib5b3b73e804ef2e256e1cd914f55f454e3fe843e
---
M includes/PageRenderingHooks.php
1 file changed, 29 insertions(+), 45 deletions(-)


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

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index c2aef24..a90cc08 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -106,11 +106,22 @@
                }
 
                if ( $renderBanner && $renderWarning && $acceptBilling !== 
'yes' ) {
-                       $output = self::renderChargeConfirmation();
+                       $output = self::renderQuestion(
+                               str_replace(
+                                       '.wikipedia.org/',
+                                       '.m.wikipedia.org/',
+                                       wfExpandUrl( $wgRequest->appendQuery( 
'acceptbilling=yes' ), PROTO_CURRENT )
+                               )
+                       );
                        $out->clearHTML();
                        $out->setPageTitle( null );
                } elseif ( $wgRequest->getFuzzyBool( 'renderZeroRatedRedirect' 
) ) {
-                       $output = self::renderZeroRedirect();
+                       $output = self::renderQuestion(
+                               $wgRequest->appendQuery(
+                                       
'acceptbilling=yes&renderZeroRatedBanner=true&returnto='
+                                       . urlencode( $wgRequest->getVal( 
'returnto' ) ) ),
+                               true // isWarning
+                       );
                        $out->clearHTML();
                        $out->setPageTitle( null );
                } elseif ( $renderBanner ) {
@@ -132,7 +143,8 @@
                }
 
                if ( $output ) {
-                       $output = Html::openElement( 'div', array( 'id' => 
'zero-landing-page' ) ) . $output . Html::closeElement( 'div' );
+                       $output = Html::rawElement( 'div',
+                               array( 'id' => 'zero-landing-page' ), $output );
                        $out->addHTML( $output );
                }
 
@@ -159,8 +171,11 @@
                        $bannerText );
                $banner = Html::rawElement( 'div',
                        array( 'class' => 'mw-mf-banner 
mw-mf-banner-undismissable',
-                               'style' => 'display:none;', 'id' => 
'zero-rated-banner-red' ), $bannerText );
-               return Html::openElement( 'div', array( 'id' => 
'zero-landing-page' ) ) . $banner . Html::closeElement( 'div' );
+                               'style' => 'display:none;', 'id' => 
'zero-rated-banner-red' ),
+                       $bannerText );
+               return Html::rawElement( 'div',
+                       array( 'id' => 'zero-landing-page' ),
+                       $banner );
        }
 
        /**
@@ -225,17 +240,15 @@
 
 
        /**
+        * @param string $acceptUrl If user agrees, send them here
+        * @param bool $isWarning Adds mw-mf-banner-warning CSS class if true
         * @return string
         */
-       private static function renderChargeConfirmation() {
+       private static function renderQuestion( $acceptUrl, $isWarning = false 
) {
                global $wgRequest;
                $referrer = $wgRequest->getHeader( 'referer' );
                $acceptBillingYes = Html::rawElement( 'a',
-                       array( 'href' => str_replace(
-                               '.wikipedia.org/',
-                               '.m.wikipedia.org/',
-                               wfExpandUrl( $wgRequest->appendQuery( 
'acceptbilling=yes' ), PROTO_CURRENT )
-                       ) ),
+                       array( 'href' => $acceptUrl ),
                        wfMessage( 
'zero-rated-mobile-access-banner-text-data-charges-yes' )->escaped() );
                $acceptBillingNo = Html::rawElement( 'a',
                        array( 'href' => $wgRequest->appendQuery( 
'acceptbilling=no&returnto=' . urlencode( $referrer ) ) ),
@@ -246,41 +259,12 @@
                        wfMessage( 
'zero-rated-mobile-access-banner-text-data-charges' )
                                ->rawParams( $acceptBillingYes, 
$acceptBillingNo )->escaped()
                );
+               $cssClass = 'mw-mf-banner mw-mf-banner-undismissable';
+               if ( $isWarning ) {
+                       $cssClass .= 'mw-mf-banner-warning';
+               }
                $banner = Html::rawElement( 'div',
-                       array( 'class' => 'mw-mf-banner 
mw-mf-banner-undismissable',
-                               'style' => 'display:none;', 'id' => 
'zero-rated-banner-red' ), $bannerText );
-               return $banner;
-       }
-
-
-       /**
-        * @return string
-        */
-       private static function renderZeroRedirect() {
-               global $wgRequest;
-               $returnto = $wgRequest->getVal( 'returnto' );
-               $acceptBillingYes = Html::rawElement( 'a',
-                       array(
-                               'href' => $wgRequest->appendQuery(
-                                       
'renderZeroRatedBanner=true&acceptbilling=yes&returnto=' . urlencode( $returnto 
) )
-                       ),
-                       wfMessage( 
'zero-rated-mobile-access-banner-text-data-charges-yes' )->escaped()
-               );
-               $referrer = $wgRequest->getHeader( 'referer' );
-               $acceptBillingNo = Html::rawElement( 'a',
-                       array( 'href' => $wgRequest->appendQuery(
-                               'acceptbilling=no&returnto=' . urlencode( 
$referrer ) )
-                       ),
-                       wfMessage( 
'zero-rated-mobile-access-banner-text-data-charges-no' )->escaped()
-               );
-               $bannerText = Html::rawElement( 'div',
-                       array( 'class' => 'mw-mf-message',
-                               'id' => 'zero-rated-banner-text' ),
-                       wfMessage( 
'zero-rated-mobile-access-banner-text-data-charges' )
-                               ->rawParams( $acceptBillingYes, 
$acceptBillingNo )->escaped()
-               );
-               $banner = Html::rawElement( 'div',
-                       array( 'class' => 'mw-mf-banner 
mw-mf-banner-undismissable mw-mf-banner-warning',
+                       array( 'class' => $cssClass,
                                'style' => 'display:none;', 'id' => 
'zero-rated-banner-red' ), $bannerText );
                return $banner;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5b3b73e804ef2e256e1cd914f55f454e3fe843e
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