Adamw has uploaded a new change for review.

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

Change subject: Add a UI for attaching mixins to banners
......................................................................

Add a UI for attaching mixins to banners

Also, propagate the "debug" parameter from the content page request to the
banner load ajax.  If debug is set on the banner load and a mixin is included,
the payload will not be minified.

Change-Id: Ie99c7363bc9bd1b3df4ed6cbb478744e9ecd6c0c
---
M CentralNotice.i18n.php
M includes/Banner.php
M modules/ext.centralNotice.bannerController/bannerController.js
M special/SpecialCentralNoticeBanners.php
4 files changed, 37 insertions(+), 27 deletions(-)


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

diff --git a/CentralNotice.i18n.php b/CentralNotice.i18n.php
index c7cd486..a74e6db 100644
--- a/CentralNotice.i18n.php
+++ b/CentralNotice.i18n.php
@@ -135,7 +135,8 @@
        'centralnotice-banner-autolink-help' => 'When enabled CentralNotice 
will automatically create a localised link to $3 with a landing page selected 
at random. There must be an anchor tag with $1 in the banner body.',
        'centralnotice-banner-landing-pages' => 'Landing pages 
(comma-separated)',
        'centralnotice-banner-landing-pages-default' => 'e.g. JimmyAppeal01',
-       'centralnotice-banner-mixins' => 'Mixins (comma-separated):',
+       'centralnotice-banner-mixins' => 'Mixins',
+       'centralnotice-banner-mixins-help' => 'Check each mixin that you want 
to be included during banner delivery.  See 
https://mediawiki.org/wiki/Extension:CentralNotice/Banner_mixins for more 
information.',
        'centralnotice-geo' => 'Geotargeted',
        'centralnotice-countries' => 'Countries',
        'centralnotice-global-allocation' => 'Global allocation',
@@ -499,6 +500,7 @@
        'centralnotice-banner-landing-pages' => 'Label for an input box. 
Landing pages are valid MediaWiki titles that donors are redirected to upon 
clicking a banner.',
        'centralnotice-banner-landing-pages-default' => 'Example valid landing 
pages for an input box placeholder text.',
        'centralnotice-banner-mixins' => 'Label for a list of banner 
"[[mw:Extension:CentralNotice/Banner_mixins|mixins]]", code components which 
can be reused between banners.',
+       'centralnotice-banner-mixins-help' => 'Help text for editing a list of 
"[[mw:Extension:CentralNotice/Banner_mixins|banner mixins]]", code components 
which can be reused between banners.',
        'centralnotice-geo' => 'Used to label a checkbox which activates 
geotargeting',
        'centralnotice-countries' => 'Used as column header of the table in 
[[Special:CentralNotice]].
 {{Related|Centralnotice-th}}
