Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php |
— | — | @@ -64,28 +64,21 @@ |
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', null, 1, 1, $this->location ); |
| 68 | + $notices = $this->centralNoticeDB->getNotices( null, 'en', null, 1, 1, $this->location ); |
69 | 69 | |
70 | 70 | if ( $notices ) { |
71 | | - // Pull out values |
72 | | - foreach ( $notices as $notice => $val ) { |
73 | | - // Either match against ALL project or a specific project |
74 | | - if ( $val['project'] === '' || $val['project'] == $this->project ) { |
75 | | - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notice ); |
76 | | - break; |
77 | | - } |
78 | | - } |
| 71 | + // Pull banners |
| 72 | + $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices ); |
79 | 73 | } |
80 | 74 | } |
81 | 75 | |
82 | 76 | if ( !$templates && $this->project == 'wikipedia' ) { |
83 | 77 | // See if we have any preferred notices for this language wikipedia |
84 | 78 | $notices = $this->centralNoticeDB->getNotices( 'wikipedia', $this->language, null, 1, 1, $this->location ); |
| 79 | + |
85 | 80 | if ( $notices ) { |
86 | | - foreach ( $notices as $notice => $val ) { |
87 | | - $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notice ); |
88 | | - break; |
89 | | - } |
| 81 | + // Pull banners |
| 82 | + $templates = $this->centralNoticeDB->selectTemplatesAssigned( $notices ); |
90 | 83 | } |
91 | 84 | } |
92 | 85 | |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -1067,39 +1067,9 @@ |
1068 | 1068 | } |
1069 | 1069 | } |
1070 | 1070 | |
1071 | | - // Pull all banners assigned to the campaigns |
1072 | | - $bannerResults = $dbr->select( |
1073 | | - array( |
1074 | | - 'cn_notices', |
1075 | | - 'cn_assignments', |
1076 | | - 'cn_templates' |
1077 | | - ), |
1078 | | - array( |
1079 | | - 'tmp_name', |
1080 | | - 'SUM(tmp_weight) AS total_weight', |
1081 | | - 'tmp_display_anon', |
1082 | | - 'tmp_display_account' |
1083 | | - ), |
1084 | | - array( |
1085 | | - 'cn_notices.not_id' => $campaigns, |
1086 | | - 'cn_notices.not_id=cn_assignments.not_id', |
1087 | | - 'cn_assignments.tmp_id=cn_templates.tmp_id' |
1088 | | - ), |
1089 | | - __METHOD__, |
1090 | | - array( |
1091 | | - 'GROUP BY' => 'tmp_name' |
1092 | | - ) |
1093 | | - ); |
1094 | | - |
1095 | 1071 | $templates = array(); |
1096 | | - foreach ( $bannerResults as $row ) { |
1097 | | - $template = array(); |
1098 | | - $template['name'] = $row->tmp_name; |
1099 | | - $template['weight'] = intval( $row->total_weight ); |
1100 | | - $template['display_anon'] = intval( $row->tmp_display_anon ); |
1101 | | - $template['display_account'] = intval( $row->tmp_display_account ); |
1102 | | - $templates[] = $template; |
1103 | | - } |
| 1072 | + // Pull all banners assigned to the campaigns |
| 1073 | + $templates = $this->centralNoticeDB->selectTemplatesAssigned( $campaigns ); |
1104 | 1074 | return $templates; |
1105 | 1075 | } |
1106 | 1076 | |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -37,9 +37,6 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | // Use whatever conditional arguments got passed in |
41 | | - if ( $project ) { |
42 | | - $conds[] = "not_project =" . $dbr->addQuotes( $project ); |
43 | | - } |
44 | 41 | if ( $language ) { |
45 | 42 | $conds[] = "nl_notice_id = cn_notices.not_id"; |
46 | 43 | $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
— | — | @@ -50,6 +47,7 @@ |
51 | 48 | if ( $preferred ) { |
52 | 49 | $conds[] = "not_preferred = 1"; |
53 | 50 | } |
| 51 | + $conds[] = 'not_project' => array( '', $project ); |
54 | 52 | $conds[] = "not_geo = 0"; |
55 | 53 | $conds[] = "not_start <= " . $encTimestamp; |
56 | 54 | $conds[] = "not_end >= " . $encTimestamp; |
— | — | @@ -58,35 +56,25 @@ |
59 | 57 | $res = $dbr->select( |
60 | 58 | $tables, |
61 | 59 | array( |
62 | | - 'not_name', |
63 | | - 'not_project', |
64 | | - 'not_locked', |
65 | | - 'not_enabled', |
66 | | - 'not_preferred' |
| 60 | + 'not_id' |
67 | 61 | ), |
68 | 62 | $conds, |
69 | 63 | __METHOD__ |
70 | 64 | ); |
71 | 65 | |
72 | | - // Loop through result set and return attributes |
| 66 | + // Loop through result set and return ids |
73 | 67 | foreach ( $res as $row ) { |
74 | | - $notice = $row->not_name; |
75 | | - $notices[$notice]['project'] = $row->not_project; |
76 | | - $notices[$notice]['preferred'] = $row->not_preferred; |
77 | | - $notices[$notice]['locked'] = $row->not_locked; |
78 | | - $notices[$notice]['enabled'] = $row->not_enabled; |
| 68 | + $notices[] = $row->not_id; |
79 | 69 | } |
80 | 70 | |
81 | 71 | // If a location is passed, also pull geotargeted campaigns that match the location |
82 | 72 | if ( $location ) { |
83 | 73 | $tables = array(); |
84 | 74 | $tables[] = "cn_notices"; |
| 75 | + $tables[] = "cn_notice_countries"; |
85 | 76 | if ( $language ) { |
86 | 77 | $tables[] = "cn_notice_languages"; |
87 | 78 | } |
88 | | - if ( $location ) { |
89 | | - $tables[] = "cn_notice_countries"; |
90 | | - } |
91 | 79 | |
92 | 80 | // Use whatever conditional arguments got passed in |
93 | 81 | $conds = array(); |
— | — | @@ -97,17 +85,17 @@ |
98 | 86 | $conds[] = "nl_notice_id = cn_notices.not_id"; |
99 | 87 | $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
100 | 88 | } |
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 | | - } |
| 89 | + |
106 | 90 | if ( $enabled ) { |
107 | 91 | $conds[] = "not_enabled = 1"; |
108 | 92 | } |
109 | 93 | if ( $preferred ) { |
110 | 94 | $conds[] = "not_preferred = 1"; |
111 | 95 | } |
| 96 | + $conds[] = 'not_project' => array( '', $project ); |
| 97 | + $conds[] = "not_geo = 1"; |
| 98 | + $conds[] = "nc_notice_id = cn_notices.not_id"; |
| 99 | + $conds[] = "nc_country =" . $dbr->addQuotes( $location ); |
112 | 100 | $conds[] = "not_start <= " . $encTimestamp; |
113 | 101 | $conds[] = "not_end >= " . $encTimestamp; |
114 | 102 | |
— | — | @@ -115,23 +103,15 @@ |
116 | 104 | $res = $dbr->select( |
117 | 105 | $tables, |
118 | 106 | array( |
119 | | - 'not_name', |
120 | | - 'not_project', |
121 | | - 'not_locked', |
122 | | - 'not_enabled', |
123 | | - 'not_preferred' |
| 107 | + 'not_id' |
124 | 108 | ), |
125 | 109 | $conds, |
126 | 110 | __METHOD__ |
127 | 111 | ); |
128 | 112 | |
129 | | - // Loop through result set and return attributes |
| 113 | + // Loop through result set and return ids |
130 | 114 | 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; |
| 115 | + $notices[] = $row->not_id; |
136 | 116 | } |
137 | 117 | } |
138 | 118 | |
— | — | @@ -139,9 +119,9 @@ |
140 | 120 | } |
141 | 121 | |
142 | 122 | /* |
143 | | - * Given a notice return all banners bound to it |
| 123 | + * Given one or more campaign ids, return all banners bound to them |
144 | 124 | */ |
145 | | - public function selectTemplatesAssigned( $notice ) { |
| 125 | + public function selectTemplatesAssigned( $campaigns ) { |
146 | 126 | $dbr = wfGetDB( DB_SLAVE ); |
147 | 127 | |
148 | 128 | // Pull templates based on join with assignments |
— | — | @@ -158,7 +138,7 @@ |
159 | 139 | 'tmp_display_account' |
160 | 140 | ), |
161 | 141 | array( |
162 | | - 'cn_notices.not_name' => $notice, |
| 142 | + 'cn_notices.not_id' => $campaigns, |
163 | 143 | 'cn_notices.not_id = cn_assignments.not_id', |
164 | 144 | 'cn_assignments.tmp_id = cn_templates.tmp_id' |
165 | 145 | ), |