Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | |
66 | 66 | if ( $this->language == 'en' && $this->project != null ) { |
67 | 67 | // See if we have any preferred notices for all of en |
68 | | - $notices = $this->centralNoticeDB->getNotices( '', 'en', '', '', 1, $this->location ); |
| 68 | + $notices = $this->centralNoticeDB->getNotices( '', 'en', null, 1, 1, $this->location ); |
69 | 69 | |
70 | 70 | if ( $notices ) { |
71 | 71 | // Pull out values |
— | — | @@ -79,7 +79,8 @@ |
80 | 80 | } |
81 | 81 | |
82 | 82 | if ( !$templates && $this->project == 'wikipedia' ) { |
83 | | - $notices = $this->centralNoticeDB->getNotices( 'wikipedia', $this->language, '', '', 1, $this->location ); |
| 83 | + // See if we have any preferred notices for this language wikipedia |
| 84 | + $notices = $this->centralNoticeDB->getNotices( 'wikipedia', $this->language, null, 1, 1, $this->location ); |
84 | 85 | if ( $notices ) { |
85 | 86 | foreach ( $notices as $notice => $val ) { |
86 | 87 | $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notice ); |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -15,20 +15,26 @@ |
16 | 16 | } |
17 | 17 | |
18 | 18 | /* |
19 | | - * Return notices in the system within given constraints |
20 | | - * Optional: return both enabled and disabled notices |
| 19 | + * Return campaigns in the system within given constraints |
| 20 | + * By default returns enabled campaigns, if $enabled set to false, returns both enabled and disabled campaigns |
21 | 21 | */ |
22 | 22 | public function getNotices( $project = false, $language = false, $date = false, $enabled = true, $preferred = false, $location = false ) { |
| 23 | + |
| 24 | + $notices = array(); |
| 25 | + |
23 | 26 | // Database setup |
24 | 27 | $dbr = wfGetDB( DB_SLAVE ); |
25 | 28 | |
| 29 | + if ( !$date ) { |
| 30 | + $encTimestamp = $dbr->addQuotes( $dbr->timestamp() ); |
| 31 | + } else { |
| 32 | + $encTimestamp = $dbr->addQuotes( $date ); |
| 33 | + } |
| 34 | + |
26 | 35 | $tables[] = "cn_notices"; |
27 | 36 | if ( $language ) { |
28 | 37 | $tables[] = "cn_notice_languages"; |
29 | 38 | } |
30 | | - if ( $location ) { |
31 | | - $tables[] = "cn_notice_countries"; |
32 | | - } |
33 | 39 | |
34 | 40 | // Use whatever conditional arguments got passed in |
35 | 41 | if ( $project ) { |
— | — | @@ -38,21 +44,16 @@ |
39 | 45 | $conds[] = "nl_notice_id = cn_notices.not_id"; |
40 | 46 | $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
41 | 47 | } |
| 48 | + if ( $enabled ) { |
| 49 | + $conds[] = "not_enabled = 1"; |
| 50 | + } |
42 | 51 | if ( $preferred ) { |
43 | 52 | $conds[] = "not_preferred = 1"; |
44 | 53 | } |
45 | | - if ( $location ) { |
46 | | - $conds[] = 'nc_notice_id = cn_notices.not_id'; |
47 | | - $conds[] = "(not_geo = 0) OR ((not_geo = 1) AND (nc_country = '$location'))"; |
48 | | - } |
49 | | - if ( !$date ) { |
50 | | - $date = $dbr->timestamp(); |
51 | | - } |
| 54 | + $conds[] = "not_geo = 0"; |
| 55 | + $conds[] = "not_start <= " . $encTimestamp; |
| 56 | + $conds[] = "not_end >= " . $encTimestamp; |
52 | 57 | |
53 | | - $conds[] = ( $date ) ? "not_start <= " . $dbr->addQuotes( $date ) : "not_start <= " . $dbr->addQuotes( $dbr->timestamp( $date ) ); |
54 | | - $conds[] = ( $date ) ? "not_end >= " . $dbr->addQuotes( $date ) : "not_end >= " . $dbr->addQuotes( $dbr->timestamp( $date ) ); |
55 | | - $conds[] = ( $enabled ) ? "not_enabled = " . $dbr->addQuotes( $enabled ) : "not_enabled = " . $dbr->addQuotes( 1 ); |
56 | | - |
57 | 58 | // Pull db data |
58 | 59 | $res = $dbr->select( |
59 | 60 | $tables, |
— | — | @@ -67,20 +68,72 @@ |
68 | 69 | __METHOD__ |
69 | 70 | ); |
70 | 71 | |
71 | | - // If no matching notices, return NULL |
72 | | - if ( $dbr->numRows( $res ) < 1 ) { |
73 | | - return; |
74 | | - } |
75 | | - |
76 | | - $notices = array(); |
77 | 72 | // Loop through result set and return attributes |
78 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
| 73 | + foreach ( $res as $row ) { |
79 | 74 | $notice = $row->not_name; |
80 | 75 | $notices[$notice]['project'] = $row->not_project; |
81 | 76 | $notices[$notice]['preferred'] = $row->not_preferred; |
82 | 77 | $notices[$notice]['locked'] = $row->not_locked; |
83 | 78 | $notices[$notice]['enabled'] = $row->not_enabled; |
84 | 79 | } |
| 80 | + |
| 81 | + // If a location is passed, also pull geotargeted campaigns that match the location |
| 82 | + if ( $location ) { |
| 83 | + $tables = array(); |
| 84 | + $tables[] = "cn_notices"; |
| 85 | + if ( $language ) { |
| 86 | + $tables[] = "cn_notice_languages"; |
| 87 | + } |
| 88 | + if ( $location ) { |
| 89 | + $tables[] = "cn_notice_countries"; |
| 90 | + } |
| 91 | + |
| 92 | + // Use whatever conditional arguments got passed in |
| 93 | + $conds = array(); |
| 94 | + if ( $project ) { |
| 95 | + $conds[] = "not_project =" . $dbr->addQuotes( $project ); |
| 96 | + } |
| 97 | + if ( $language ) { |
| 98 | + $conds[] = "nl_notice_id = cn_notices.not_id"; |
| 99 | + $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
| 100 | + } |
| 101 | + if ( $location ) { |
| 102 | + $conds[] = "not_geo = 1"; |
| 103 | + $conds[] = "nc_notice_id = cn_notices.not_id"; |
| 104 | + $conds[] = "nc_country =" . $dbr->addQuotes( $location ); |
| 105 | + } |
| 106 | + if ( $enabled ) { |
| 107 | + $conds[] = "not_enabled = 1"; |
| 108 | + } |
| 109 | + if ( $preferred ) { |
| 110 | + $conds[] = "not_preferred = 1"; |
| 111 | + } |
| 112 | + $conds[] = "not_start <= " . $encTimestamp; |
| 113 | + $conds[] = "not_end >= " . $encTimestamp; |
| 114 | + |
| 115 | + // Pull db data |
| 116 | + $res = $dbr->select( |
| 117 | + $tables, |
| 118 | + array( |
| 119 | + 'not_name', |
| 120 | + 'not_project', |
| 121 | + 'not_locked', |
| 122 | + 'not_enabled', |
| 123 | + 'not_preferred' |
| 124 | + ), |
| 125 | + $conds, |
| 126 | + __METHOD__ |
| 127 | + ); |
| 128 | + |
| 129 | + // Loop through result set and return attributes |
| 130 | + foreach ( $res as $row ) { |
| 131 | + $notice = $row->not_name; |
| 132 | + $notices[$notice]['project'] = $row->not_project; |
| 133 | + $notices[$notice]['preferred'] = $row->not_preferred; |
| 134 | + $notices[$notice]['locked'] = $row->not_locked; |
| 135 | + $notices[$notice]['enabled'] = $row->not_enabled; |
| 136 | + } |
| 137 | + } |
85 | 138 | |
86 | 139 | return $notices; |
87 | 140 | } |