r71828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71827‎ | r71828 | r71829 >
Date:00:15, 28 August 2010
Author:kaldari
Status:resolved
Tags:
Comment:
adding noticeExists() test, moving updatePreferred(), removing unneccessary transactions
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -228,19 +228,6 @@
229229 $wgOut->addHTML( Xml::closeElement( 'div' ) );
230230 }
231231
232 - /**
233 - * Update the enabled/disabled state of a campaign
234 - */
235 - private function updateEnabled( $notice, $state ) {
236 - $dbw = wfGetDB( DB_MASTER );
237 - $dbw->begin();
238 - $res = $dbw->update( 'cn_notices',
239 - array( 'not_enabled' => $state ),
240 - array( 'not_name' => $notice )
241 - );
242 - $dbw->commit();
243 - }
244 -
245232 public static function printHeader() {
246233 global $wgOut, $wgTitle, $wgUser;
247234 $sk = $wgUser->getSkin();
@@ -1000,9 +987,7 @@
1001988 function addNotice( $noticeName, $enabled, $start, $project_name, $project_languages ) {
1002989 global $wgOut;
1003990
1004 - $dbr = wfGetDB( DB_SLAVE );
1005 - $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) );
1006 - if ( $dbr->numRows( $res ) > 0 ) {
 991+ if ( $this->noticeExists( $noticeName ) ) {
1007992 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-exists' );
1008993 return;
1009994 } elseif ( empty( $project_languages ) ) {
@@ -1116,7 +1101,7 @@
11171102 if ( $row ) {
11181103 return $row->not_id;
11191104 } else {
1120 - return;
 1105+ return null;
11211106 }
11221107 }
11231108
@@ -1171,8 +1156,7 @@
11721157 }
11731158
11741159 // Invalid campaign name
1175 - $row = $dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) );
1176 - if ( !$row ) {
 1160+ if ( !$this->noticeExists( $noticeName ) ) {
11771161 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
11781162 return;
11791163 }
@@ -1191,23 +1175,54 @@
11921176 );
11931177 }
11941178
 1179+ /**
 1180+ * Update the enabled/disabled state of a campaign
 1181+ */
 1182+ private function updateEnabled( $noticeName, $isEnabled ) {
 1183+ global $wgOut;
 1184+
 1185+ if ( !$this->noticeExists( $noticeName ) ) {
 1186+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
 1187+ } else {
 1188+ $dbw = wfGetDB( DB_MASTER );
 1189+ $res = $dbw->update( 'cn_notices',
 1190+ array( 'not_enabled' => $isEnabled ),
 1191+ array( 'not_name' => $noticeName )
 1192+ );
 1193+ }
 1194+ }
 1195+
 1196+ /**
 1197+ * Update the preferred/not preferred state of a campaign
 1198+ */
 1199+ function updatePreferred( $noticeName, $isPreferred ) {
 1200+ global $wgOut;
 1201+
 1202+ if ( !$this->noticeExists( $noticeName ) ) {
 1203+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
 1204+ } else {
 1205+ $dbw = wfGetDB( DB_MASTER );
 1206+ $res = $dbw->update( 'cn_notices',
 1207+ array( 'not_preferred' => $isPreferred ),
 1208+ array( 'not_name' => $noticeName )
 1209+ );
 1210+ }
 1211+ }
 1212+
 1213+ /**
 1214+ * Update the locked/unlocked state of a campaign
 1215+ */
11951216 function updateLock( $noticeName, $isLocked ) {
11961217 global $wgOut;
11971218
1198 - $dbr = wfGetDB( DB_SLAVE );
1199 - $res = $dbr->select( 'cn_notices', 'not_name',
1200 - array( 'not_name' => $noticeName )
1201 - );
1202 - if ( $dbr->numRows( $res ) < 1 ) {
 1219+ if ( !$this->noticeExists( $noticeName ) ) {
12031220 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
12041221 } else {
12051222 $dbw = wfGetDB( DB_MASTER );
1206 - $dbw->begin();
12071223 $res = $dbw->update( 'cn_notices',
12081224 array( 'not_locked' => $isLocked ),
12091225 array( 'not_name' => $noticeName )
12101226 );
1211 - $dbw->commit();
12121227 }
12131228 }
12141229
@@ -1296,14 +1311,12 @@
12971312
12981313 function updateProjectName( $notice, $projectName ) {
12991314 $dbw = wfGetDB( DB_MASTER );
1300 - $dbw->begin();
13011315 $res = $dbw->update( 'cn_notices',
13021316 array ( 'not_project' => $projectName ),
13031317 array(
13041318 'not_name' => $notice
13051319 )
13061320 );
1307 - $dbw->commit();
13081321 }
13091322
13101323 function updateProjectLanguages( $notice, $newLanguages ) {
@@ -1335,6 +1348,17 @@
13361349
13371350 $dbw->commit();
13381351 }
 1352+
 1353+ public static function noticeExists( $noticeName ) {
 1354+ $dbr = wfGetDB( DB_SLAVE );
 1355+ $eNoticeName = htmlspecialchars( $noticeName );
 1356+ $row = $dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $eNoticeName ) );
 1357+ if ( $row ) {
 1358+ return true;
 1359+ } else {
 1360+ return false;
 1361+ }
 1362+ }
13391363
13401364 public static function dropDownList( $text, $values ) {
13411365 $dropDown = "* {$text}\n";
Index: trunk/extensions/CentralNotice/CentralNotice.db.php
@@ -118,20 +118,5 @@
119119 }
120120 return $templates;
121121 }
122 -
123 - public function updatePreferred( $notice, $preferred ) {
124 - $dbw = wfGetDB( DB_MASTER );
125 - $dbw->begin();
126 -
127 - $res = $dbw->update( 'cn_notices',
128 - array(
129 - 'not_preferred' => $preferred,
130 - ),
131 - array(
132 - 'not_name' => $notice
133 - )
134 - );
135 - $dbw->commit();
136 - return $res;
137 - }
 122+
138123 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r71829forgot to update calls to updatePreferred in r71828kaldari00:24, 28 August 2010

Status & tagging log