diff --git a/includes/Banner.php b/includes/Banner.php
index 12751da..f6fabd9 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -576,7 +576,7 @@
        /**
         * Set the banner mixins to enable.
         *
-        * @param string[]|string $mixins Names of mixins to enable on this 
banner. Valid values
+        * @param array $mixins Names of mixins to enable on this banner. Valid 
values
         * come from @see $wgNoticeMixins
         *
         * @throws MWException
@@ -587,21 +587,19 @@
 
                $this->populateMixinData();
 
-               $mixins = array_unique( array_values( (array)$mixins ) );
+               $mixins = array_unique( $mixins );
                sort( $mixins );
 
-               if ( array_keys( $this->mixins ) != $mixins ) {
-                       $this->mixins = array();
-                       foreach ( $mixins as $mixin ) {
-                               if ( !$mixin ) {
-                                       // Empty
-                                       continue;
-                               } elseif ( !array_key_exists( $mixin, 
$wgNoticeMixins ) ) {
-                                       throw new MWException( "Mixin does not 
exist: {$mixin}" );
-                               }
-                               $this->mixins[$mixin] = $wgNoticeMixins[$mixin];
-                       }
+               if ( $this->mixins != $mixins ) {
                        $this->markMixinDataDirty();
+               }
+
+               $this->mixins = array();
+               foreach ( $mixins as $mixin ) {
+                       if ( !array_key_exists( $mixin, $wgNoticeMixins ) ) {
+                               throw new MWException( "Mixin does not exist: 
{$mixin}" );
+                       }
+                       $this->mixins[$mixin] = $wgNoticeMixins[$mixin];
                }
 
                return $this;
@@ -1087,7 +1085,7 @@
                $destBanner->setCategory( $this->getCategory() );
                $destBanner->setAutoLink( $this->isAutoLinked(), 
$this->getAutoLinks() );
                $destBanner->setDevices( $this->getDevices() );
-               $destBanner->setMixins( $this->getMixins() );
+               $destBanner->setMixins( array_keys( $this->getMixins() ) );
                $destBanner->setPriorityLanguages( 
$this->getPriorityLanguages() );
 
                $destBanner->setBodyContent( $this->getBodyContent() );
@@ -1385,14 +1383,14 @@
         * @param $fundraising      integer flag for fundraising banner 
(optional)
         * @param $autolink         integer flag for automatically creating 
landing page links (optional)
         * @param $landingPages     string list of landing pages (optional)
-        * @param $mixins           string list of mixins (optional)
+        * @param $mixins           array list of mixins (optional)
         * @param $priorityLangs    array Array of priority languages for the 
translate extension
         * @param $devices          array Array of device names this banner is 
targeted at
         *
         * @return bool true or false depending on whether banner was 
successfully added
         */
        static function addTemplate( $name, $body, $user, $displayAnon, 
$displayAccount, $fundraising = 0,
-               $autolink = 0, $landingPages = '', $mixins = '', $priorityLangs 
= array(), $devices = array( 'desktop' )
+               $autolink = 0, $landingPages = '', $mixins = array(), 
$priorityLangs = array(), $devices = array( 'desktop' )
        ) {
                if ( $name == '' || !Banner::isValidBannerName( $name ) || 
$body == '' ) {
                        return 'centralnotice-null-string';
@@ -1413,8 +1411,6 @@
                array_walk( $landingPages, function ( &$x ) { $x = trim( $x ); 
} );
                $banner->setAutoLink( $autolink, $landingPages );
 
-               $mixins = explode( ",", $mixins );
-               array_walk( $mixins, function ( &$x ) { $x = trim( $x ); } );
                $banner->setMixins( $mixins );
 
                $banner->save( $user );
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index 02d8d36..3a86230 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -97,7 +97,8 @@
                                db: mw.config.get( 'wgDBname' ),
                                project: mw.config.get( 'wgNoticeProject' ),
                                country: mw.centralNotice.data.country,
-                               device: mw.centralNotice.data.device
+                               device: mw.centralNotice.data.device,
+                               debug: mw.centralNotice.data.getVars.debug
                        };
 
                        $.ajax({
@@ -116,7 +117,8 @@
                                bucket: mw.centralNotice.data.bucket,
                                country: mw.centralNotice.data.country,
                                device: mw.centralNotice.data.device,
-                               slot: Math.floor( Math.random() * RAND_MAX ) + 1
+                               slot: Math.floor( Math.random() * RAND_MAX ) + 
1,
+                               debug: mw.centralNotice.data.getVars.debug
                        };
                        var scriptUrl = mw.config.get( 
'wgCentralBannerDispatcher' ) + '?' + $.param( bannerDispatchQuery );
 
diff --git a/special/SpecialCentralNoticeBanners.php 
b/special/SpecialCentralNoticeBanners.php
index 22a76f2..452b6e5 100644
--- a/special/SpecialCentralNoticeBanners.php
+++ b/special/SpecialCentralNoticeBanners.php
@@ -337,7 +337,7 @@
        }
 
        protected function generateBannerEditForm() {
-               global $wgNoticeUseTranslateExtension, $wgNoticeFundraisingUrl, 
$wgLanguageCode;
+               global $wgNoticeMixins, $wgNoticeUseTranslateExtension, 
$wgNoticeFundraisingUrl, $wgLanguageCode;
 
                $languages = Language::fetchLanguageNames( 
$this->getLanguage()->getCode() );
                array_walk( $languages, function( &$val, $index ) { $val = 
"$index - $val"; } );
@@ -426,6 +426,20 @@
                if ( !$this->editable ) {
                        $formDescriptor[ 'landing-pages' ][ 'readonly' ] = true;
                }
+
+               $mixinNames = array_keys( $wgNoticeMixins );
+               $availableMixins = array_combine( $mixinNames, $mixinNames );
+               $selectedMixins = array_keys( $banner->getMixins() );
+               $formDescriptor['mixins'] = array(
+                       'section' => 'settings',
+                       'type' => 'multiselect',
+                       'disabled' => !$this->editable,
+                       'label-message' => 'centralnotice-banner-mixins',
+                       'help-message' => 'centralnotice-banner-mixins-help',
+                       'cssclass' => 'separate-form-element',
+                       'options' => $availableMixins,
+                       'default' => $selectedMixins,
+               );
 
                /* --- Translatable Messages Section --- */
                $messages = $banner->getMessageFieldsFromCache( 
$banner->getBodyContent() );
@@ -744,11 +758,7 @@
                array_walk( $landingPages, function ( &$x ) { $x = trim( $x ); 
} );
                $banner->setAutoLink( $formData[ 'create-landingpage-link' ], 
$landingPages );
 
-               /* TODO: Mixins
-               $mixins = explode( ",", $mixins );
-               array_walk( $mixins, function ( &$x ) { $x = trim( $x ); } );
-               $banner->setMixins( $mixins );
-               */
+               $banner->setMixins( $formData['mixins'] );
 
                $banner->save( $this->getUser() );
 

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

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

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

Reply via email to