r95527 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95526‎ | r95527 | r95528 >
Date:21:29, 25 August 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.sql (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.php
@@ -110,7 +110,6 @@
111111
112112 $wgAutoloadClasses['CentralNotice'] = $specialDir . 'SpecialCentralNotice.php';
113113 $wgAutoloadClasses['CentralNoticeDB'] = $dir . 'CentralNotice.db.php';
114 - $wgAutoloadClasses['TemplatePager'] = $dir . 'TemplatePager.php';
115114
116115 if ( $wgNoticeInfrastructure ) {
117116 $wgSpecialPages['CentralNotice'] = 'CentralNotice';
@@ -124,6 +123,11 @@
125124
126125 $wgSpecialPages['CentralNoticeLogs'] = 'SpecialCentralNoticeLogs';
127126 $wgAutoloadClasses['SpecialCentralNoticeLogs'] = $specialDir . 'SpecialCentralNoticeLogs.php';
 127+
 128+ $wgAutoloadClasses['TemplatePager'] = $dir . 'TemplatePager.php';
 129+ $wgAutoloadClasses['CentralNoticePager'] = $dir . 'CentralNoticePager.php';
 130+ $wgAutoloadClasses['CentralNoticeLogPager'] = $dir . 'CentralNoticeLogPager.php';
 131+ $wgAutoloadClasses['CentralNoticeBannerLogPager'] = $dir . 'CentralNoticeBannerLogPager.php';
128132 }
129133 }
130134
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.php
___________________________________________________________________
Modified: svn:mergeinfo
131135 Merged /trunk/extensions/CentralNotice/CentralNotice.php:r92918-95526
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.sql
___________________________________________________________________
Modified: svn:mergeinfo
132136 Merged /trunk/extensions/CentralNotice/CentralNotice.sql:r92918-95526
Index: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.db.php
@@ -5,6 +5,9 @@
66 exit( 1 );
77 }
88
 9+/**
 10+ * Static methods that retrieve information from the database.
 11+ */
