r70901 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70900‎ | r70901 | r70902 >
Date:18:08, 11 August 2010
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
fixing CentralNotice issues from r68580
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -60,6 +60,7 @@
6161
6262 // Show list of campaigns
6363 $this->listNotices();
 64+ $wgOut->addHTML( Xml::closeElement( 'div' ) );
6465 return;
6566 }
6667
@@ -475,7 +476,7 @@
476477 $language_count = count( $project_langs );
477478 $languageList = '';
478479 if ( $language_count > 3 ) {
479 - $languageList = "multiple ($language_count)";
 480+ $languageList = wfMsg ( 'centralnotice-multiple_languages', $language_count );
480481 } elseif ( $language_count > 0 ) {
481482 $languageList = implode(', ',$project_langs);
482483 }
@@ -576,7 +577,7 @@
577578 // Name
578579 $htmlOut .= Xml::openElement( 'tr' );
579580 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-notice-name' ) );
580 - $htmlOut .= Xml::tags( 'td', array(), Xml::inputLabel( '', 'noticeName', 'noticeName', 25 ) );
 581+ $htmlOut .= Xml::tags( 'td', array(), Xml::input( 'noticeName', 25 ) );
581582 $htmlOut .= Xml::closeElement( 'tr' );
582583 // Start Date
583584 $htmlOut .= Xml::openElement( 'tr' );
@@ -585,7 +586,7 @@
586587 $htmlOut .= Xml::closeElement( 'tr' );
587588 // Start Time
588589 $htmlOut .= Xml::openElement( 'tr' );
589 - $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-hour' ) . "(GMT)" );
 590+ $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-hour' ) );
590591 $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'start' ) );
591592 $htmlOut .= Xml::closeElement( 'tr' );
592593 // Project
@@ -1062,7 +1063,7 @@
10631064 "not_end >= $encTimestamp",
10641065 "not_enabled = 1",
10651066 'cn_notice_languages.not_id = cn_notices.not_id',
1066 - "cn_notice_languages.not_language = '$language'",
 1067+ 'cn_notice_languages.not_language' => $language,
10671068 "not_project" => array( '', $project ),
10681069 'cn_notices.not_id=cn_assignments.not_id',
10691070 'cn_assignments.tmp_id=cn_templates.tmp_id'
@@ -1089,6 +1090,9 @@
10901091 if ( $dbr->numRows( $res ) > 0 ) {
10911092 $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-notice-exists' ) ) );
10921093 return;
 1094+ } elseif ( empty( $project_languages ) ) {
 1095+ $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-no-language' ) ) );
 1096+ return;
10931097 } else {
10941098 $dbw = wfGetDB( DB_MASTER );
10951099 $dbw->begin();
@@ -1338,7 +1342,11 @@
13391343
13401344 $options = "\n";
13411345 foreach( $languages as $code => $name ) {
1342 - $options .= Xml::option( "$code - $name", $code, in_array( $code, $selected ) ) . "\n";
 1346+ $options .= Xml::option(
 1347+ wfMsg( 'centralnotice-language-listing', $code, $name ),
 1348+ $code,
 1349+ in_array( $code, $selected )
 1350+ ) . "\n";
13431351 }
13441352 $htmlOut = '';
13451353 if ( $this->editable ) {
@@ -1391,15 +1399,15 @@
13921400 $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) );
13931401
13941402 // Add newly assigned languages
1395 - $addLanguages = array_diff($newLanguages, $oldLanguages);
 1403+ $addLanguages = array_diff( $newLanguages, $oldLanguages );
 1404+ $insertArray = array();
13961405 foreach( $addLanguages as $code ) {
1397 - $res = $dbw->insert( 'cn_notice_languages',
1398 - array( 'not_id' => $row->not_id, 'not_language' => $code )
1399 - );
 1406+ $insertArray[] = array( 'not_id' => $row->not_id, 'not_language' => $code );
14001407 }
 1408+ $res = $dbw->insert( 'cn_notice_languages', $insertArray );
14011409
14021410 // Remove disassociated languages
1403 - $removeLanguages = array_diff($oldLanguages, $newLanguages);
 1411+ $removeLanguages = array_diff( $oldLanguages, $newLanguages );
