r71639 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71638‎ | r71639 | r71640 >
Date:18:09, 25 August 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
checking for bad notice names per r71613
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -1081,9 +1081,12 @@
10821082 public static function getNoticeId( $noticeName ) {
10831083 $dbr = wfGetDB( DB_SLAVE );
10841084 $eNoticeName = htmlspecialchars( $noticeName );
1085 - $res = $dbr->select( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
1086 - $row = $dbr->fetchObject( $res );
1087 - return $row->not_id;
 1085+ $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
 1086+ if ( $row ) {
 1087+ return $row->not_id;
 1088+ } else {
 1089+ return;
 1090+ }
10881091 }
10891092
10901093 function getNoticeLanguages( $noticeName ) {
@@ -1282,7 +1285,7 @@
12831286 $oldLanguages = $this->getNoticeLanguages( $notice );
12841287
12851288 // Get the notice id
1286 - $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) );
 1289+ $row = $this->getNoticeId( $notice );
12871290
12881291 // Add newly assigned languages
12891292 $addLanguages = array_diff( $newLanguages, $oldLanguages );
@@ -1303,7 +1306,7 @@
13041307 $dbw->commit();
13051308 }
13061309
1307 - function dropDownList( $text, $values ) {
 1310+ public static function dropDownList( $text, $values ) {
13081311 $dropDown = "* {$text}\n";
13091312 foreach ( $values as $value ) {
13101313 $dropDown .= "**{$value}\n";
@@ -1335,18 +1338,26 @@
13361339 function getQueryInfo() {
13371340 $notice = $this->mRequest->getVal( 'notice' );
13381341 $noticeId = CentralNotice::getNoticeId( $notice );
1339 - // Return all the banners not already assigned to the current campaign
1340 - return array(
1341 - 'tables' => array( 'cn_assignments', 'cn_templates' ),
1342 - 'fields' => array( 'cn_templates.tmp_name', 'cn_templates.tmp_id' ),
1343 - 'conds' => array( 'cn_assignments.tmp_id IS NULL' ),
1344 - 'join_conds' => array(
1345 - 'cn_assignments' => array(
1346 - 'LEFT JOIN',
1347 - "cn_assignments.tmp_id = cn_templates.tmp_id AND cn_assignments.not_id = $noticeId"
 1342+ if ( $noticeId ) {
 1343+ // Return all the banners not already assigned to the current campaign
 1344+ return array(
 1345+ 'tables' => array( 'cn_assignments', 'cn_templates' ),
 1346+ 'fields' => array( 'cn_templates.tmp_name', 'cn_templates.tmp_id' ),
 1347+ 'conds' => array( 'cn_assignments.tmp_id IS NULL' ),
 1348+ 'join_conds' => array(
 1349+ 'cn_assignments' => array(
 1350+ 'LEFT JOIN',
 1351+ "cn_assignments.tmp_id = cn_templates.tmp_id AND cn_assignments.not_id = $noticeId"
 1352+ )
13481353 )
1349 - )
1350 - );
 1354+ );
 1355+ } else {
 1356+ // Return all the banners in the database
 1357+ return array(
 1358+ 'tables' => 'cn_templates',
 1359+ 'fields' => array( 'tmp_name', 'tmp_id' ),
 1360+ );
 1361+ }
13511362 }
13521363
13531364 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r71729fixing bug introduced in r71639kaldari19:28, 26 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71613cleaning up form tags, fixing error message, removing unneeded name check in ...kaldari01:41, 25 August 2010

Comments

#Comment by Catrope (talk | contribs)   21:08, 25 August 2010
+		 	return;

Please explicitly return null or false here; I know PHP returns null by default if you use return; like this but it's not obvious to everyone.

Status & tagging log