| Index: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.php |
| — | — | @@ -110,7 +110,6 @@ |
| 111 | 111 | |
| 112 | 112 | $wgAutoloadClasses['CentralNotice'] = $specialDir . 'SpecialCentralNotice.php'; |
| 113 | 113 | $wgAutoloadClasses['CentralNoticeDB'] = $dir . 'CentralNotice.db.php'; |
| 114 | | - $wgAutoloadClasses['TemplatePager'] = $dir . 'TemplatePager.php'; |
| 115 | 114 | |
| 116 | 115 | if ( $wgNoticeInfrastructure ) { |
| 117 | 116 | $wgSpecialPages['CentralNotice'] = 'CentralNotice'; |
| — | — | @@ -124,6 +123,11 @@ |
| 125 | 124 | |
| 126 | 125 | $wgSpecialPages['CentralNoticeLogs'] = 'SpecialCentralNoticeLogs'; |
| 127 | 126 | $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'; |
| 128 | 132 | } |
| 129 | 133 | } |
| 130 | 134 | |
| Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.php |
| ___________________________________________________________________ |
| Modified: svn:mergeinfo |
| 131 | 135 | Merged /trunk/extensions/CentralNotice/CentralNotice.php:r92918-95526 |
| Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.sql |
| ___________________________________________________________________ |
| Modified: svn:mergeinfo |
| 132 | 136 | Merged /trunk/extensions/CentralNotice/CentralNotice.sql:r92918-95526 |
| Index: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.db.php |
| — | — | @@ -5,6 +5,9 @@ |
| 6 | 6 | exit( 1 ); |
| 7 | 7 | } |
| 8 | 8 | |
| | 9 | +/** |
| | 10 | + * Static methods that retrieve information from the database. |
| | 11 | + */ |
| 9 | 12 | class CentralNoticeDB { |
| 10 | 13 | |
| 11 | 14 | /* Functions */ |
| — | — | @@ -166,7 +169,7 @@ |
| 167 | 170 | $campaign['languages'] = implode( ", ", $languages ); |
| 168 | 171 | $campaign['countries'] = implode( ", ", $geo_countries ); |
| 169 | 172 | |
| 170 | | - $bannersIn = CentralNoticeDB::getCampaignBanners( $row->not_id ); |
| | 173 | + $bannersIn = CentralNoticeDB::getCampaignBanners( $row->not_id, true ); |
| 171 | 174 | $bannersOut = array(); |
| 172 | 175 | // All we want are the banner names and weights |
| 173 | 176 | foreach ( $bannersIn as $key => $row ) { |
| — | — | @@ -182,15 +185,21 @@ |
| 183 | 186 | |
| 184 | 187 | /* |
| 185 | 188 | * 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) |
| 187 | 191 | * @return a 2D array of banners with associated weights and settings |
| 188 | 192 | */ |
| 189 | | - static function getCampaignBanners( $campaigns ) { |
| | 193 | + static function getCampaignBanners( $campaigns, $logging = false ) { |
| 190 | 194 | global $wgCentralDBname; |
| 191 | 195 | |
| 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 | + } |
| 193 | 202 | |
| 194 | | - $templates = array(); |
| | 203 | + $banners = array(); |
| 195 | 204 | |
| 196 | 205 | if ( $campaigns ) { |
| 197 | 206 | $res = $dbr->select( |
| — | — | @@ -217,21 +226,56 @@ |
| 218 | 227 | ); |
| 219 | 228 | |
| 220 | 229 | 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 |
| 229 | 238 | ); |
| 230 | 239 | } |
| 231 | 240 | } |
| 232 | | - return $templates; |
| | 241 | + return $banners; |
| 233 | 242 | } |
| 234 | 243 | |
| 235 | 244 | /** |
| | 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 | + /** |
| 236 | 280 | * Lookup function for active banners under a given language/project/location. This function is |
| 237 | 281 | * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for |
| 238 | 282 | * each project. |
| — | — | @@ -307,15 +351,26 @@ |
| 308 | 352 | } |
| 309 | 353 | } |
| 310 | 354 | |
| 311 | | - $templates = array(); |
| | 355 | + $banners = array(); |
| 312 | 356 | if ( $campaigns ) { |
| 313 | 357 | // Pull all banners assigned to the campaigns |
| 314 | | - $templates = CentralNoticeDB::getCampaignBanners( $campaigns ); |
| | 358 | + $banners = CentralNoticeDB::getCampaignBanners( $campaigns ); |
| 315 | 359 | } |
| 316 | | - return $templates; |
| | 360 | + return $banners; |
| 317 | 361 | } |
| 318 | 362 | |
| 319 | 363 | /* |
| | 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 | + /* |
| 320 | 375 | * See if a given banner exists in the database |
| 321 | 376 | */ |
| 322 | 377 | public static function bannerExists( $bannerName ) { |
| Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/CentralNotice.db.php |
| ___________________________________________________________________ |
| Added: svn:mergeinfo |
| 323 | 378 | 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 |
| 324 | 379 | 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 |
| 325 | 380 | Merged /branches/wmf-deployment/extensions/CentralNotice/CentralNotice.db.php:r60970 |
| 326 | 381 | Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/CentralNotice.db.php:r67177,69199,76243,77266 |