jenkins-bot has submitted this change and it was merged.
Change subject: Always Display Emergency Priority Banners
......................................................................
Always Display Emergency Priority Banners
We have a small problem right now where we need to make sure that people
have seen a banner (regarding VE) but probably still have hide cookies.
This patch tells the CN controller to always attempt to show an emergency
priority banner. This also means that the banner itself must now track its
hide/show status to avoid bugging people if that's required.
Change-Id: Iaf0de3c7043b00a6ce02d7bff95f5d618dad8fe1
---
M includes/Campaign.php
M modules/ext.centralNotice.bannerController/bannerController.js
M special/SpecialBannerLoader.php
M special/SpecialBannerRandom.php
4 files changed, 238 insertions(+), 9 deletions(-)
Approvals:
MarkTraceur: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Campaign.php b/includes/Campaign.php
index 10fc2fe..f4cbe49 100644
--- a/includes/Campaign.php
+++ b/includes/Campaign.php
@@ -1,6 +1,223 @@
<?php
class Campaign {
+
+ protected $id = null;
+ protected $name = null;
+
+ /** @var MWTimestamp Start datetime of campaign */
+ protected $start = null;
+
+ /** @var MWTimestamp End datetime of campaign */
+ protected $end = null;
+
+ /** @var int Priority level of the campaign, higher is more important */
+ protected $priority = null;
+
+ /** @var bool True if the campaign is enabled for showing */
+ protected $enabled = null;
+
+ /** @var bool True if the campaign is currently non editable */
+ protected $locked = null;
+
+ /** @var bool True if there is geo-targeting data for ths campaign */
+ protected $geotargeted = null;
+
+ /** @var int The number of buckets in this campaign */
+ protected $buckets = null;
+
+ /**
+ * Construct a lazily loaded CentralNotice campaign object
+ *
+ * @param string|int $campaignIdentifier Either an ID or name for the
campaign
+ */
+ public function __construct( $campaignIdentifier ) {
+ if ( is_int( $campaignIdentifier ) ) {
+ $this->id = $campaignIdentifier;
+ } else {
+ $this->name = $campaignIdentifier;
+ }
+ }
+
+ /**
+ * Get the unique numerical ID for this campaign
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return int
+ */
+ public function getId() {
+ if ( $this->id === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->id;
+ }
+
+ /**
+ * Get the unique name for this campaign
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return string
+ */
+ public function getName() {
+ if ( $this->name === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->name;
+ }
+
+ /**
+ * Get the start time for the campaign. Only applicable if the campaign
is enabled.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return MWTimestamp
+ */
+ public function getStartTime() {
+ if ( $this->start === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->start;
+ }
+
+ /**
+ * Get the end time for the campaign. Only applicable if the campaign
is enabled.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return MWTimestamp
+ */
+ public function getEndTime() {
+ if ( $this->end === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->end;
+ }
+
+ /**
+ * Get the priority level for this campaign. The larger this is the
higher the priority is.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return int
+ */
+ public function getPriority() {
+ if ( $this->priority === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->priority;
+ }
+
+ /**
+ * Returns the enabled/disabled status of the campaign.
+ *
+ * If a campaign is enabled it is eligible to be shown to users.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return bool
+ */
+ public function isEnabled() {
+ if ( $this->enabled === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->enabled;
+ }
+
+ /**
+ * Returns the locked/unlocked status of the campaign. A locked
campaign is not able to be
+ * edited until unlocked.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return bool
+ */
+ public function isLocked() {
+ if ( $this->locked === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->priority;
+ }
+
+ /**
+ * Returned the geotargeted status of this campaign. Will be true if
GeoIP information should
+ * be used to determine user eligibility.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return bool
+ */
+ public function isGeotargeted() {
+ if ( $this->geotargeted === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->geotargeted;
+ }
+
+ /**
+ * Get the number of buckets in this campaign.
+ *
+ * @throws CampaignExistenceException If lazy loading failed.
+ * @return int
+ */
+ public function getBuckets() {
+ if ( $this->priority === null ) {
+ $this->loadBasicSettings();
+ }
+
+ return $this->priority;
+ }
+
+ /**
+ * Load basic campaign settings from the database table cn_notices
+ *
+ * @throws CampaignExistenceException If the campaign doesn't exist
+ */
+ protected function loadBasicSettings() {
+ $db = CNDatabase::getDb();
+
+ // What selector are we using?
+ if ( $this->id !== null ) {
+ $selector = array( 'not_id' => $this->id );
+ } elseif ( $this->name !== null ) {
+ $selector = array( 'not_name' => $this->name );
+ } else {
+ throw new CampaignExistenceException( "No valid
database key available for campaign." );
+ }
+
+ // Get campaign info from database
+ $row = $db->selectRow(
+ array('notices' => 'cn_notices'),
+ array(
+ 'not_id',
+ 'not_name',
+ 'not_start',
+ 'not_end',
+ 'not_enabled',
+ 'not_preferred',
+ 'not_locked',
+ 'not_geo',
+ 'not_buckets',
+ ),
+ $selector,
+ __METHOD__
+ );
+ if ( $row ) {
+ $this->start = new MWTimestamp( $row->not_start );
+ $this->end = new MWTimestamp( $row->not_end );
+ $this->enabled = (bool)$row->not_enabled;
+ $this->priority = (int)$row->not_preferred;
+ $this->locked = (bool)$row->not_locked;
+ $this->geotargeted = (bool)$row->not_geo;
+ $this->buckets = (int)$row->not_buckets;
+ } else {
+ throw new CampaignExistenceException(
+ "Campaign could not be retrieved from database
with id '{$this->id}' or name '{$this->name}'"
+ );
+ }
+ }
+
/**
* See if a given campaign exists in the database
*
@@ -898,3 +1115,5 @@
return $logs;
}
}
+
+class CampaignExistenceException extends MWException {}
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js
b/modules/ext.centralNotice.bannerController/bannerController.js
index 3f126b6..cc24170 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -273,8 +273,9 @@
reason: 'mobile'
}
} else if (
- $.cookie( 'centralnotice_' +
encodeURIComponent( mw.centralNotice.data.bannerType ) ) === 'hide' &&
- !mw.centralNotice.data.testing
+ bannerJson.priority < 3 && /* A priority of 3
is Emergency and cannot be hidden */
+ !mw.centralNotice.data.testing && /* And we
want to see what we're testing! :) */
+ $.cookie( 'centralnotice_' +
encodeURIComponent( mw.centralNotice.data.bannerType ) ) === 'hide'
) {
// The banner was hidden by a bannertype hide
cookie and we're not testing
impressionResultData = {
diff --git a/special/SpecialBannerLoader.php b/special/SpecialBannerLoader.php
index e87cbaf..1073a87 100644
--- a/special/SpecialBannerLoader.php
+++ b/special/SpecialBannerLoader.php
@@ -3,11 +3,11 @@
* Renders banner contents as jsonp.
*/
class SpecialBannerLoader extends UnlistedSpecialPage {
- /** @var string Name of the choosen banner */
+ /** @var string Name of the chosen banner */
public $bannerName;
- /** @var string Name of the campaign that the banner belongs to. Will
be 'undefined' if not attatched. */
- public $campaign;
+ /** @var string Name of the campaign that the banner belongs to.*/
+ public $campaignName;
public $allocContext = null;
@@ -59,7 +59,7 @@
$anonymous, $device, $bucket
);
- $this->campaign = $request->getText( 'campaign' );
+ $this->campaignName = $request->getText( 'campaign' );
$this->bannerName = $request->getText( 'banner' );
}
@@ -99,7 +99,7 @@
throw new EmptyBannerException( $bannerName );
}
$banner = new Banner( $bannerName );
- $bannerRenderer = new BannerRenderer( $this->getContext(),
$banner, $this->campaign, $this->allocContext );
+ $bannerRenderer = new BannerRenderer( $this->getContext(),
$banner, $this->campaignName, $this->allocContext );
$bannerHtml = $bannerRenderer->toHtml();
@@ -113,11 +113,20 @@
$bannerArray = array(
'bannerName' => $bannerName,
'bannerHtml' => $bannerHtml,
- 'campaign' => $this->campaign,
+ 'campaign' => $this->campaignName,
'fundraising' => $settings['fundraising'],
'autolink' => $settings['autolink'],
'landingPages' => explode( ", ",
$settings['landingpages'] ),
);
+
+ try {
+ $campaignObj = new Campaign( $this->campaignName );
+ $priority = $campaignObj->getPriority();
+ } catch ( CampaignExistenceException $ex ) {
+ $priority = 0;
+ }
+ $bannerArray['priority'] = $priority;
+
$bannerJson = FormatJson::encode( $bannerArray );
$preload = $bannerRenderer->getPreloadJs();
diff --git a/special/SpecialBannerRandom.php b/special/SpecialBannerRandom.php
index 1ec10cd..1d0acd5 100644
--- a/special/SpecialBannerRandom.php
+++ b/special/SpecialBannerRandom.php
@@ -29,7 +29,7 @@
if ( $banner ) {
$this->bannerName = $banner['name'];
- $this->campaign = $banner['campaign'];
+ $this->campaignName = $banner['campaign'];
}
}
--
To view, visit https://gerrit.wikimedia.org/r/71751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaf0de3c7043b00a6ce02d7bff95f5d618dad8fe1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits