r73103 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73102‎ | r73103 | r73104 >
Date:00:32, 16 September 2010
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
db functions should be static, fixing query conds bug in r73101
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerListLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php
@@ -15,7 +15,6 @@
1616 function __construct() {
1717 // Register special page
1818 parent::__construct( "BannerListLoader" );
19 - $this->centralNoticeDB = new CentralNoticeDB();
2019 }
2120
2221 function execute( $par ) {
@@ -64,21 +63,21 @@
6564
6665 if ( $this->language == 'en' && $this->project != null ) {
6766 // See if we have any preferred notices for all of en
68 - $notices = $this->centralNoticeDB->getNotices( null, 'en', null, 1, 1, $this->location );
 67+ $notices = CentralNoticeDB::getNotices( null, 'en', null, 1, 1, $this->location );
6968
7069 if ( $notices ) {
7170 // Pull banners
72 - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices );
 71+ $templates = CentralNoticeDB::selectTemplatesAssigned( $notices );
7372 }
7473 }
7574
7675 if ( !$templates && $this->project == 'wikipedia' ) {
7776 // See if we have any preferred notices for this language wikipedia
78 - $notices = $this->centralNoticeDB->getNotices( 'wikipedia', $this->language, null, 1, 1, $this->location );
 77+ $notices = CentralNoticeDB::getNotices( 'wikipedia', $this->language, null, 1, 1, $this->location );
7978
8079 if ( $notices ) {
8180 // Pull banners
82 - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices );
 81+ $templates = CentralNoticeDB::selectTemplatesAssigned( $notices );
8382 }
8483 }
8584
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -14,8 +14,6 @@
1515
1616 // Internationalization
1717 wfLoadExtensionMessages( 'CentralNotice' );
18 -
19 - $this->centralNoticeDB = new CentralNoticeDB();
2018 }
2119
2220 /**
@@ -1069,7 +1067,7 @@
10701068
10711069 $templates = array();
10721070 // Pull all banners assigned to the campaigns
1073 - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $campaigns );
 1071+ $templates = CentralNoticeDB::selectTemplatesAssigned( $campaigns );
10741072 return $templates;
10751073 }
10761074
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -18,7 +18,7 @@
1919 * Return campaigns in the system within given constraints
2020 * By default returns enabled campaigns, if $enabled set to false, returns both enabled and disabled campaigns
2121 */
22 - public function getNotices( $project = false, $language = false, $date = false, $enabled = true, $preferred = false, $location = false ) {
 22+ static function getNotices( $project = false, $language = false, $date = false, $enabled = true, $preferred = false, $location = false ) {
2323
2424 $notices = array();
2525
@@ -47,7 +47,7 @@
4848 if ( $preferred ) {
4949 $conds[] = "not_preferred = 1";
5050 }
51 - $conds[] = 'not_project' => array( '', $project );
 51+ $conds[] = "not_project IN ( '', " . $dbr->addQuotes($project ) . " )";
5252 $conds[] = "not_geo = 0";
5353 $conds[] = "not_start <= " . $encTimestamp;
5454 $conds[] = "not_end >= " . $encTimestamp;
@@ -92,7 +92,7 @@
9393 if ( $preferred ) {
9494 $conds[] = "not_preferred = 1";
9595 }
96 - $conds[] = 'not_project' => array( '', $project );
 96+ $conds[] = "not_project IN ( '', " . $dbr->addQuotes($project ) . " )";
9797 $conds[] = "not_geo = 1";
9898 $conds[] = "nc_notice_id = cn_notices.not_id";
9999 $conds[] = "nc_country =" . $dbr->addQuotes( $location );
@@ -121,7 +121,7 @@
122122 /*
123123 * Given one or more campaign ids, return all banners bound to them
124124 */
125 - public function selectTemplatesAssigned( $campaigns ) {
 125+ static function selectTemplatesAssigned( $campaigns ) {
126126 $dbr = wfGetDB( DB_SLAVE );
127127
128128 // Pull templates based on join with assignments

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73101consolidating similar code for pulling bannerskaldari23:29, 15 September 2010

Comments

#Comment by Catrope (talk | contribs)   18:18, 27 September 2010
+		$conds[] = "not_project IN ( '', " . $dbr->addQuotes($project ) . " )";

Use $conds['not_project'] = $project;.

#Comment by Catrope (talk | contribs)   18:12, 23 October 2010

This got fixed later at some point.

Status & tagging log