912 class CentralNoticeDB {
1013
1114 /* Functions */
@@ -166,7 +169,7 @@
167170 $campaign['languages'] = implode( ", ", $languages );
168171 $campaign['countries'] = implode( ", ", $geo_countries );
169172
170 - $bannersIn = CentralNoticeDB::getCampaignBanners( $row->not_id );
 173+ $bannersIn = CentralNoticeDB::getCampaignBanners( $row->not_id, true );
171174 $bannersOut = array();
172175 // All we want are the banner names and weights
173176 foreach ( $bannersIn as $key => $row ) {
@@ -182,15 +185,21 @@
183186
184187 /*
185188 * Given one or more campaign ids, return all banners bound to them
186 - * @param $campaigns An array of id numbers
 189+ * @param $campaigns array of id numbers
 190+ * @param $logging boolean whether or not request is for logging (optional)
187191 * @return a 2D array of banners with associated weights and settings
188192 */
189 - static function getCampaignBanners( $campaigns ) {
 193+ static function getCampaignBanners( $campaigns, $logging = false ) {
190194 global $wgCentralDBname;
191195
192 - $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 196+ // If logging, read from the master database to avoid concurrency problems
 197+ if ( $logging ) {
 198+ $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
 199+ } else {
 200+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 201+ }
193202
194 - $templates = array();
 203+ $banners = array();
195204
196205 if ( $campaigns ) {
197206 $res = $dbr->select(
@@ -217,21 +226,56 @@
218227 );
219228
220229 foreach ( $res as $row ) {
221 - $templates[] = array(
222 - 'name' => $row->tmp_name,
223 - 'weight' => intval( $row->tmp_weight ),
224 - 'display_anon' => intval( $row->tmp_display_anon ),
225 - 'display_account' => intval( $row->tmp_display_account ),
226 - 'fundraising' => intval( $row->tmp_fundraising ),
227 - 'landing_pages' => $row->tmp_landing_pages,
228 - 'campaign' => $row->not_name
 230+ $banners[] = array(
 231+ 'name' => $row->tmp_name, // name of the banner
 232+ 'weight' => intval( $row->tmp_weight ), // weight assigned to the banner
 233+ 'display_anon' => intval( $row->tmp_display_anon ), // display to anonymous users?
 234+ 'display_account' => intval( $row->tmp_display_account ), // display to logged in users?
 235+ 'fundraising' => intval( $row->tmp_fundraising ), // fundraising banner?
 236+ 'landing_pages' => $row->tmp_landing_pages, // landing pages to link to
 237+ 'campaign' => $row->not_name // campaign the banner is assigned to
229238 );
230239 }
231240 }
232 - return $templates;
 241+ return $banners;
233242 }
234243
235244 /**
 245+ * Return settings for a banner
 246+ * @param $bannerName string name of banner
 247+ * @return an array of banner settings
 248+ */
 249+ static function getBannerSettings( $bannerName ) {
 250+ global $wgCentralDBname;
 251+
 252+ $banner = array();
 253+
 254+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 255+
 256+ $row = $dbr->selectRow( 'cn_templates',
 257+ array(
 258+ 'tmp_display_anon',
 259+ 'tmp_display_account',
 260+ 'tmp_fundraising',
 261+ 'tmp_landing_pages'
 262+ ),
 263+ array( 'tmp_name' => $bannerName ),
 264+ __METHOD__
 265+ );
 266+
 267+ if ( $row ) {
 268+ $banner = array(
 269+ 'anon' => $row->tmp_display_anon,
 270+ 'account' => $row->tmp_display_account,
 271+ 'fundraising' => $row->tmp_fundraising,
 272+ 'landingpages' => $row->tmp_landing_pages
 273+ );
 274+ }
 275+
 276+ return $banner;
 277+ }
 278+
 279+ /**
236280 * Lookup function for active banners under a given language/project/location. This function is
237281 * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for
238282 * each project.
@@ -307,15 +351,26 @@
308352 }
309353 }
310354
311 - $templates = array();
 355+ $banners = array();
312356 if ( $campaigns ) {
313357 // Pull all banners assigned to the campaigns
314 - $templates = CentralNoticeDB::getCampaignBanners( $campaigns );
 358+ $banners = CentralNoticeDB::getCampaignBanners( $campaigns );
315359 }
316 - return $templates;
 360+ return $banners;
317361 }
318362
319363 /*
 364+ * See if a given campaign exists in the database
 365+ */
 366+ public static function campaignExists( $campaignName ) {
 367+ global $wgCentralDBname;
 368+ $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
 369+
 370+ $eCampaignName = htmlspecialchars( $campaignName );
 371+ return (bool)$dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $eCampaignName ) );
 372+ }
 373+
 374+ /*
320375 * See if a given banner exists in the database
321376 */
322377 public static function bannerExists( $bannerName ) {
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.db.php
___________________________________________________________________
Added: svn:mergeinfo
323378 Merged /trunk/extensions/CentralNotice/CentralNotice.db.php:r62820-67552,67557,67559-71720,71725-71731,71734-71739,71748-71753,71774-71997,72058-72131,72136-73830,73847,73850,73852,73855,73959,73963,73973,73980,73983,73991,73994-73995,74000-74321,74325-74406,75376-75470,75567,75643,75646,75674,75680,75726,75849,75889,75908,75973,76141,76145,76333,76347,76351,76356-76358,76361,76363,76462,76543,76763,77622-79761,79780,79783-80145,80147-80148,80150,80152-80602,81461-83563,83565-91117,91146,91368-92408,92767,92918-95525
324379 Merged /trunk/phase3/extensions/CentralNotice/CentralNotice.db.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,77555,77558-77560,77563-77565,77573
325380 Merged /branches/wmf-deployment/extensions/CentralNotice/CentralNotice.db.php:r60970
326381 Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/CentralNotice.db.php:r67177,69199,76243,77266

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92917more banner setting loggingkaldari23:11, 22 July 2011
r95526Use addTable function...reedy21:25, 25 August 2011

Status & tagging log