14041412 foreach( $removeLanguages as $code ) {
14051413 $res = $dbw->delete( 'cn_notice_languages',
14061414 array( 'not_id' => $row->not_id, 'not_language' => $code )
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -33,6 +33,8 @@
3434 'centralnotice-add-template' => 'Add a banner',
3535 'centralnotice-show-notices' => 'Show campaigns',
3636 'centralnotice-list-templates' => 'List banners',
 37+ 'centralnotice-multiple_languages' => 'multiple ($1)',
 38+ 'centralnotice-language-listing' => '$1 - $2',
3739 'centralnotice-translations' => 'Translations',
3840 'centralnotice-translate-to' => 'Translate to',
3941 'centralnotice-translate' => 'Translate',
@@ -48,6 +50,7 @@
4951 'centralnotice-notices' => 'Campaigns',
5052 'centralnotice-notice-exists' => 'Campaign already exists.
5153 Not adding.',
 54+ 'centralnotice-no-language' => 'No language was selected for the campaign. Not adding.',
5255 'centralnotice-template-exists' => 'Banner already exists.
5356 Not adding.',
5457 'centralnotice-notice-doesnt-exist' => 'Campaign does not exist.',
@@ -76,7 +79,7 @@
7780 'centralnotice-template-already-exists' => 'Banner is already tied to campaign.
7881 Not adding.',
7982 'centralnotice-preview-template' => 'Preview banner',
80 - 'centralnotice-start-hour' => 'Start time',
 83+ 'centralnotice-start-hour' => 'Start time (GMT)',
8184 'centralnotice-change-lang' => 'Change translation language',
8285 'centralnotice-weights' => 'Weights',
8386 'centralnotice-notice-is-locked' => 'Campaign is locked.
@@ -109,7 +112,10 @@
110113 'centralnotice-donate-button' => 'Donate button',
111114 'centralnotice-expanded-banner' => 'Expanded banner',
112115 'centralnotice-collapsed-banner' => 'Collapsed banner',
113 - 'centralnotice-banner-type' => 'Banner type',
 116+ 'centralnotice-banner-display' => 'Display to:',
 117+ 'centralnotice-banner-anonymous' => 'Anonymous users',
 118+ 'centralnotice-banner-logged-in' => 'Logged in users',
 119+ 'centralnotice-banner-type' => 'Banner type:',
114120 'centralnotice-banner-hidable' => 'Static/Hidable',
115121 'centralnotice-banner-collapsable' => 'Collapsable',
116122
@@ -144,6 +150,7 @@
145151 'centralnotice-remove' => '{{Identical|Remove}}',
146152 'centralnotice-translate-heading' => 'Fieldset label. $1 is a name of a template.',
147153 'centralnotice-add' => '{{Identical|Add}}',
 154+ 'centralnotice-language-listing' => 'A language listing for the language multi-select box. First parameter is the language code. Second parameter is the name of the language.',
148155 'centralnotice-translate' => '{{Identical|Translate}}',
149156 'centralnotice-notice-exists' => 'Error message displayed in Special:CentralNotice when trying to add a notice with the same name of another notice',
150157 'centralnotice-template-exists' => 'Error message displayed in Special:NoticeTemplate when trying to add a template with the same name of another template',

Follow-up revisions

RevisionCommit summaryAuthorDate
r70902Follow-up r70901: This message is optional for Translatewikiraymond18:25, 11 August 2010
r70972fixing insert per r70901kaldari17:17, 12 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68580CentralNotice: adding support for multiple languages per notice, Bug 20229kaldari18:48, 25 June 2010

Comments

#Comment by Catrope (talk | contribs)   12:24, 12 August 2010
+		$res = $dbw->insert( 'cn_notice_languages', $insertArray );

You probably want to do an INSERT IGNORE so MediaWiki doesn't die with an error if two processes try to insert the same rows at the same time. The code for this is $dbw->insert( 'cn_notice_languages, $insertArray, __METHOD__, array( 'IGNORE' ) );

Status & tagging log