jenkins-bot has submitted this change and it was merged.
Change subject: Large banner limit mixin
......................................................................
Large banner limit mixin
In campaigns with this mixin enabled, a reader will see a large
banner only once, then will only see small banners for a configurable
period.
Requires a 4-bucket campaign with large banners in A & B and small
banners in C & D.
Transitions readers from bucket A to C and B to D, or optionally to
either of C and D randomly.
Cookie name is configurable, but defaults to same as on-wiki scripts
for compatibility.
TODO: after on-wiki scripts are no longer in use, move indicator to
localStorage when available.
Bug: T90919
Change-Id: Idac967fc2c4edb1d35350a2c9611c53c1d5a8d36
---
M CentralNotice.modules.php
M CentralNotice.php
M i18n/en.json
M i18n/qqq.json
M resources/subscribing/ext.centralNotice.display.state.js
A resources/subscribing/ext.centralNotice.largeBannerLimit.js
6 files changed, 135 insertions(+), 2 deletions(-)
Approvals:
AndyRussG: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CentralNotice.modules.php b/CentralNotice.modules.php
index 0a6c530..193e952 100644
--- a/CentralNotice.modules.php
+++ b/CentralNotice.modules.php
@@ -162,6 +162,14 @@
'centralnotice-impression-diet-restart-cycle-delay-help',
'centralnotice-impression-diet-skip-initial',
'centralnotice-impression-diet-skip-initial-help',
+
+ // Large banner limit
+ 'centralnotice-large-banner-limit-days',
+ 'centralnotice-large-banner-limit-days-help',
+ 'centralnotice-large-banner-limit-randomize',
+ 'centralnotice-large-banner-limit-randomize-help',
+ 'centralnotice-large-banner-limit-cookie-name',
+ 'centralnotice-large-banner-limit-cookie-name-help',
)
);
@@ -254,6 +262,17 @@
'targets' => array( 'desktop', 'mobile' ),
);
+$wgResourceModules[ 'ext.centralNotice.largeBannerLimit' ] = array(
+ 'localBasePath' => $dir . '/resources',
+ 'remoteExtPath' => 'CentralNotice/resources',
+ 'scripts' => 'subscribing/ext.centralNotice.largeBannerLimit.js',
+ 'dependencies' => array(
+ 'ext.centralNotice.display',
+ 'mediawiki.cookie',
+ ),
+ 'targets' => array( 'desktop', 'mobile' ),
+);
+
$wgResourceModules[ 'ext.centralNotice.legacySupport' ] = array(
'localBasePath' => $dir . '/resources',
'remoteExtPath' => 'CentralNotice/resources',
diff --git a/CentralNotice.php b/CentralNotice.php
index d25a50c..9c989b1 100644
--- a/CentralNotice.php
+++ b/CentralNotice.php
@@ -322,6 +322,30 @@
),
),
),
+ 'largeBannerLimit' => array(
+ 'module' => 'ext.centralNotice.largeBannerLimit',
+ 'nameMsg' => 'centralnotice-large-banner-limit',
+ 'helpMsg' => 'centralnotice-large-banner-limit-help',
+ 'parameters' => array(
+ 'days' => array(
+ 'type' => 'integer',
+ 'labelMsg' =>
'centralnotice-large-banner-limit-days',
+ 'helpMsg' =>
'centralnotice-large-banner-limit-days-help',
+ 'defaultValue' => 250,
+ ),
+ 'randomize' => array(
+ 'type' => 'boolean',
+ 'labelMsg' =>
'centralnotice-large-banner-limit-randomize',
+ 'helpMsg' =>
'centralnotice-large-banner-limit-randomize-help',
+ ),
+ 'cookieName' => array(
+ 'type' => 'string',
+ 'labelMsg' =>
'centralnotice-large-banner-limit-cookie-name',
+ 'helpMsg' =>
'centralnotice-large-banner-limit-cookie-name-help',
+ 'defaultValue' =>
'centralnotice-frbanner-seen-fullscreen',
+ ),
+ ),
+ ),
);
/* Setup */
diff --git a/i18n/en.json b/i18n/en.json
index 618fcbb..d9c693b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -283,5 +283,13 @@
"centralnotice-impression-diet-restart-cycle-delay": "How long to wait
before restarting the cycle, in seconds (optional)",
"centralnotice-impression-diet-restart-cycle-delay-help": "Defaults to
0, which means readers will experience a single cycle, and then we stop
displaying banners.",
"centralnotice-impression-diet-skip-initial": "Number of initial
impressions to skip (optional)",
- "centralnotice-impression-diet-skip-initial-help": "Defaults to 0,
which will not skip any impressions. When the cycle begins, we will skip this
many potential impressions before displaying a banner."
+ "centralnotice-impression-diet-skip-initial-help": "Defaults to 0,
which will not skip any impressions. When the cycle begins, we will skip this
many potential impressions before displaying a banner.",
+ "centralnotice-large-banner-limit": "Large banner limit and switch",
+ "centralnotice-large-banner-limit-help": "Show a large banner once,
then switch to small banners. Place large banners in buckets A and B and small
banners in buckets C and D.",
+ "centralnotice-large-banner-limit-days": "Length of suppression",
+ "centralnotice-large-banner-limit-days-help": "Number of days to
suppress large banner display after initial impression.",
+ "centralnotice-large-banner-limit-randomize": "Randomize bucket
transition",
+ "centralnotice-large-banner-limit-randomize-help": "Normal bucket
transition is A to C, B to D. When checked, readers will randomly move to
buckets C or D.",
+ "centralnotice-large-banner-limit-cookie-name": "Large banner cookie
name",
+ "centralnotice-large-banner-limit-cookie-name-help": "Large banner
display is suppressed across campaigns with the same cookie. Default value
'centralnotice-frbanner-seen-fullscreen' is compatible with on-wiki fundraising
scripts."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 9e8ca18..ca9888e 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -307,5 +307,13 @@
"centralnotice-impression-diet-restart-cycle-delay": "Label for the
form control to set cycle restart delay",
"centralnotice-impression-diet-restart-cycle-delay-help": "Help text
for form control.",
"centralnotice-impression-diet-skip-initial": "Label for the form
control to skip initial impressions",
- "centralnotice-impression-diet-skip-initial-help": "Help text for form
control"
+ "centralnotice-impression-diet-skip-initial-help": "Help text for form
control",
+ "centralnotice-large-banner-limit": "Label for the large banner limit
mixin",
+ "centralnotice-large-banner-limit-help": "Help text for the large
banner limit mixin",
+ "centralnotice-large-banner-limit-days": "Label for the form control to
set large banner suppression length",
+ "centralnotice-large-banner-limit-days-help": "Help text for the form
control to set large banner suppression length",
+ "centralnotice-large-banner-limit-randomize": "Label for the form
control to randomize bucket transition",
+ "centralnotice-large-banner-limit-randomize-help": "Help text for the
form control to randomize bucket transition",
+ "centralnotice-large-banner-limit-cookie-name": "Label for the form
control to set large banner cookie name",
+ "centralnotice-large-banner-limit-cookie-name-help": "Help text for the
form control to set large banner cookie name"
}
diff --git a/resources/subscribing/ext.centralNotice.display.state.js
b/resources/subscribing/ext.centralNotice.display.state.js
index 5fd1c70..e9030b0 100644
--- a/resources/subscribing/ext.centralNotice.display.state.js
+++ b/resources/subscribing/ext.centralNotice.display.state.js
@@ -296,6 +296,10 @@
return status === STATUSES.BANNER_CANCELED;
},
+ isBannerShown: function() {
+ return status === STATUSES.BANNER_SHOWN;
+ },
+
setNoBannerAvailable: function() {
setStatus( STATUSES.NO_BANNER_AVAILABLE );
diff --git a/resources/subscribing/ext.centralNotice.largeBannerLimit.js
b/resources/subscribing/ext.centralNotice.largeBannerLimit.js
new file mode 100644
index 0000000..d9c602d
--- /dev/null
+++ b/resources/subscribing/ext.centralNotice.largeBannerLimit.js
@@ -0,0 +1,70 @@
+/**
+ * Large banner limit mixin. Shows readers a large banner once, then switches
+ * to small banners for a configurable number of days.
+ *
+ * Requires a campaign with four buckets. Buckets A and B are assumed to
contain
+ * large banners, and buckets C and D small banners.
+ *
+ * Replaces the following scripts:
+ *
https://meta.wikimedia.org/wiki/MediaWiki:FR2014/Resources/ShowHideCheckFullscreen.js
+ *
https://meta.wikimedia.org/wiki/MediaWiki:FR2014/Resources/ChangeBucket-AtoC-BtoD.js
+ */
+( function ( mw ) {
+ 'use strict';
+
+ var cn = mw.centralNotice,
+ forced = mw.util.getParamValue( 'force' ),
+ mixin = new cn.Mixin( 'largeBannerLimit' );
+
+ function isLarge() {
+ var currentBucket = cn.internal.bucketer.getBucket();
+ return ( currentBucket <= 1 );
+ }
+
+ function cookiesEnabled() {
+ var enabled;
+ // Set a cookie, then try to read it back
+ mw.cookie.set( 'cookieTest', 'lbl' );
+ enabled = ( mw.cookie.get( 'cookieTest' ) === 'lbl' );
+ // Clear it out
+ mw.cookie.set( 'cookieTest', null );
+ return enabled;
+ }
+
+ mixin.setPreBannerHandler( function( mixinParams ) {
+ var newBucket;
+
+ if ( forced ) {
+ return;
+ }
+
+ if ( isLarge() &&
+ ( !cookiesEnabled() || mw.cookie.get(
mixinParams.cookieName, '' ) )
+ ) {
+ // Move reader immediately into small banner bucket
+ if ( mixinParams.randomize ) {
+ newBucket = Math.floor( Math.random() * 2 ) +
2;
+ } else {
+ newBucket = cn.internal.bucketer.getBucket() +
2;
+ }
+ cn.setBucket( newBucket );
+ }
+ } );
+
+ mixin.setPostBannerHandler( function( mixinParams ) {
+ if ( isLarge() && !forced && cn.internal.state.isBannerShown()
) {
+ // Set a cookie to remember that the reader has just
seen a large banner
+ // The next time they are set to see one, they will be
moved into a
+ // small banner bucket by the pre-banner handler.
+ var options = {
+ expires: mixinParams.days * 24 * 60 * 60,
+ path: '/',
+ prefix: '' // Do not prefix cookie with wiki
name
+ };
+ mw.cookie.set( mixinParams.cookieName, Date.now(),
options );
+ }
+ } );
+
+ // Register the mixin
+ cn.registerCampaignMixin( mixin );
+} )( mediaWiki );
--
To view, visit https://gerrit.wikimedia.org/r/247460
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idac967fc2c4edb1d35350a2c9611c53c1d5a8d36
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits