Mwalker has submitted this change and it was merged.
Change subject: Reconstruct campaigns from logs
......................................................................
Reconstruct campaigns from logs
Change-Id: I4c0e275c211dde7fe661ed4077a5bc8100e51548
---
M includes/Banner.php
M includes/Campaign.php
M special/SpecialGlobalAllocation.php
3 files changed, 112 insertions(+), 0 deletions(-)
Approvals:
Mwalker: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Banner.php b/includes/Banner.php
index 74e45ab..b103f3e 100644
--- a/includes/Banner.php
+++ b/includes/Banner.php
@@ -348,6 +348,50 @@
}
/**
+ * FIXME: a little thin, it's just enough to get the job done
+ */
+ static function getHistoricalBanner( $name, $ts ) {
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
+ $id = Banner::getTemplateId( $name );
+
+ $newestLog = $dbr->selectRow(
+ "cn_template_log",
+ array(
+ "log_id" => "MAX(tmplog_id)",
+ ),
+ array(
+ "tmplog_timestamp <= $ts",
+ "tmplog_template_id = $id",
+ ),
+ __METHOD__
+ );
+
+ $row = $dbr->selectRow(
+ "cn_template_log",
+ array(
+ "display_anon" => "tmplog_end_anon",
+ "display_account" => "tmplog_end_account",
+ "fundraising" => "tmplog_end_fundraising",
+ "autolink" => "tmplog_end_autolink",
+ "landing_pages" => "tmplog_end_landingpages",
+ ),
+ array(
+ "tmplog_id = {$newestLog->log_id}",
+ ),
+ __METHOD__
+ );
+ $banner['display_anon'] = intval( $row->display_anon );
+ $banner['display_account'] = intval( $row->display_account );
+
+ $banner['fundraising'] = intval( $row->fundraising );
+ $banner['autolink'] = intval( $row->autolink );
+ $banner['landing_pages'] = explode( ", ", $row->landing_pages );
+
+ return $banner;
+ }
+
+ /**
* DEPRECATED, but included for backwards compatibility during upgrade
* Lookup function for active banners under a given
language/project/location. This function is
* called by SpecialBannerListLoader::getJsonList() in order to build
the banner list JSON for
diff --git a/includes/Campaign.php b/includes/Campaign.php
index 6d63c4b..a5422c9 100644
--- a/includes/Campaign.php
+++ b/includes/Campaign.php
@@ -188,6 +188,71 @@
}
/**
+ * Get all campaign configurations as of timestamp $ts
+ */
+ static function getHistoricalCampaigns( $ts ) {
+ global $wgCentralDBname;
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
+ $res = $dbr->select(
+ "cn_notice_log",
+ array(
+ "log_id" => "MAX(notlog_id)",
+ ),
+ array(
+ "notlog_timestamp <= $ts",
+ "notlog_end_start <= $ts",
+ "notlog_end_end >= $ts",
+ "notlog_end_enabled = 1",
+ ),
+ __METHOD__,
+ array(
+ "GROUP BY" => "notlog_not_id",
+ )
+ );
+
+ $banners = array();
+ $campaigns = array();
+ foreach ( $res as $row ) {
+ $singleRes = $dbr->select(
+ "cn_notice_log",
+ array(
+ "name" => "notlog_not_name",
+ "projects" => "notlog_end_projects",
+ "languages" => "notlog_end_languages",
+ "countries" => "notlog_end_countries",
+ "preferred" => "notlog_end_preferred",
+ "geo" => "notlog_end_geo",
+ "banners" => "notlog_end_banners",
+ "buckets" => "notlog_end_buckets",
+ ),
+ array(
+ "notlog_id = {$row->log_id}",
+ ),
+ __METHOD__
+ );
+
+ $campaign = $singleRes->fetchRow();
+ $campaign['banners'] = FormatJson::decode(
$campaign['banners'], true );
+ foreach ( $campaign['banners'] as $name => &$banner ) {
+ $historical_banner =
Banner::getHistoricalBanner( $name, $ts );
+
+ $banner['name'] = $name;
+
+ $campaign_info = array(
+ 'campaign' => $campaign['name'],
+ 'campaign_z_index' =>
$campaign['preferred'],
+ 'campaign_num_buckets' =>
$campaign['buckets'],
+ );
+
+ $banner = array_merge( $banner, $campaign_info,
$historical_banner );
+ }
+
+ $campaigns[] = $campaign;
+ }
+ return $campaigns;
+ }
+
+ /**
* Get all the campaigns in the database
*
* @return array an array of campaign names
diff --git a/special/SpecialGlobalAllocation.php
b/special/SpecialGlobalAllocation.php
index 55272c3..0f841a5 100644
--- a/special/SpecialGlobalAllocation.php
+++ b/special/SpecialGlobalAllocation.php
@@ -408,6 +408,9 @@
// This is annoying. Within the campaign, banners usually vary
by user
// logged-in status, and bucket. Determine the allocations and
// collapse any dimensions which do not vary.
+ //
+ // TODO: the allocation hash should also be used to collapse
groupings which
+ // are identical because of e.g. z-index
foreach ( array( true, false ) as $isAnon ) {
for ( $bucket = 0; $bucket < $numBuckets; $bucket++ ) {
$variations[$isAnon][$bucket] =
ApiCentralNoticeAllocations::getAllocationInformation(
--
To view, visit https://gerrit.wikimedia.org/r/55449
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4c0e275c211dde7fe661ed4077a5bc8100e51548
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits