Awight has uploaded a new change for review.

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

Change subject: Revert "Remove unused banner variance parameters"
......................................................................

Revert "Remove unused banner variance parameters"

This reverts commit bc023091fe4c788a8695e78d768151ee7692b11f.

Conflicts:
        modules/ext.centralNotice.bannerController/bannerController.js

Change-Id: I91d3480e068f5bf3e3b36a55f9b7c44826490394
---
M includes/BannerRenderer.php
M includes/MixinController.php
M modules/ext.centralNotice.bannerController/bannerController.js
M special/SpecialBannerLoader.php
M special/SpecialCentralNoticeBanners.php
5 files changed, 60 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/31/188131/1

diff --git a/includes/BannerRenderer.php b/includes/BannerRenderer.php
index b42c772..8b64845 100644
--- a/includes/BannerRenderer.php
+++ b/includes/BannerRenderer.php
@@ -20,16 +20,24 @@
 
        protected $mixinController = null;
 
-       protected $debug;
-
-       function __construct( IContextSource $context, Banner $banner, 
$campaignName = null, $debug = false ) {
+       function __construct( IContextSource $context, Banner $banner, 
$campaignName = null, AllocationContext $allocContext = null ) {
                $this->context = $context;
 
                $this->banner = $banner;
                $this->campaignName = $campaignName;
-               $this->debug = $debug;
 
-               $this->mixinController = new MixinController( $this->context, 
$this->banner->getMixins() );
+               if ( $allocContext === null ) {
+                       /**
+                        * This should only be used when banners are previewed 
in management forms.
+                        * TODO: set realistic context in the admin ui, drawn 
from the campaign
+                        * configuration and current translation settings.
+                        */
+                       $this->allocContext = new AllocationContext( 'XX', 
'en', 'wikipedia', true, 'desktop', 0 );
+               } else {
+                       $this->allocContext = $allocContext;
+               }
+
+               $this->mixinController = new MixinController( $this->context, 
$this->banner->getMixins(), $allocContext );
 
                //FIXME: it should make sense to do this:
                // $this->mixinController->registerMagicWord( 'campaign', 
array( $this, 'getCampaign' ) );
@@ -120,7 +128,7 @@
 
                if ( $snippets ) {
                        foreach ( $snippets as $mixin => $code ) {
-                               if ( !$this->debug ) {
+                               if ( 
!$this->context->getRequest()->getFuzzyBool( 'debug' ) ) {
                                        $code = JavaScriptMinifier::minify( 
$code );
                                }
 
diff --git a/includes/MixinController.php b/includes/MixinController.php
index 8567423..34e33ee 100644
--- a/includes/MixinController.php
+++ b/includes/MixinController.php
@@ -5,9 +5,11 @@
 
        protected $magicWords = array();
        protected $uiContext;
+       protected $allocContext;
 
-       function __construct( IContextSource $uiContext, $mixins ) {
+       function __construct( IContextSource $uiContext, $mixins, 
AllocationContext $allocContext = null ) {
                $this->uiContext = $uiContext;
+               $this->allocContext = $allocContext;
                $this->mixins = $mixins;
 
                $this->loadPhp();
@@ -17,6 +19,10 @@
                return $this->uiContext;
        }
 
+       function getAllocContext() {
+               return $this->allocContext;
+       }
+
        function getMagicWords() {
                $words = array_keys( $this->magicWords );
                sort( $words );
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index 9e047fc..8f83f2c 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -147,6 +147,10 @@
                                banner: bannerName,
                                campaign: campaign,
                                uselang: mw.config.get( 'wgUserLanguage' ),
+                               db: mw.config.get( 'wgDBname' ),
+                               project: mw.config.get( 'wgNoticeProject' ),
+                               country: mw.centralNotice.data.country,
+                               device: mw.centralNotice.data.device,
                                debug: mw.centralNotice.data.getVars.debug
                        };
 
@@ -163,7 +167,14 @@
                },
                loadRandomBanner: function () {
 
-                       var loadBannerQueryParams,
+                       var fetchBannerQueryParams = {
+                                       uselang: mw.config.get( 
'wgUserLanguage' ),
+                                       project: mw.config.get( 
'wgNoticeProject' ),
+                                       anonymous: mw.config.get( 'wgUserName' 
) === null,
+                                       country: mw.centralNotice.data.country,
+                                       device: mw.centralNotice.data.device,
+                                       debug: 
mw.centralNotice.data.getVars.debug
+                               },
                                scriptUrl;
 
                        // Either choose the banner on the client, or call the 
server to get
@@ -193,15 +204,11 @@
 
                                // Only fetch a banner if we need to :)
                                if ( mw.centralNotice.data.banner ) {
-                                       loadBannerQueryParams = {
-                                               banner: 
mw.centralNotice.data.banner,
-                                               campaign: 
mw.centralNotice.data.campaign,
-                                               uselang: mw.config.get( 
'wgUserLanguage' ),
-                                               debug: 
mw.centralNotice.data.getVars.debug
-                                       };
+                                       fetchBannerQueryParams.banner = 
mw.centralNotice.data.banner;
+                                       fetchBannerQueryParams.campaign = 
mw.centralNotice.data.campaign;
 
-                                       scriptUrl = new mw.Uri( mw.config.get( 
'wgCentralSelectedBannerDispatcher' ) );
-                                       scriptUrl.extend( loadBannerQueryParams 
);
+                                       scriptUrl = mw.config.get( 
'wgCentralSelectedBannerDispatcher' ) +
+                                               '?' + $.param( 
fetchBannerQueryParams );
 
                                        // This will call insertBanner() after 
the banner is retrieved
                                        $.ajax( {
@@ -220,20 +227,11 @@
 
                        } else {
                                var RAND_MAX = 30;
+                               fetchBannerQueryParams.slot = Math.floor( 
Math.random() * RAND_MAX ) + 1;
+                               fetchBannerQueryParams.bucket = 
mw.centralNotice.data.bucket;
 
-                               loadBannerQueryParams = {
-                                       uselang: mw.config.get( 
'wgUserLanguage' ),
-                                       project: mw.config.get( 
'wgNoticeProject' ),
-                                       anonymous: mw.config.get( 'wgUserName' 
) === null,
-                                       country: mw.centralNotice.data.country,
-                                       device: mw.centralNotice.data.device,
-                                       debug: 
mw.centralNotice.data.getVars.debug,
-                                       slot: Math.floor( Math.random() * 
RAND_MAX ) + 1,
-                                       bucket: mw.centralNotice.data.bucket
-                               };
-
-                               scriptUrl = new mw.Uri( mw.config.get( 
'wgCentralBannerDispatcher' ) );
-                               scriptUrl.extend( loadBannerQueryParams );
+                               scriptUrl = mw.config.get( 
'wgCentralBannerDispatcher' ) +
+                                       '?' + $.param( fetchBannerQueryParams );
 
                                $.ajax( {
                                        url: scriptUrl.toString,
diff --git a/special/SpecialBannerLoader.php b/special/SpecialBannerLoader.php
index 8ab1229..692a90b 100644
--- a/special/SpecialBannerLoader.php
+++ b/special/SpecialBannerLoader.php
@@ -9,7 +9,7 @@
        /** @var string Name of the campaign that the banner belongs to.*/
        public $campaignName;
 
-       protected $debug;
+       public $allocContext = null;
 
        function __construct() {
                // Register special page
@@ -34,21 +34,30 @@
        function getParams() {
                $request = $this->getRequest();
 
-               // FIXME: Don't allow a default language.
                $language = $this->getLanguage()->getCode();
 
-               $this->campaignName = $request->getText( 'campaign' );
-               $this->bannerName = $request->getText( 'banner' );
-               $this->debug = $request->getFuzzyBool( 'debug' );
+               $project = $this->getSanitized( 'project', 
ApiCentralNoticeAllocations::PROJECT_FILTER );
+               $country = $this->getSanitized( 'country', 
ApiCentralNoticeAllocations::LOCATION_FILTER );
+               $anonymous = ( $this->getSanitized( 'anonymous', 
ApiCentralNoticeAllocations::ANONYMOUS_FILTER ) === 'true' );
+               $bucket = intval( $this->getSanitized( 'bucket', 
ApiCentralNoticeAllocations::BUCKET_FILTER ) );
+               $device = $this->getSanitized( 'device', 
ApiCentralNoticeAllocations::DEVICE_NAME_FILTER );
 
                $required_values = array(
-                       $this->campaignName, $this->bannerName, $language
+                       $project, $language, $country, $anonymous, $bucket, 
$device
                );
                foreach ( $required_values as $value ) {
                        if ( is_null( $value ) ) {
                                throw new MissingRequiredParamsException();
                        }
                }
+
+               $this->allocContext = new AllocationContext(
+                       $country, $language, $project,
+                       $anonymous, $device, $bucket
+               );
+
+               $this->campaignName = $request->getText( 'campaign' );
+               $this->bannerName = $request->getText( 'banner' );
        }
 
        function getSanitized( $param, $filter ) {
@@ -91,7 +100,7 @@
                if ( !$banner->exists() ) {
                        throw new EmptyBannerException( $bannerName );
                }
-               $bannerRenderer = new BannerRenderer( $this->getContext(), 
$banner, $this->campaignName, $this->debug );
+               $bannerRenderer = new BannerRenderer( $this->getContext(), 
$banner, $this->campaignName, $this->allocContext );
 
                $bannerHtml = $bannerRenderer->toHtml();
 
diff --git a/special/SpecialCentralNoticeBanners.php 
b/special/SpecialCentralNoticeBanners.php
index 7408d2c..bd66ca5 100644
--- a/special/SpecialCentralNoticeBanners.php
+++ b/special/SpecialCentralNoticeBanners.php
@@ -917,8 +917,10 @@
                $langContext = new DerivativeContext( $this->getContext() );
 
                foreach ( $langs as $lang ) {
+                       // HACK: We need to unify these two contexts...
                        $langContext->setLanguage( $lang );
-                       $bannerRenderer = new BannerRenderer( $langContext, 
$banner, 'test' );
+                       $allocContext = new AllocationContext( 'XX', $lang, 
'wikipedia', true, 'desktop', 0 );
+                       $bannerRenderer = new BannerRenderer( $langContext, 
$banner, 'test', $allocContext );
 
                        // Link and Preview all available translations
                        $htmlOut .= Xml::tags(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I91d3480e068f5bf3e3b36a55f9b7c44826490394
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

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

Reply via email to