r74222 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74221‎ | r74222 | r74223 >
Date:16:19, 3 October 2010
Author:catrope
Status:ok
Tags:
Comment:
Style fixes for CentralNotice. Mostly about calling DB functions and handling arrays
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -32,33 +32,33 @@
3333 $encTimestamp = $dbr->addQuotes( $dbr->timestamp( $date ) );
3434 }
3535
36 - $tables[] = "cn_notices";
 36+ $tables = array( 'cn_notices' );
3737 if ( $language ) {
38 - $tables[] = "cn_notice_languages";
 38+ $tables[] = 'cn_notice_languages';
3939 }
4040
 41+ $conds = array(
 42+ 'not_project' => array( '', $project ),
 43+ 'not_geo' => 0,
 44+ "not_start <= $encTimestamp",
 45+ "not_end >= $encTimestamp",
 46+ );
4147 // Use whatever conditional arguments got passed in
4248 if ( $language ) {
43 - $conds[] = "nl_notice_id = cn_notices.not_id";
44 - $conds[] = "nl_language =" . $dbr->addQuotes( $language );
 49+ $conds[] = 'nl_notice_id = cn_notices.not_id';
 50+ $conds['nl_language'] = $language;
4551 }
4652 if ( $enabled ) {
47 - $conds[] = "not_enabled = 1";
 53+ $conds['not_enabled'] = 1;
4854 }
4955 if ( $preferred ) {
50 - $conds[] = "not_preferred = 1";
 56+ $conds['not_preferred'] = 1;
5157 }
52 - $conds[] = "not_project IN ( '', " . $dbr->addQuotes( $project ) . " )";
53 - $conds[] = "not_geo = 0";
54 - $conds[] = "not_start <= " . $encTimestamp;
55 - $conds[] = "not_end >= " . $encTimestamp;
5658
5759 // Pull db data
5860 $res = $dbr->select(
5961 $tables,
60 - array(
61 - 'not_id'
62 - ),
 62+ 'not_id',
6363 $conds,
6464 __METHOD__
6565 );
@@ -70,39 +70,35 @@
7171
7272 // If a location is passed, also pull geotargeted campaigns that match the location
7373 if ( $location ) {
74 - $tables = array();
75 - $tables[] = "cn_notices";
76 - $tables[] = "cn_notice_countries";
 74+ $tables = array( 'cn_notices', 'cn_notice_countries' );
7775 if ( $language ) {
78 - $tables[] = "cn_notice_languages";
 76+ $tables[] = 'cn_notice_languages';
7977 }
8078
8179 // Use whatever conditional arguments got passed in
82 - $conds = array();
 80+ $conds = array(
 81+ 'not_project' => array( '', $project ),
 82+ 'not_geo' => 1,
 83+ 'nc_notice_id = cn_notices.not_id',
 84+ 'nc_country' => $location,
 85+ "not_start <= $encTimestamp",
 86+ "not_end >= $encTimestamp",
 87+ );
8388 if ( $language ) {
8489 $conds[] = "nl_notice_id = cn_notices.not_id";
85 - $conds[] = "nl_language =" . $dbr->addQuotes( $language );
 90+ $conds['nl_language'] = $language;
8691 }
8792
8893 if ( $enabled ) {
89 - $conds[] = "not_enabled = 1";
 94+ $conds['not_enabled'] = 1;
9095 }
9196 if ( $preferred ) {
92 - $conds[] = "not_preferred = 1";
93 - }
94 - $conds[] = "not_project IN ( '', " . $dbr->addQuotes($project ) . " )";
95 - $conds[] = "not_geo = 1";
96 - $conds[] = "nc_notice_id = cn_notices.not_id";
97 - $conds[] = "nc_country =" . $dbr->addQuotes( $location );
98 - $conds[] = "not_start <= " . $encTimestamp;
99 - $conds[] = "not_end >= " . $encTimestamp;
100 -
 97+ $conds['not_preferred'] = 1;
 98+ }
10199 // Pull db data
102100 $res = $dbr->select(
103101 $tables,
104 - array(
105 - 'not_id'
106 - ),
 102+ 'not_id'
107103 $conds,
108104 __METHOD__
109105 );
@@ -151,12 +147,12 @@
152148 }
153149 $templates = array();
154150 foreach ( $res as $row ) {
155 - $template = array();
156 - $template['name'] = $row->tmp_name;
157 - $template['weight'] = intval( $row->total_weight );
158 - $template['display_anon'] = intval( $row->tmp_display_anon );
159 - $template['display_account'] = intval( $row->tmp_display_account );
160 - $templates[] = $template;
 151+ $templates[] = array(
 152+ 'name' => $row->tmp_name,
 153+ 'weight' => intval( $row->total_weight ),
 154+ 'display_anon' => intval( $row->tmp_display_anon ),
 155+ 'display_account' => intval( $row->tmp_display_account ),
 156+ );
161157 }
162158 return $templates;
163159 }
@@ -166,7 +162,7 @@
167163 * (This should probably be moved to a core database table at some point.)
168164 */
169165 static function getCountriesList() {
170 - $countries = array(
 166+ return array(
171167 'AF'=>'Afghanistan',
172168 'AL'=>'Albania',
173169 'DZ'=>'Algeria',
@@ -408,6 +404,5 @@
409405 'ZM'=>'Zambia',
410406 'ZW'=>'Zimbabwe'
411407 );
412 - return $countries;
413408 }
414409 }

Status & tagging log