r42803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42802‎ | r42803 | r42804 >
Date:04:56, 30 October 2008
Author:tparscal
Status:old
Tags:
Comment:
Cleaned up code. Renamed database tables and fields.
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.sql (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeCentral.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/rebuildTemplates.php (modified) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php
@@ -67,15 +67,15 @@
6868 'descriptionmsg' => 'centralnotice-desc',
6969 );
7070
71 -$wgExtensionMessagesFiles['CentralNotice'] = dirname(__FILE__) . '/CentralNotice.i18n.php';
 71+$dir = dirname( __FILE__ ) . '/';
7272
73 -$dir = dirname(__FILE__) . '/';
74 -$wgAutoloadClasses['CentralNotice'] = dirname(__FILE__) . '/SpecialNoticeCentral.php';
 73+$wgExtensionMessagesFiles['CentralNotice'] = $dir . 'CentralNotice.i18n.php';
 74+$wgAutoloadClasses['CentralNotice'] = $dir . 'SpecialNoticeCentral.php';
7575
7676 $wgAvailableRights[] = 'centralnotice_admin_rights';
7777 $wgGroupPermissions['sysop']['centralnotice_admin_rights'] = true; // Only sysops can make change
7878 $wgGroupPermissions['sysop']['centralnotice_translate_rights'] = true; // Only sysops can make change
79 -
 79+
8080 $wgSpecialPages['CentralNotice'] = 'CentralNotice';
8181 $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate';
8282 $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate';
@@ -84,44 +84,36 @@
8585 $wgSpecialPageGroups['NoticeTemplate'] = 'wiki'; // Wiki data and tools"
8686
8787 function efCentralNoticeSetup() {
88 - global $wgHooks, $wgNoticeInfrastructure;
89 - global $wgAutoloadClasses, $wgSpecialPages;
90 -
91 - global $wgCentralNoticeLoader;
92 -
93 - if ($wgCentralNoticeLoader) {
94 - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader';
95 - }
 88+ global $wgHooks, $wgNoticeInfrastructure, $wgAutoloadClasses, $wgSpecialPages;
 89+ global $wgCentralNoticeLoader, $dir;
9690
97 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook';
98 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook';
99 -
100 - $wgAutoloadClasses['NoticePage'] =
101 - dirname( __FILE__ ) . '/NoticePage.php';
 91+ if ($wgCentralNoticeLoader) {
 92+ $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader';
 93+ }
10294
103 - $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal';
104 - $wgAutoloadClasses['SpecialNoticeLocal'] =
105 - dirname( __FILE__ ) . '/SpecialNoticeLocal.php';
 95+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook';
 96+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook';
 97+
 98+ $wgAutoloadClasses['NoticePage'] = $dir . 'NoticePage.php';
 99+
 100+ $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal';
 101+ $wgAutoloadClasses['SpecialNoticeLocal'] = $dir . 'SpecialNoticeLocal.php';
106102
107103 if( $wgNoticeInfrastructure ) {
108 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeSaveHook';
109 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeDeleteHook';
110 -
111 - $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader';
112 - $wgAutoloadClasses['SpecialNoticeLoader'] =
113 - dirname( __FILE__ ) . '/SpecialNoticeLoader.php';
114 -
115 - $wgSpecialPages['NoticeText'] = 'SpecialNoticeText';
116 - $wgAutoloadClasses['SpecialNoticeText'] =
117 - dirname( __FILE__ ) . '/SpecialNoticeText.php';
 104+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeSaveHook';
 105+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeDeleteHook';
118106
119 - $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate';
120 - $wgAutoloadClasses['SpecialNoticeTemplate'] =
121 - dirname( __FILE__ ) . '/SpecialNoticeTemplate.php';
122 -
123 - $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate';
124 - $wgAutoloadClasses['SpecialNoticeTranslate'] =
125 - dirname( __FILE__ ) . '/SpecialNoticeTranslate.php';
 107+ $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader';
 108+ $wgAutoloadClasses['SpecialNoticeLoader'] = $dir . 'SpecialNoticeLoader.php';
 109+
 110+ $wgSpecialPages['NoticeText'] = 'SpecialNoticeText';
 111+ $wgAutoloadClasses['SpecialNoticeText'] = $dir . 'SpecialNoticeText.php';
 112+
 113+ $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate';
 114+ $wgAutoloadClasses['SpecialNoticeTemplate'] = $dir . 'SpecialNoticeTemplate.php';
 115+
 116+ $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate';
 117+ $wgAutoloadClasses['SpecialNoticeTranslate'] = $dir . 'SpecialNoticeTranslate.php';
126118 }
127119 }
128120
@@ -129,8 +121,7 @@
130122 global $wgScript, $wgUser;
131123 global $wgNoticeLoader, $wgNoticeLang, $wgNoticeProject;
132124
133 - $wgCentralnoticeTable = "central_notice_campaign";
134 - $wgNotice = efSelectNotice($wgCentralnoticeTable);
 125+ $wgNotice = efSelectNotice( 'cn_notices' );
135126 if ( isset( $wgNotice ) ) { //Do we have an active notice campaign
136127 $encNoticeLoader = htmlspecialchars( $wgNoticeLoader );
137128 $encProject = Xml::encodeJsVar( $wgNoticeProject );
@@ -170,15 +161,26 @@
171162 * Lookup function for active notice under a given language and project
172163 * Returns and id for the running notice
173164 */
174 -function efSelectNotice( $centralnotice_table ) {
 165+function efSelectNotice( $dbTable ) {
175166 global $wgNoticeLang, $wgNoticeProject;
176 -
 167+
177168 $dbr = wfGetDB( DB_SLAVE );
178169 $timestamp = wfTimestampNow();
179 - $res = $dbr->select( $centralnotice_table, 'notice_id', array ( "notice_start_date <= '$timestamp'", "notice_end_date >= '$timestamp'", "notice_enabled = 'Y'", "notice_language = '$wgNoticeLang'", "notice_project = '$wgNoticeProject'"));
 170+ $res = $dbr->select( $dbTable, 'not_id',
 171+ array (
 172+ "not_start <= '{$timestamp}'",
 173+ "not_end >= '{$timestamp}'",
 174+ "not_enabled = 'Y'",
 175+ "not_language = '{$wgNoticeLang}'",
 176+ "not_project = '{$wgNoticeProject}'"
 177+ )
 178+ );
180179 if ( $dbr->numRows( $res ) == 1) {
181180 $row = $dbr->fetchObject( $res );
182 - return $row->notice_id;
 181+ if( $row ) {
 182+ return $row->not_id;
 183+ }
 184+ return null;
183185 }
184186 }
185187
@@ -188,9 +190,11 @@
189191 * Trigger a purge of the notice loader when we've updated the source pages.
190192 */
191193 function efCentralNoticeSaveHook( $article, $user, $text, $summary, $isMinor,
192 - $isWatch, $section, $flags, $revision ) {
 194+ $isWatch, $section, $flags, $revision ) {
193195 efCentralNoticeMaybePurge( $article->getTitle() );
194 - return true; // Continue hook processing
 196+
 197+ // Continue
 198+ return true;
195199 }
196200
197201 /**
@@ -198,9 +202,11 @@
199203 * Trigger a purge of the local notice when we've updated the source pages.
200204 */
201205 function efCentralNoticeLocalSaveHook( $article, $user, $text, $summary, $isMinor,
202 - $isWatch, $section, $flags, $revision ) {
 206+ $isWatch, $section, $flags, $revision ) {
203207 efCentralNoticeMaybePurgeLocal( $article->getTitle() );
204 - return true; // Continue hook processing
 208+
 209+ // Continue
 210+ return true;
205211 }
206212
207213 /**
@@ -209,7 +215,9 @@
210216 */
211217 function efCentralNoticeDeleteHook( $article, $user, $reason ) {
212218 efCentralNoticeMaybePurge( $article->getTitle() );
213 - return true; // Continue hook processing
 219+
 220+ // Continue
 221+ return true;
214222 }
215223
216224 /**
@@ -218,7 +226,9 @@
219227 */
220228 function efCentralNoticeLocalDeleteHook( $article, $user, $reason ) {
221229 efCentralNoticeMaybePurgeLocal( $article->getTitle() );
222 - return true; // Continue hook processing
 230+
 231+ // Continue
 232+ return true;
223233 }
224234
225235 /**
@@ -276,6 +286,7 @@
277287 */
278288 function efCentralNoticeEpoch() {
279289 global $wgMemc;
 290+
280291 $epoch = $wgMemc->get( 'centralnotice-epoch' );
281292 if( $epoch ) {
282293 return wfTimestamp( TS_MW, $epoch );
@@ -290,6 +301,7 @@
291302 */
292303 function efCentralNoticeUpdateEpoch() {
293304 global $wgMemc, $wgNoticeServerTimeout;
 305+
294306 $epoch = wfTimestamp( TS_MW );
295307 $wgMemc->set( "centralnotice-epoch", $epoch, $wgNoticeServerTimeout );
296308 return $epoch;
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeCentral.php
@@ -5,347 +5,475 @@
66 exit( 1 );
77 }
88
9 -class CentralNotice extends SpecialPage
10 -{
 9+class CentralNotice extends SpecialPage {
 10+
 11+ /* Functions */
 12+
1113 function CentralNotice() {
12 - SpecialPage::SpecialPage("CentralNotice");
13 - wfLoadExtensionMessages('CentralNotice');
 14+ // Register special page
 15+ SpecialPage::SpecialPage( 'CentralNotice' );
 16+
 17+ // Internationalization
 18+ wfLoadExtensionMessages( 'CentralNotice' );
1419 }
1520
1621 function execute( $sub ) {
1722 global $wgOut, $wgUser, $wgRequest;
1823
 24+ // Begin output
1925 $this->setHeaders();
 26+
 27+ // Get current skin
2028 $sk = $wgUser->getSkin();
21 -
22 - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' )) {
 29+
 30+ // Check permissions
 31+ if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' ) ) {
2332 $wgOut->permissionRequired( 'centralnotice_admin_rights' );
2433 return;
2534 }
2635
27 - $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ));
 36+ // Show summary
 37+ $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) );
 38+
 39+ // Show header
2840 $this->printHeader();
29 -
30 -
 41+
 42+ // Handle form sumissions
3143 if ( $wgRequest->wasPosted() ) {
32 - $body = file_get_contents('php://input');
33 - $wgOut->addHtml("Body of post: $body");
34 -
35 - $toRemove = $wgRequest->getArray('removeNotices');
36 - if ( isset($toRemove) ){
 44+ /*
 45+ * This is for debugging only
 46+ */
 47+ $body = file_get_contents( 'php://input' );
 48+ $wgOut->addHtml( Xml::element( 'pre', null, $body ) );
 49+
 50+
 51+ // Handle removing
 52+ $toRemove = $wgRequest->getArray( 'removeNotices' );
 53+ if ( isset( $toRemove ) ) {
 54+ // Remove notices in list
3755 foreach ( $toRemove as $template ) {
3856 $this->removeNotice( $template );
3957 }
 58+
 59+ // Show list of notices
4060 $this->listNotices();
4161 return;
4262 }
43 -
44 - $lockedNotices = $wgRequest->getArray('locked');
 63+
 64+ // Handle locking/unlocking
 65+ $lockedNotices = $wgRequest->getArray( 'locked' );
4566 if ( isset( $lockedNotices ) ) {
46 - $allNotices = $this->getNoticesName();
47 - $diff_set = array_diff( $allNotices, $lockedNotices);
 67+ // Build list of notices to lock
 68+ $unlockedNotices = array_diff( $this->getNoticesName(), $lockedNotices);
4869
 70+ // Set locked/unlocked flag accordingly
4971 foreach( $lockedNotices as $notice ) {
5072 $this->updateLock( $notice, 'Y' );
5173 }
52 -
53 - foreach( $diff_set as $notice ) {
 74+ foreach( $unlockedNotices as $notice ) {
5475 $this->updateLock( $notice, 'N' );
5576 }
5677 }
 78+
 79+ // Handle enabling/disabling
5780 $enabledNotices = $wgRequest->getArray('enabled');
5881 if ( isset( $enabledNotices ) ) {
59 - $allNotices = $this->getNoticesName();
60 - $diff_set = array_diff( $allNotices, $enabledNotices);
61 -
 82+ // Build list of notices to disable
 83+ $disabledNotices = array_diff( $this->getNoticesName(), $enabledNotices);
 84+
 85+ // Set enabled/disabled flag accordingly
6286 foreach ( $enabledNotices as $notice) {
6387 $this->updateEnabled( $notice, 'Y');
6488 }
65 - foreach ( $diff_set as $notice) {
 89+ foreach ( $disabledNotices as $notice) {
6690 $this->updateEnabled( $notice, 'N');
6791 }
6892 }
69 -
70 - $start_date = $wgRequest->getArray('start_date');
71 - $end_date = $wgRequest->getArray('end_date');
72 -
73 - if ( isset( $start_date ) && isset( $end_date )) {
74 - foreach( $start_date as $noticeName => $date_value ) {
75 - $updatedStartDate = '';
76 - foreach ( $date_value as $date_portion => $value) {
77 - $updatedStartDate .= $value;
 93+
 94+ $noticeName = $wgRequest->getVal( 'notice' );
 95+
 96+ // Handle range setting
 97+ $start = $wgRequest->getArray( 'start' );
 98+ $end = $wgRequest->getArray( 'end' );
 99+ if ( isset( $start ) && isset( $end )) {
 100+ foreach( $start as $noticeName => $date ) {
 101+ $updatedStart = '';
 102+ foreach ( $date as $value) {
 103+ $updatedStart .= $value;
78104 }
79 - $updatedStartDate .= "00";
 105+ $updatedStart .= '00';
80106 }
81 - foreach( $end_date as $noticeName => $date_value ) {
82 - $updatedEndDate = '';
83 - foreach ( $date_value as $date_portion => $value) {
84 - $updatedEndDate .= $value;
 107+ foreach( $end as $noticeName => $date ) {
 108+ $updatedEnd = '';
 109+ foreach ( $date as $value) {
 110+ $updatedEnd .= $value;
85111 }
86 - $updatedEndDate .= "000000";
87 - }
88 - $this->updateNoticeDate( $noticeName, $updatedStartDate, $updatedEndDate );
 112+ $updatedEnd .= '000000';
 113+ }
 114+ $this->updateNoticeDate( $noticeName, $updatedStart, $updatedEnd );
89115 }
90 - $noticeName = $wgRequest->getVal('notice');
91 - $updatedWeights = $wgRequest->getArray('weight');
 116+
 117+ // Handle weight change
 118+ $updatedWeights = $wgRequest->getArray( 'weight' );
92119 if ( isset( $updatedWeights ) ) {
93 - foreach( $updatedWeights as $templateName => $weight) {
94 - $this->updateWeight( $noticeName, $templateName, $weight);
95 - }
 120+ foreach( $updatedWeights as $templateName => $weight ) {
 121+ $this->updateWeight( $noticeName, $templateName, $weight );
 122+ }
96123 }
97124 }
98 -
 125+
 126+ // Handle adding
99127 $method = $wgRequest->getVal('method');
100128 $this->showAll = $wgRequest->getVal('showAll');
101 -
102129 if ( $method == 'addNotice' ) {
103 - $noticeName = $wgRequest->getVal('noticeName');
104 - $start_min = $wgRequest->getVal('start_min');
105 - $start_day = $wgRequest->getVal('start_day');
106 - $start_month = $wgRequest->getVal('start_month');
107 - $start_year = $wgRequest->getVal('start_year');
108 - $start_hour = $wgRequest->getVal('start_hour');
109 - $project_name = $wgRequest->getVal('project_name');
110 - $project_language = $wgRequest->getVal('wpUserLanguage');
111 - if ( $noticeName == '') {
 130+ $noticeName = $wgRequest->getVal( 'noticeName' );
 131+ $start_min = $wgRequest->getVal( 'start_min' );
 132+ $start_day = $wgRequest->getVal( 'start_day' );
 133+ $start_month = $wgRequest->getVal( 'start_month' );
 134+ $start_year = $wgRequest->getVal( 'start_year' );
 135+ $start_hour = $wgRequest->getVal( 'start_hour' );
 136+ $project_name = $wgRequest->getVal( 'project_name' );
 137+ $project_language = $wgRequest->getVal( 'wpUserLanguage' );
 138+ if ( $noticeName == '' ) {
112139 $wgOut->addHtml( wfMsg ( 'centralnotice-null-string' ) );
113140 }
114141 else {
115142 $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $start_hour, $start_min, $project_name, $project_language );
116143 }
117144 }
 145+
 146+ // Handle removing
118147 if ( $method == 'removeNotice' ) {
119 - $noticeName = $wgRequest->getVal ('noticeName');
 148+ $noticeName = $wgRequest->getVal ( 'noticeName' );
120149 $this->removeNotice ( $noticeName );
121150 }
122 - if ( $method == 'addTemplateTo') {
123 - $noticeName = $wgRequest->getVal('noticeName');
124 - $templateName = $wgRequest->getVal('templateName');
125 - $this->addTemplateTo($noticeName, $templateName, 0);
 151+
 152+ // Handle adding of template
 153+ if ( $method == 'addTemplateTo' ) {
 154+ $noticeName = $wgRequest->getVal( 'noticeName' );
 155+ $templateName = $wgRequest->getVal( 'templateName' );
 156+ $this->addTemplateTo( $noticeName, $templateName, 0 );
126157 $this->listNoticeDetail( $noticeName );
127158 return;
128159 }
129 - if ( $method == 'removeTemplateFor') {
130 - $noticeName = $wgRequest->getVal ( 'noticeName');
 160+
 161+ // Handle removing of template
 162+ if ( $method == 'removeTemplateFor' ) {
 163+ $noticeName = $wgRequest->getVal ( 'noticeName' );
131164 $templateName = $wgRequest->getVal ( 'templateName ');
132165 $this->removeTemplateFor( $noticeName , $templateName );
133166 }
134 - if ( $method == 'listNoticeDetail') {
 167+
 168+ // Handle showing detail
 169+ if ( $method == 'listNoticeDetail' ) {
135170 $notice = $wgRequest->getVal ( 'notice' );
136171 $this->listNoticeDetail( $notice );
137172 return;
138173 }
139 -
 174+
 175+ // Show lsit of notices
140176 $this->listNotices();
141177 }
142 -
143 - private function updateEnabled( $update_notice, $enabled) {
144 - $centralnotice_table = "central_notice_campaign";
 178+
 179+ // Update the enabled/disabled state of notice
 180+ private function updateEnabled( $notice, $state ) {
145181 $dbw = wfGetDB( DB_MASTER );
146 - $res = $dbw->update($centralnotice_table, array( 'notice_enabled' => $enabled ), array( 'notice_name' => $update_notice));
 182+ $res = $dbw->update( 'cn_notices',
 183+ array( 'not_enabled' => $state ),
 184+ array( 'not_name' => $notice )
 185+ );
147186 }
148 -
 187+
149188 static public function printHeader() {
150189 global $wgOut;
151 - $wgOut->addWikiText( '[[' . 'Special:CentralNotice/listNotices ' . '|' . wfMsg( 'centralnotice-notices') . ']]' . " | "
152 - . '[[' . 'Special:NoticeTemplate/listTemplates' . '|' . wfMsg ( 'centralnotice-templates' ) . ']]' . " | "
153 - . '[[' . 'Special:NoticeTranslate/listTranslations' . '|' . wfMsg( 'centralnotice-translate') . ']]' . " | ");
 190+
 191+ $wgOut->addWikiText(
 192+ '[[Special:CentralNotice/listNotices |' .
 193+ wfMsg( 'centralnotice-notices') . ']] | ' .
 194+ '[[Special:NoticeTemplate/listTemplates|' .
 195+ wfMsg ( 'centralnotice-templates' ) . ']] |' .
 196+ '[[Special:NoticeTranslate/listTranslations|' .
 197+ wfMsg( 'centralnotice-translate') . ']]'
 198+ );
 199+ }
154200
155 - }
156 -
157201 function getNoticesName() {
158 - $centralnotice_table = "central_notice_campaign";
159202 $dbr = wfGetDB( DB_SLAVE );
160 - $res = $dbr->select( $centralnotice_table,"notice_name" );
 203+ $res = $dbr->select( 'cn_notices', 'not_name' );
161204 $notices = array();
162205 while ( $row = $dbr->fetchObject( $res )) {
163 - array_push( $notices, $row->notice_name);
 206+ array_push( $notices, $row->not_name);
164207 }
165208 return $notices;
166209 }
 210+
 211+ /*
 212+ * listNotices
 213+ *
 214+ * Print out all campaigns found in db
 215+ */
167216
168 - ####
169 - # listNotices
170 - ###
171 - # Print out all campaigns found in db
172 - ###
173 -
174217 function listNotices() {
175 - global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang;
176 -
177 - $centralnotice_table = "central_notice_campaign";
 218+ global $wgOut, $wgRequest, $wgTitle, $wgScript, $wgNoticeLang;
 219+
178220 $dbr = wfGetDB( DB_SLAVE );
179 - $this->showAll = 'Y'; //temp
 221+
 222+ /*
 223+ * This is temporarily hard-coded
 224+ */
 225+ $this->showAll = 'Y';
 226+
180227 if ( isset( $this->showAll )) {
181 - $res = $dbr->select( $centralnotice_table,
182 - "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_language, notice_locked",
183 - '',
184 - '',
185 - array('ORDER BY' => 'notice_id'),
186 - ''
187 - );
 228+ // Show only notices for all languages
 229+ $res = $dbr->select( 'cn_notices',
 230+ array(
 231+ 'not_name',
 232+ 'not_start',
 233+ 'not_end',
 234+ 'not_enabled',
 235+ 'not_project',
 236+ 'not_language',
 237+ 'not_locked'
 238+ ),
 239+ null,
 240+ __METHOD__,
 241+ array('ORDER BY' => 'not_id')
 242+ );
 243+ } else {
 244+ // Show only notices for this language
 245+ $res = $dbr->select( 'cn_notices',
 246+ array(
 247+ 'not_name',
 248+ 'not_start',
 249+ 'not_end',
 250+ 'not_enabled',
 251+ 'not_project',
 252+ 'not_locked'
 253+ ),
 254+ array ( 'not_language' => $wgNoticeLang ),
 255+ __METHOD__,
 256+ array('ORDER BY' => 'not_id')
 257+ );
188258 }
189 - else { //show only notices for this language
190 - $res = $dbr->select( $centralnotice_table,
191 - "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_locked",
192 - array ( "notice_language = '$wgNoticeLang'"),
193 - '',
194 - array('ORDER BY' => 'notice_id'),
195 - ''
196 - );
197 - }
198259
199 - $years = range( 2007, 2012);
200 - $months = range( 1, 12 );
201 - $months = array_map( array( $this, 'addZero'), $months );
202 - $days = range( 1 , 31);
203 - $days = array_map( array( $this, 'addZero'), $days);
204 - $hours = range( 0 , 23);
205 - $hours = array_map( array( $this, 'addZero'), $hours);
206 - $min = range( 0, 59, 15);
207 - $min = array_map( array( $this, 'addZero'), $min);
 260+ $years = range( 2007, 2012);
 261+ $months = range( 1, 12 );
 262+ $months = array_map( array( $this, 'addZero' ), $months );
 263+ $days = range( 1 , 31);
 264+ $days = array_map( array( $this, 'addZero' ), $days);
 265+ $hours = range( 0 , 23);
 266+ $hours = array_map( array( $this, 'addZero' ), $hours);
 267+ $min = range( 0, 59, 15);
 268+ $min = array_map( array( $this, 'addZero' ), $min);
208269
209 - $table = "<form name='centranoticeform' id='centralnoticeform' method='post'>";
210 - $table .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-manage" ) . "</legend>";
211 - $table .= "<table cellpadding=\"9\">";
212 - $table .= "<tr><th colspan = \"9\"></th></tr>";
213 - $table .= "<th>" . wfMsg ( 'centralnotice-notice-name') . "</th>";
214 - $table .= "<th>" . wfMsg ( 'centralnotice-project-name') . "</th>";
215 - if ( isset ( $this->showAll ) )
216 - $table .= "<th>" . wfMsg ( 'centralnotice-project-lang') . "</th>";
217 - $table .= "<th>" . wfMsg ( 'centralnotice-start-date') . "</th>";
218 - $table .= "<th>" . wfMsg ( 'centralnotice-end-date') . "</th>";
219 - $table .= "<th>" . wfMsg ( 'centralnotice-enabled') . "</th>";
220 - $table .= "<th>" . wfMsg ( 'centralnotice-locked') . "</th>";
221 - $table .= "<th>" . wfMsg ( 'centralnotice-remove') . "</th>";
222 - while ( $row = $dbr->fetchObject( $res )) {
223 - $table .= "<tr><td><a href=\"" . $this->getTitle()->getLocalUrl("method=listNoticeDetail&notice=$row->notice_name") . "\">$row->notice_name</a></td>";
224 - $table .= "<td>$row->notice_project</td>";
225 - if ( isset ( $this->showAll ))
226 - $table .= "<td>" . $row->notice_language . "</td>";
 270+ // Notices
 271+ $htmlOut = Xml::openElement( 'form',
 272+ array(
 273+ 'method' => 'post',
 274+ 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getFullUrl()
 275+ )
 276+ );
 277+ $htmlOut .= Xml::fieldset( wfMsgHtml( "centralnotice-manage" ) );
 278+ $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ) ;
 279+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-notice-name' ) );
 280+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-project-name' ) );
 281+ if ( isset ( $this->showAll ) ) {
 282+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-project-lang' ) );
 283+ }
 284+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-start-date' ) );
 285+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-end-date' ) );
 286+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-enabled' ) );
 287+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-locked' ) );
 288+ $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-remove' ) );
 289+ while ( $row = $dbr->fetchObject( $res ) ) {
 290+ $htmlLanguage = '';
 291+ if ( isset ( $this->showAll ) ) {
 292+ $htmlLanguage = Xml::tags( 'td', null,
 293+ $row->not_language
 294+ );
 295+ }
 296+ $htmlOut .= Xml::tags( 'tr', null,
 297+ Xml::tags( 'td', null,
 298+ Xml::element( 'a',
 299+ array(
 300+ 'href' => $this->getTitle()->getLocalUrl("method=listNoticeDetail&notice=$row->not_name")
 301+ ),
 302+ $row->not_name
 303+ )
 304+ ) .
 305+ Xml::tags( 'td', null,
 306+ $row->not_project
 307+ ) .
 308+ $htmlLanguage
 309+ );
227310
228 - $start_timestamp = $row->notice_start_date;
229 - $start_year = substr( $start_timestamp, 0 , 4);
230 - $start_month = substr( $start_timestamp, 4, 2);
231 - $start_day = substr( $start_timestamp, 6, 2);
232 - $start_hour = substr( $start_timestamp, 8, 2);
233 - $start_min = substr( $start_timestamp, 10, 2);
 311+ $start_timestamp = $row->not_start;
 312+ $start_year = substr( $start_timestamp, 0 , 4 );
 313+ $start_month = substr( $start_timestamp, 4, 2 );
 314+ $start_day = substr( $start_timestamp, 6, 2 );
 315+ $start_hour = substr( $start_timestamp, 8, 2 );
 316+ $start_min = substr( $start_timestamp, 10, 2 );
234317
235 - $end_timestamp = $row->notice_end_date;
236 - $end_year = substr( $end_timestamp, 0 , 4);
 318+ $end_timestamp = $row->not_end;
 319+ $end_year = substr( $end_timestamp, 0 , 4 );
237320 $end_month = substr( $end_timestamp, 4, 2);
238 - $end_day = substr( $end_timestamp, 6, 2);
239 -
240 - $table .= "<td>" . "$start_year/$start_month/$start_day" . " " . "$start_hour:$start_min" . "</td>";
241 - $table .= "<td>" . "$end_year/$end_month/$end_day" . "</td>";
242 - $enabled = ( $row->notice_enabled == 'Y' ) ? true : false;
243 - $table .= "<td>" . Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->notice_name)) . "</td>";
244 - // lock down to certain users
245 - $locked = ( $row->notice_locked == 'Y' ) ? true : false;
246 - $table .= "<td>" . Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>";
247 - $table .= "<td>" . Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>";
 321+ $end_day = substr( $end_timestamp, 6, 2 );
 322+
 323+ $htmlOut .= Xml::element( 'td', null,
 324+ "{$start_year}/{$start_month}/{$start_day} {$start_hour}:{$start_min}"
 325+ );
 326+ $htmlOut .= Xml::element( 'td' );
 327+ $htmlOut .= Xml::element( 'td', null,
 328+ "{$end_year}/{$end_month}/{$end_day}"
 329+ );
 330+ $htmlOut .= Xml::tags( 'td', null,
 331+ Xml::check( 'enabled[]', ( $row->not_enabled == 'Y' ),
 332+ array( 'value' => $row->not_name) )
 333+ );
 334+ $htmlOut .= Xml::tags( 'td', null,
 335+ Xml::check( 'locked[]', ( $row->not_locked == 'Y' ),
 336+ array( 'value' => $row->not_name) )
 337+ );
 338+ $htmlOut .= Xml::tags( 'td', null,
 339+ Xml::check( 'removeNotices[]', false,
 340+ array( 'value' => $row->not_name) )
 341+ );
248342 }
249 - $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify'),
250 - array('id' => 'centralnoticesubmit','name' => 'centralnoticesubmit') ) . "</td></tr>";
251 - $table .= "</table></fieldset></form>";
252 - $wgOut->addHTML( $table);
 343+ $htmlOut .= Xml::tags( 'tr', null,
 344+ Xml::tags( 'tr', null,
 345+ Xml::submitButton( wfMsgHtml('centralnotice-modify'),
 346+ array(
 347+ 'id' => 'centralnoticesubmit',
 348+ 'name' => 'centralnoticesubmit'
 349+ )
 350+ )
 351+ )
 352+ );
253353
 354+ $htmlOut .= Xml::closeElement( 'table' );
 355+ $htmlOut .= XML::closeElement( 'fieldset' );
 356+ $htmlOut .= XML::closeElement( 'form' );
 357+
 358+ // Other section
 359+
254360 $current_day = gmdate( 'd' );
255361 $current_month = gmdate( 'm');
256362 $current_year = gmdate( 'o' );
257363 $action = "addNotice";
258364
259 - global $wgNoticeProject,$wpUserLang;
 365+ global $wgNoticeProject, $wpUserLang;
260366
261367 list( $lsLabel, $lsSelect) = Xml::languageSelector( $wpUserLang );
262368 $languagebar = $this->tableRow( $lsLabel, $lsSelect) ;
263369
264 - $wgOut->addHtml(
265 - Xml::openElement( 'form', array(
266 - 'method' => 'post',
267 - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl())) .
268 - '<fieldset>' .
269 - Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-notice' ) ) .
270 - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
271 - Xml::hidden( 'method', $action ) .
272 - '<p>' .
273 - Xml::inputLabel( wfMsg( 'centralnotice-notice-name' ),
274 - 'noticeName', 'noticeName', 25) .
275 - " " . Xml::label( wfMsg('centralnotice-start-date'), 'start-date') . ": " .
276 - Xml::listDropDown( 'start_month', $this->dropDownList( wfMsg( 'centralnotice-month'), $months ), '', $current_month, '', 6 ) .
277 - Xml::listDropDown( 'start_day', $this->dropDownList( wfMsg( 'centralnotice-day'), $days ), '', $current_day, '', 7 ) .
278 - Xml::listDropDown( 'start_year', $this->dropDownList( wfMsg( 'centralnotice-year'), $years ), '', $current_year, '', 8) .
279 - " " . wfMsg( 'centralnotice-start-hour' ) . "(GMT)" . ": " .
280 - Xml::listDropDown( 'start_hour', $this->dropDownList( wfMsg( 'centralnotice-hours'), $hours), '', "00", '', 9) .
281 - Xml::listDropDown( 'start_min', $this->dropDownList( wfMsg( 'centralnotice-min'), $min), '', "00", '', 10) . "<p>" .
282 - " " . wfMsg( 'centralnotice-project-name' ) . ": " .
283 - Xml::listDropDown( 'project_name', wfMsg( 'centralnotice-project-name-list'), '', $wgNoticeProject, '', 11) .
284 - " " . $languagebar .
285 - '</p>' .
286 - '<p>' .
287 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
288 - '</p>' .
289 - '</fieldset>' .
290 - '</form>'
291 - );
 370+ $htmlOut .= Xml::openElement( 'form',
 371+ array(
 372+ 'method' => 'post',
 373+ 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl()
 374+ )
 375+ );
 376+ $htmlOut .= Xml::openElement( 'fieldset' );
 377+ $htmlOut .= Xml::element( 'legend', null, wfMsg( 'centralnotice-add-template' ) );
 378+ $htmlOut .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() );
 379+ $htmlOut .= Xml::hidden( 'method', $action );
 380+ $htmlOut .= Xml::tags( 'p', null,
 381+ Xml::inputLabel(
 382+ wfMsg( 'centralnotice-notice-name' ),
 383+ 'noticeName',
 384+ 'noticeName',
 385+ 25
 386+ ) .
 387+ ' ' . Xml::label( wfMsg('centralnotice-start-date'), 'start-date') . ': ' .
 388+ Xml::listDropDown( 'start_month', $this->dropDownList( wfMsg( 'centralnotice-month'), $months ), '', $current_month, '', 6 ) .
 389+ Xml::listDropDown( 'start_day', $this->dropDownList( wfMsg( 'centralnotice-day'), $days ), '', $current_day, '', 7 ) .
 390+ Xml::listDropDown( 'start_year', $this->dropDownList( wfMsg( 'centralnotice-year'), $years ), '', $current_year, '', 8) .
 391+ ' ' . wfMsg( 'centralnotice-start-hour' ) . "(GMT)" . ': ' .
 392+ Xml::listDropDown( 'start_hour', $this->dropDownList( wfMsg( 'centralnotice-hours'), $hours), '', "00", '', 9) .
 393+ Xml::listDropDown( 'start_min', $this->dropDownList( wfMsg( 'centralnotice-min'), $min), '', "00", '', 10)
 394+ );
 395+ $htmlOut .= wfMsg( 'centralnotice-project-name' ) . ': ';
 396+ $htmlOut .= Xml::listDropDown( 'project_name', wfMsg( 'centralnotice-project-name-list'), '', $wgNoticeProject, '', 11);
 397+ $htmlOut .= ' ' . $languagebar;
 398+ $htmlOut .= Xml::submitButton( wfMsg( 'centralnotice-modify' ) );
 399+ $htmlOut .= Xml::closeElement( 'fieldset' );
 400+ $htmlOut .= Xml::closeElement( 'form' );
 401+
 402+ $wgOut->addHTML( $htmlOut );
292403 }
293 -
 404+
294405 function tableRow( $td1, $td2 ) {
295 - $td3 = '';
296 - $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
297 - $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
298 - return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
299 - }
300 -
 406+ return Xml::tags( 'tr', null,
 407+ Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 ) .
 408+ Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 )
 409+ );
 410+ }
 411+
301412 function listNoticeDetail( $notice ) {
302 - global $wgOut,$wgRequest;
303 -
304 - $eNotice = htmlspecialchars( $notice );
305 -
306 - if ($wgRequest->wasPosted()) {
307 - $templateToRemove = $wgRequest->getArray('removeTemplates');
308 - if (isset( $templateToRemove )) {
309 - foreach ($templateToRemove as $template) {
310 - $this->removeTemplateFor( $eNotice, $template);
 413+ global $wgOut, $wgRequest;
 414+
 415+ if ( $wgRequest->wasPosted() ) {
 416+ // Handle removing of templates
 417+ $templateToRemove = $wgRequest->getArray( 'removeTemplates' );
 418+ if ( isset( $templateToRemove ) ) {
 419+ foreach ( $templateToRemove as $template ) {
 420+ $this->removeTemplateFor( $notice, $template );
311421 }
312422 }
313 - $weights = $wgRequest->getArray('weights');
314 - if (isset( $weights )) {
315 - }
316 - $templatesToAdd = $wgRequest->getArray('addTemplates');
317 - if (isset( $templatesToAdd )) {
318 - foreach ($templatesToAdd as $template) {
319 - $this->addTemplateTo( $notice, $template, 0);
 423+
 424+ // Handle weight change
 425+ $weights = $wgRequest->getArray( 'weights' );
 426+ if ( isset( $weights ) ) {
 427+ // Do something?
 428+ }
 429+
 430+ // Handle adding of templates
 431+ $templatesToAdd = $wgRequest->getArray( 'addTemplates' );
 432+ if ( isset( $templatesToAdd ) ) {
 433+ foreach ( $templatesToAdd as $template ) {
 434+ $this->addTemplateTo( $notice, $template, 0 );
320435 }
321436 }
322 -
323437 }
324 -
325 - $centralnotice_table = "central_notice_campaign";
 438+
326439 $dbr = wfGetDB( DB_SLAVE );
327 - $this->showAll = 'Y'; //temp
328 - if ( isset( $this->showAll )) {
329 - $res = $dbr->select( $centralnotice_table,
330 - "notice_name, notice_start_date, notice_end_date,
331 - notice_enabled, notice_project, notice_language, notice_locked",
332 - "notice_name = '$notice'",
333 - '',
334 - array('ORDER BY' => 'notice_id'),
335 - ''
336 - );
337 - }
338 -
 440+
 441+ /*
 442+ * Temporarily hard coded
 443+ */
 444+ $this->showAll = 'Y';
 445+
 446+ if ( isset( $this->showAll )) {
 447+ $res = $dbr->select( 'cn_notices',
 448+ array(
 449+ 'not_name',
 450+ 'not_start',
 451+ 'not_end',
 452+ 'not_enabled',
 453+ 'not_project',
 454+ 'not_language',
 455+ 'not_locked'
 456+ ),
 457+ array( 'not_name' => $notice ),
 458+ __METHOD__,
 459+ array( 'ORDER BY' => 'not_id' )
 460+ );
 461+ }
 462+
339463 $years = range( 2007, 2012);
340 - $months = range( 1, 12 );
341 - $months = array_map( array( $this, 'addZero'), $months );
342 - $days = range( 1 , 31);
343 - $days = array_map( array( $this, 'addZero'), $days);
344 - $hours = range( 0 , 23);
345 - $hours = array_map( array( $this, 'addZero'), $hours);
346 - $min = range( 0, 59, 15);
347 - $min = array_map( array( $this, 'addZero'), $min);
 464+ $months = range( 1, 12 );
 465+ $months = array_map( array( $this, 'addZero'), $months );
 466+ $days = range( 1 , 31);
 467+ $days = array_map( array( $this, 'addZero'), $days);
 468+ $hours = range( 0 , 23);
 469+ $hours = array_map( array( $this, 'addZero'), $hours);
 470+ $min = range( 0, 59, 15);
 471+ $min = array_map( array( $this, 'addZero'), $min);
348472
349473
 474+ /*
 475+ * Needs to be refactored to use the Xml class
 476+ *
 477+ */
350478 $table = Xml::openElement( 'form', array(
351479 'method' => 'post',
352480 'action' => ''));
@@ -363,53 +491,57 @@
364492
365493 while ( $row = $dbr->fetchObject( $res )) {
366494
367 - $start_timestamp = $row->notice_start_date;
 495+ $start_timestamp = $row->not_start;
368496 $start_year = substr( $start_timestamp, 0 , 4);
369497 $start_month = substr( $start_timestamp, 4, 2);
370498 $start_day = substr( $start_timestamp, 6, 2);
371499 $start_hour = substr( $start_timestamp, 8, 2);
372500 $start_min = substr( $start_timestamp, 10, 2);
373501
374 - $end_timestamp = $row->notice_end_date;
 502+ $end_timestamp = $row->not_end;
375503 $end_year = substr( $end_timestamp, 0 , 4);
376504 $end_month = substr( $end_timestamp, 4, 2);
377505 $end_day = substr( $end_timestamp, 6, 2);
378506
 507+ /*
 508+ * Needs to be refactored to use the Xml class
 509+ *
 510+ */
379511 $table .= "<tr><td>" .
380 - $row->notice_project .
 512+ $row->not_project .
381513 "</td>" .
382514 "<td>" .
383 - $row->notice_language .
 515+ $row->not_language .
384516 "</td>" .
385517 "<td>" .
386 - Xml::listDropDown( "start_date[$row->notice_name][year]",
 518+ Xml::listDropDown( "start[$row->not_name][year]",
387519 $this->dropDownList( wfMsg( 'centralnotice-year'), $years ), '', $start_year, '', 3) .
388 - Xml::listDropDown( "start_date[$row->notice_name][month]",
 520+ Xml::listDropDown( "start[$row->not_name][month]",
389521 $this->dropDownList( wfMsg( 'centralnotice-month'), $months), '', $start_month, '', 4 ) .
390 - Xml::listDropDown( "start_date[$row->notice_name][day]",
 522+ Xml::listDropDown( "start[$row->not_name][day]",
391523 $this->dropDownList( wfMsg( 'centralnotice-day' ), $days ) , '', $start_day, '', 5) .
392 - Xml::listDropDown( "start_date[$row->notice_name][hour]",
 524+ Xml::listDropDown( "start[$row->not_name][hour]",
393525 $this->dropDownList( wfMsg( 'centralnotice-hours'), $hours), '', $start_hour, '', 6) .
394 - Xml::listDropDown( "start_date[$row->notice_name][min]",
 526+ Xml::listDropDown( "start[$row->not_name][min]",
395527 $this->dropDownList( wfMsg( 'centralnotice-min'), $min), '', $start_min, '', 7) .
396528 "</td>";
397529 $table .= "<td>" .
398 - Xml::listDropDown( "end_date[$row->notice_name][year]",
 530+ Xml::listDropDown( "end[$row->not_name][year]",
399531 $this->dropDownList( wfMsg( 'centralnotice-year'), $years ), '', $end_year, '', 8) .
400 - Xml::listDropDown( "end_date[$row->notice_name][month]",
 532+ Xml::listDropDown( "end[$row->not_name][month]",
401533 $this->dropDownList( wfMsg( 'centralnotice-month'), $months ), '', $end_month, '', 9 ) .
402 - Xml::listDropDown( "end_date[$row->notice_name][day]",
 534+ Xml::listDropDown( "end[$row->not_name][day]",
403535 $this->dropDownList( wfMsg( 'centralnotice-day'), $days ), '', $end_day, '', 10 ) .
404536 "</td>";
405537
406 - $enabled = ( $row->notice_enabled == 'Y' ) ? true : false;
 538+ $enabled = ( $row->not_enabled == 'Y' ) ? true : false;
407539 $table .= "<td>" .
408 - Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->notice_name)) . "</td>";
409 - $locked = ( $row->notice_locked == 'Y' ) ? true : false;
 540+ Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->not_name)) . "</td>";
 541+ $locked = ( $row->not_locked == 'Y' ) ? true : false;
410542 $table .= "<td>" .
411 - Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>";
 543+ Xml::check( 'locked[]', $locked, array ( 'value' => $row->not_name)) . "</td>";
412544 $table .= "<td>" .
413 - Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>";
 545+ Xml::check( 'removeNotices[]', false, array( 'value' => $row->not_name)) . "</td>";
414546 }
415547 $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) . "</tr></td";
416548 $table .= Xml::closeElement( 'table' );
@@ -417,15 +549,15 @@
418550 $table .= "</fieldset>";
419551 $wgOut->addHtml( $table ) ;
420552
421 - $res = $dbr->select( array ( $centralnotice_table,
422 - "central_notice_template_assignments",
423 - "central_notice_templates"),
424 - "template_name,template_weight",
425 - array ( 'notice_name' => $eNotice,
426 - 'campaign_id = notice_id',
427 - 'central_notice_template_assignments.template_id = central_notice_templates.template_id'),
 553+ $res = $dbr->select( array ( 'cn_notices',
 554+ "cn_assignments",
 555+ "cn_templates"),
 556+ "tmp_name,tmp_weight",
 557+ array ( 'not_name' => $eNotice,
 558+ 'not_id = not_id',
 559+ 'cn_assignments.tmp_id = cn_templates.tmp_id'),
428560 '',
429 - array('ORDER BY' => 'notice_id'),
 561+ array('ORDER BY' => 'not_id'),
430562 ''
431563 );
432564 if ( $dbr->numRows( $res ) < 1) {
@@ -434,6 +566,10 @@
435567 return;
436568 }
437569
 570+ /*
 571+ * Needs to be refactored to use the Xml class
 572+ *
 573+ */
438574 $table = "<form name='centranoticeform' id='centralnoticeform' method='post'>";
439575 $table .= '<fieldset><legend>' . $eNotice . "</legend>";
440576 $table .= "<table cellpadding=\"9\">";
@@ -442,9 +578,9 @@
443579 $table .= "<th>" . wfMsg ( "centralnotice-weight" ) . "</th>";
444580 $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>";
445581 while ( $row = $dbr->fetchObject( $res )) {
446 - $table .= "<tr><td>" . Xml::label($row->template_name, 'name') . "</td>";
447 - $table .= "<td>" . Xml::listDropDown( "weight[$row->template_name]", $this->dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5) ), '', $row->template_weight, '', 1) . "</td>";
448 - $table .= "<td>" . Xml::check( 'removeTemplates[]', false, array( 'value' => $row->template_name)) . "</td></tr>";
 582+ $table .= "<tr><td>" . Xml::label($row->tmp_name, 'name') . "</td>";
 583+ $table .= "<td>" . Xml::listDropDown( "weight[$row->tmp_name]", $this->dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5) ), '', $row->tmp_weight, '', 1) . "</td>";
 584+ $table .= "<td>" . Xml::check( 'removeTemplates[]', false, array( 'value' => $row->tmp_name)) . "</td></tr>";
449585 }
450586 $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify') ) . "</td></tr>";
451587 $table .= "</table></fieldset></form>";
@@ -453,13 +589,9 @@
454590 }
455591
456592 function addTemplatesForm() {
457 - $centralnotice_table = 'central_notice_templates';
458593 $dbr = wfGetDB( DB_SLAVE );
459 - $res = $dbr->select( $centralnotice_table,
460 - "template_name",
461 - '',
462 - '',
463 - array('ORDER BY' => 'template_id'));
 594+ $res = $dbr->select( 'cn_notices', 'tmp_name', '', '', array( 'ORDER BY' => 'tmp_id' ) );
 595+
464596 $table = "<form name='centranoticeform' id='centralnoticeform' method='post'>";
465597 $table .= '<fieldset><legend>' . wfMsg( "centralnotice-available-templates") . '</legend>';
466598 $table .= "<table cellpadding=\"9\">";
@@ -467,32 +599,36 @@
468600 $table .= "<th>" . wfMsg ( 'centralnotice-template-name') . "</th>";
469601 $table .= "<th>" . wfMsg ( 'centralnotice-add' ) . "</th>";
470602 while ( $row = $dbr->fetchObject( $res )) {
471 - $table .= "<tr><td>" . $row->template_name . "</td>";
472 - $table .= "<td>" . Xml::check( 'addTemplates[]', '', array ( 'value' => $row->template_name)) . "</td></tr>";
 603+ $table .= "<tr><td>" . $row->tmp_name . "</td>";
 604+ $table .= "<td>" . Xml::check( 'addTemplates[]', '', array ( 'value' => $row->tmp_name)) . "</td></tr>";
473605 }
474606 $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify')) . "</td></tr>";
475607 $table .= "</table></fieldset></form>";
476608 return $table;
477609 }
478 -
479 - public function getTemplatesForNotice ( $noticeName ) {
 610+
 611+ public function getTemplatesForNotice ( $noticeName ) {
480612 $dbr = wfGetDB( DB_SLAVE );
481 - $centralnotice_table = 'central_notice_template_assignments';
482 -
483 - $eNoticeName = mysql_real_escape_string( $noticeName ) ;
484 - $res = $dbr->select( array (
485 - $centralnotice_table, "central_notice_campaign","central_notice_templates"),
486 - "template_name,template_weight",
487 - array (
488 - 'notice_name' => $eNoticeName,
489 - 'campaign_id = notice_id'),
490 - '',
491 - array(
492 - 'ORDER BY' => 'notice_id'),
493 - ''
494 - );
 613+
 614+ $res = $dbr->select(
 615+ array(
 616+ 'cn_notices',
 617+ 'cn_notices',
 618+ 'cn_templates'
 619+ ),
 620+ array(
 621+ 'tmp_name',
 622+ 'tmp_weight'
 623+ ),
 624+ array(
 625+ 'not_name' => $noticeName,
 626+ 'not_id' => 'not_id'
 627+ ),
 628+ __METHOD__,
 629+ array( 'ORDER BY' => 'not_id' )
 630+ );
495631 $templates = array();
496 - while ( $row = $dbr->fetchObject( $res )) {
 632+ while ( $row = $dbr->fetchObject( $res ) ) {
497633 $templates[$row->name] = $row->weight;
498634 }
499635 return $templates;
@@ -501,58 +637,50 @@
502638
503639 function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $start_hour, $start_min, $project_name, $project_language ) {
504640 global $wgOut;
 641+
505642 $dbr = wfGetDB( DB_SLAVE );
506 - $centralnotice_table = 'central_notice_campaign';
507643 $start_hour = substr( $start_hour, 0 , 2 );
508 -
509 - $eNoticeName = mysql_real_escape_string( $noticeName ) ;
510 - $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$eNoticeName' " );
 644+ $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) );
511645 if ( $dbr->numRows( $res ) > 0 ) {
512646 $wgOut->addHTML( wfMsg( 'centralnotice-notice-exists' ) );
513647 return;
514648 }
515649 else {
516650 $dbw = wfGetDB( DB_MASTER );
517 - $start_date = wfTimeStamp( TS_MW, $start_year . ":" .
518 - $start_month . ":" .
519 - $start_day . " " .
520 - $start_hour . ":" .
521 - $start_min . ":00");
522 - if ( $start_month == 12) {
 651+ $start = wfTimeStamp( TS_MW, "{$end_year}:{$end_month}:{$start_day} {$start_hour}:00:00");
 652+ if ( $start_month == 12 ) {
523653 $end_month = '01';
524654 $end_year = ($start_year + 1);
525 - }
526 - elseif ( $start_month == '09' ) {
 655+ } elseif ( $start_month == '09' ) {
527656 $end_month = '10';
528657 $end_year = $start_year;
529 - }
530 - else {
531 - $end_month = (substr ( $start_month, 0, 1)) == 0 ? 0 . (intval($start_month) + 1) : ($start_month + 1);
 658+ } else {
 659+ $end_month = ( substr( $start_month, 0, 1) ) == 0 ? 0 . ( intval( $start_month ) + 1 ) : ( $start_month + 1 );
532660 $end_year = $start_year;
533661 }
534 - $end_date = wfTimeStamp( TS_MW, $end_year . ":" .
535 - $end_month . ":" .
536 - $start_day . " " .
537 - $start_hour . ":" .
538 - "00" . ":00");
539 -
540 - $res = $dbr->select( $centralnotice_table, 'notice_name',
541 - array ( "notice_start_date >= '$start_date'",
542 - "notice_end_date <= '$end_date'",
543 - "notice_project = '$project_name'",
544 - "notice_language = '$project_language'") );
 662+ $end = wfTimeStamp( TS_MW, "{$end_year}:{$end_month}:{$start_day} {$start_hour}:00:00" );
 663+
 664+ $res = $dbr->select( 'cn_notices', 'not_name',
 665+ array (
 666+ "not_start >= '{$start}'",
 667+ "not_end <= '{$end}'",
 668+ 'not_project' => $project_name,
 669+ 'not_language' => $project_language
 670+ )
 671+ );
545672 if ( $dbr->numRows( $res ) > 0 ) {
546 - $wgOut->addHtml( wfMsg( 'centralnotice-overlap'));
 673+ $wgOut->addHtml( wfMsg( 'centralnotice-overlap' ) );
 674+ } else {
 675+ $res = $dbw->insert( 'cn_notices',
 676+ array( 'not_name' => $noticeName,
 677+ 'not_enabled' => $enabled,
 678+ 'not_start' => $start,
 679+ 'not_end' => $end,
 680+ 'not_project' => $project_name,
 681+ 'not_language' => $project_language
 682+ )
 683+ );
547684 }
548 - else {
549 - $res = $dbw->insert( $centralnotice_table,
550 - array( 'notice_name' => "$noticeName",
551 - 'notice_enabled' => "$enabled",
552 - 'notice_start_date' => "$start_date",
553 - 'notice_end_date' => "$end_date",
554 - 'notice_project' => $project_name,
555 - 'notice_language' => $project_language));
556 - }
557685 return;
558686 }
559687 }
@@ -560,170 +688,187 @@
561689 function removeNotice ( $noticeName ) {
562690 global $wgOut;
563691 $dbr = wfGetDB( DB_SLAVE );
564 - $centralnotice_table = 'central_notice_campaign';
565 -
 692+
566693 $eNoticeName = mysql_real_escape_string( $noticeName ) ;
567 - $res = $dbr->select( $centralnotice_table, 'notice_name, notice_locked', "notice_name = '$eNoticeName' " );
 694+ $res = $dbr->select( 'cn_notices', 'not_name, not_locked',
 695+ array( 'not_name' => $eNoticeName )
 696+ );
568697 if ( $dbr->numRows( $res ) < 1 ) {
569698 $wgOut->addHTML( wfMsg( 'centralnotice-notice-doesnt-exist' ) );
570699 return;
571700 }
572701 $row = $dbr->fetchObject( $res );
573 - if ( $row->notice_locked == 'Y' ) {
 702+ if ( $row->not_locked == 'Y' ) {
574703 $wgOut->addHTML( wfMsg( 'centralnotice-notice-is-locked' ) );
575704 return;
576 - }
577 - else {
 705+ } else {
578706 $dbw = wfGetDB( DB_MASTER );
579 - $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
580 - $res = $dbw->delete( "central_notice_template_assignments", array ( 'campaign_id' => $noticeId));
581 - $res = $dbw->delete( $centralnotice_table, array ( 'notice_name' => "$noticeName"));
 707+ $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ) );
 708+ $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $noticeId ) );
 709+ $res = $dbw->delete( 'cn_notices', array ( 'not_name' => $noticeName ) );
582710 return;
583711 }
584712 }
585 -
586 - function addTemplateTo( $noticeName, $templateName, $weight) {
 713+
 714+ function addTemplateTo( $noticeName, $templateName, $weight ) {
587715 global $wgOut;
588 - $centralnotice_table = "central_notice_template_assignments";
589716
590717 $dbr = wfGetDB( DB_SLAVE );
591718 $eNoticeName = mysql_real_escape_string( $noticeName );
592719 $eTemplateName = mysql_real_escape_string( $templateName );
593720 $eWeight = mysql_real_escape_string ( $weight );
594 -
 721+
595722 $noticeId = $this->getNoticeId( $noticeName );
596723 $templateId = $this->getTemplateId( $templateName );
597 - $res = $dbr->select( $centralnotice_table, 'template_assignment_id',
598 - array(
599 - 'template_id' => $templateId,
600 - 'campaign_id' => $noticeId));
601 - if ( $dbr->numRows( $res ) > 0) {
 724+ $res = $dbr->select( 'cn_assignments', 'asn_id',
 725+ array(
 726+ 'tmp_id' => $templateId,
 727+ 'not_id' => $noticeId
 728+ )
 729+ );
 730+ if ( $dbr->numRows( $res ) > 0 ) {
602731 $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) );
603 - }
604 - else {
 732+ } else {
605733 $dbw = wfGetDB( DB_MASTER );
606734 $noticeId = $this->getNoticeId( $eNoticeName );
607 - $res = $dbw->insert($centralnotice_table, array( 'template_id' => $templateId, 'template_weight' => $eWeight, 'campaign_id' => $noticeId));
 735+ $res = $dbw->insert('cn_assignments',
 736+ array(
 737+ 'tmp_id' => $templateId,
 738+ 'tmp_weight' => $eWeight,
 739+ 'not_id' => $noticeId
 740+ )
 741+ );
608742 }
609743 }
610744
611745 function getNoticeId ( $noticeName ) {
612746 $dbr = wfGetDB( DB_SLAVE );
613 - $centralnotice_table = 'central_notice_campaign';
614747 $eNoticeName = htmlspecialchars( $noticeName );
615 - $res = $dbr->select( $centralnotice_table, 'notice_id', "notice_name = '$eNoticeName'");
 748+ $res = $dbr->select( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
616749 $row = $dbr->fetchObject( $res );
617 - return $row->notice_id;
 750+ return $row->not_id;
618751 }
619752
620753 function getNoticeLanguage ( $noticeName ) {
621754 $dbr = wfGetDB( DB_SLAVE );
622 - $centralnotice_table = 'central_notice_campaign';
623755 $eNoticeName = htmlspecialchars( $noticeName );
624 - $res = $dbr->select( $centralnotice_table, 'notice_language', "notice_name = '$eNoticeName'");
 756+ $res = $dbr->select( 'cn_notices', 'not_language', array( 'not_name' => $eNoticeName ) );
625757 $row = $dbr->fetchObject( $res );
626 - return $row->notice_language;
 758+ return $row->not_language;
627759 }
628760
629761 function getNoticeProjectName ( $noticeName ) {
630762 $dbr = wfGetDB( DB_SLAVE );
631 - $centralnotice_table = 'central_notice_campaign';
632763 $eNoticeName = htmlspecialchars( $noticeName );
633 - $res = $dbr->select( $centralnotice_table, 'notice_project', "notice_name = '$eNoticeName'");
 764+ $res = $dbr->select( 'cn_notices', 'not_project', array( 'not_name' => $eNoticeName ) );
634765 $row = $dbr->fetchObject( $res );
635 - return $row->notice_project;
 766+ return $row->not_project;
636767 }
637768
638769 function getTemplateId ( $templateName ) {
639770 $dbr = wfGetDB( DB_SLAVE );
640 - $centralnotice_table = 'central_notice_templates';
641771 $templateName = htmlspecialchars ( $templateName );
642 - $res = $dbr->select( $centralnotice_table, 'template_id', "template_name = '$templateName'");
 772+ $res = $dbr->select( 'cn_templates', 'tmp_id', array( 'tmp_name' => $templateName ) );
643773 $row = $dbr->fetchObject( $res );
644 - return $row->template_id;
 774+ return $row->tmp_id;
645775 }
646 -
 776+
647777 function removeTemplateFor( $noticeName, $templateName) {
648778 global $wgOut;
649 - $centralnotice_table = "central_notice_template_assignments";
 779+
650780 $dbw = wfGetDB( DB_MASTER );
651781 $noticeId = $this->getNoticeId( $noticeName );
652782 $templateId = $this->getTemplateId( $templateName );
653 - $res = $dbw->delete( $centralnotice_table, array ( 'template_id' => "$templateId", 'campaign_id' => $noticeId));
 783+ $res = $dbw->delete( 'cn_assignments', array ( 'tmp_id' => $templateId, 'not_id' => $noticeId ) );
654784 }
655785
656 - function updateNoticeDate ( $noticeName, $startDate, $endDate ) {
 786+ function updateNoticeDate ( $noticeName, $start, $end ) {
657787 global $wgOut;
658 - $centralnotice_table = "central_notice_campaign";
 788+
659789 $dbr = wfGetDB( DB_SLAVE );
660790 $project_name = $this->getNoticeProjectname( $noticeName );
661791 $project_language = $this->getNoticeLanguage( $noticeName );
662792
663 - // start / end dont line up
664 - if ( $startDate > $endDate || $endDate < $startDate) {
665 - $wgOut->addHtml( wfMsg( 'centralnotice-invalid-date-range3' ));
 793+ // Start / end dont line up
 794+ if ( $start > $end || $end < $start) {
 795+ $wgOut->addHtml( wfMsg( 'centralnotice-invalid-date-range3' ) );
666796 return;
667797 }
668 - // invalid notice name
669 - $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$noticeName'" );
670 - if ($dbr->numRows( $res ) < 1) {
671 - $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
 798+
 799+ // Invalid notice name
 800+ $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) );
 801+ if ( $dbr->numRows( $res ) < 1 ) {
 802+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist' ) );
672803 }
673 - // overlap over a date within the same project and language
674 - $res = $dbr->select( $centralnotice_table, 'notice_id',
675 - array( "notice_language =" . $dbr->addQuotes( $project_language ),
676 - "notice_project =" . $dbr->addQuotes( $project_name ),
677 - "notice_end_date <=" . $dbr->addQuotes( $dbr->timestamp($endDate),
678 - "notice_start_date >=" . $dbr->addQuotes( $dbr->timestamp($startDate)
679 - ))));
 804+
 805+ // Overlap over a date within the same project and language
 806+ $res = $dbr->select( 'cn_notices', 'not_id',
 807+ array(
 808+ 'not_language' => $project_language,
 809+ 'not_project' => $project_name,
 810+ 'not_end' <= $dbr->addQuotes( $dbr->timestamp( $end ) ),
 811+ 'not_start' >= $dbr->addQuotes( $dbr->timestamp( $start ) )
 812+ )
 813+ );
680814 if ( $dbr->numRows( $res ) > 1 ) {
681 - $wgOut->addHtml( wfMsg( 'centralnotice-overlap-with-existing-notice' ));
 815+ $wgOut->addHtml( wfMsg( 'centralnotice-overlap-with-existing-notice' ) );
682816 return;
683 - }
684 - else {
 817+ } else {
685818 $dbw = wfGetDB( DB_MASTER );
686 - $res = $dbw->update( $centralnotice_table,
687 - array( 'notice_start_date' => $startDate,
688 - 'notice_end_date' => $endDate
689 - ),
690 - array( "notice_name =" . $dbr->addQuotes( $noticeName))
691 - );
 819+ $res = $dbw->update( 'cn_notices',
 820+ array(
 821+ 'not_start' => $start,
 822+ 'not_end' => $end
 823+ ),
 824+ array( 'not_name' => $noticeName )
 825+ );
692826 }
693827 }
694828
695829 function updateLock ( $noticeName, $isLocked ) {
696830 global $wgOut;
697 - $centralnotice_table = 'central_notice_campaign';
 831+
698832 $dbr = wfGetDB( DB_SLAVE );
699 - $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$noticeName'" );
700 - if ($dbr->numRows( $res ) < 1) {
701 - $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
702 - }
703 - else {
 833+ $res = $dbr->select( 'cn_notices', 'not_name',
 834+ array( 'not_name' => $noticeName )
 835+ );
 836+ if ( $dbr->numRows( $res ) < 1 ) {
 837+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist') );
 838+ } else {
704839 $dbw = wfGetDB( DB_MASTER );
705 - $res = $dbw->update( $centralnotice_table, array( 'notice_locked' => $isLocked ), array( 'notice_name' => $noticeName));
 840+ $res = $dbw->update( 'cn_notices',
 841+ array( 'not_locked' => $isLocked ),
 842+ array( 'not_name' => $noticeName )
 843+ );
706844 }
707845 }
708846
709847 function updateWeight ( $noticeName, $templateName, $weight ) {
710 - $centralnotice_table = 'central_notice_template_assignments';
711848 $dbw = wfGetDB( DB_MASTER );
712849 $noticeId = $this->getNoticeId( $noticeName );
713850 $templateId = $this->getTemplateId( $templateName );
714 - $res = $dbw->update( $centralnotice_table, array ( 'template_weight' => $weight ), array( 'template_id' => $templateId, 'campaign_id' => $noticeId));
 851+ $res = $dbw->update( 'cn_assignments',
 852+ array ( 'tmp_weight' => $weight ),
 853+ array(
 854+ 'tmp_id' => $templateId,
 855+ 'not_id' => $noticeId
 856+ )
 857+ );
715858 }
716859
717860 function dropDownList ( $text, $values ) {
718 - $dropDown = "* $text\n";
 861+ $dropDown = "* {$text}\n";
719862 foreach( $values as $element ) {
720 - $dropDown .= "**$element\n";
 863+ $dropDown .= "**{$element}\n";
721864 }
722865 return $dropDown;
723866 }
724 -
 867+
725868 function addZero ( $text ) {
726 - if ( strlen( $text ) == 1 ) // append a 0 for text needing it
727 - $text = 0 . $text;
 869+ // Prepend a 0 for text needing it
 870+ if ( strlen( $text ) == 1 ) {
 871+ $text = "0{$text}";
 872+ }
728873 return $text;
729874 }
730875 }
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.sql
@@ -1,25 +1,25 @@
2 -CREATE TABLE `central_notice_campaign` (
3 - `notice_id` int NOT NULL auto_increment,
4 - `notice_name` varchar(255) NOT NULL,
5 - `notice_start_date` char(14) NOT NULL,
6 - `notice_end_date` char(14) NOT NULL,
7 - `notice_enabled` bool NOT NULL default '0',
8 - `notice_locked` bool NOT NULL default '0',
9 - `notice_language` char(2) NOT NULL,
10 - `notice_project` varchar(255) NOT NULL,
11 - PRIMARY KEY (`notice_id`)
 2+CREATE TABLE `cn_notices` (
 3+ `not_id` int NOT NULL auto_increment,
 4+ `not_name` varchar(255) NOT NULL,
 5+ `not_start` char(14) NOT NULL,
 6+ `not_end` char(14) NOT NULL,
 7+ `not_enabled` bool NOT NULL default '0',
 8+ `not_locked` bool NOT NULL default '0',
 9+ `not_language` char(2) NOT NULL,
 10+ `not_project` varchar(255) NOT NULL,
 11+ PRIMARY KEY (`not_id`)
1212 ) /*$wgDBTableOptions*/;
1313
14 -CREATE TABLE `central_notice_template_assignments` (
15 - `template_assignment_id` int NOT NULL auto_increment,
16 - `template_id` int NOT NULL,
17 - `campaign_id` int NOT NULL,
18 - `template_weight` int NOT NULL,
19 - PRIMARY KEY (`template_assignment_id`)
 14+CREATE TABLE `cn_assignments` (
 15+ `asn_id` int NOT NULL auto_increment,
 16+ `not_id` int NOT NULL,
 17+ `tmp_id` int NOT NULL,
 18+ `tmp_weight` int NOT NULL,
 19+ PRIMARY KEY (`asn_id`)
2020 ) /*$wgDBTableOptions*/;
2121
22 -CREATE TABLE `central_notice_templates` (
23 - `template_id` int NOT NULL auto_increment,
24 - `template_name` varchar(255) default NULL,
25 - PRIMARY KEY (`template_id`)
 22+CREATE TABLE `cn_templates` (
 23+ `tmp_id` int NOT NULL auto_increment,
 24+ `tmp_name` varchar(255) default NULL,
 25+ PRIMARY KEY (`tmp_id`)
2626 ) /*$wgDBTableOptions*/;
Index: branches/CentralNotice-SpecialPage-Integration/rebuildTemplates.php
@@ -12,7 +12,7 @@
1313 echo " php extensions/CentralNotice/rebuildTemplates\n";
1414 } else {
1515 echo "Rebuilding templates ...\n";
16 - $notice = efSelectNotice( 'central_notice_campaign' );
 16+ $notice = efSelectNotice( 'cn_notices' );
1717 $templates = array();
1818 $templates = CentralNotice::getTemplatesForNotice( $notice );
1919
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php
@@ -47,7 +47,7 @@
4848 $body = file_get_contents( 'php://input' );
4949 $wgOut->addHtml( Xml::element( 'pre', null, $body ) );
5050
51 - // Build list of templates to remove
 51+ // Handle removing
5252 $toRemove = $wgRequest->getArray( 'removeTemplates' );
5353 if ( isset( $toRemove ) ) {
5454 // Remove templates in list
@@ -60,7 +60,7 @@
6161 return;
6262 }
6363
64 - // Build a list of notices to enable
 64+ // Handle enabling/disabling
6565 $enabledNotices = $wgRequest->getArray( 'enabled' );
6666 if ( isset( $enabledNotices ) ) {
6767 // Build a list of notices to disable
@@ -97,7 +97,7 @@
9898 global $egCentralNoticeTables;
9999
100100 $dbw = wfGetDB( DB_MASTER );
101 - $res = $dbw->update( 'central_notice_campaign',
 101+ $res = $dbw->update( 'cn_notices',
102102 array( cnc_enabled => $enabled ),
103103 array( cnc_template => $update_notice ),
104104 __METHOD__
@@ -110,16 +110,16 @@
111111
112112 function queryTemplates() {
113113 $dbr = wfGetDB( DB_SLAVE );
114 - $res = $dbr->select( 'central_notice_templates',
115 - array( 'template_name', 'template_id' ),
 114+ $res = $dbr->select( 'cn_templates',
 115+ array( 'tmp_name', 'tmp_id' ),
116116 '',
117117 __METHOD__,
118 - array( 'ORDER BY' => 'template_id' )
 118+ array( 'ORDER BY' => 'tmp_id' )
119119 );
120120
121121 $templates = array();
122122 while ( $row = $dbr->fetchObject( $res ) ) {
123 - array_push( $templates, $row->template_name );
 123+ array_push( $templates, $row->tmp_name );
124124 }
125125
126126 return $templates;
@@ -162,6 +162,7 @@
163163 );
164164 $htmlOut .= Xml::closeElement( 'table' );
165165 $htmlOut .= XML::closeElement( 'fieldset' );
 166+ $htmlOut .= XML::closeElement( 'form' );
166167
167168 // Notices
168169 $htmlOut .= Xml::openElement( 'form',
@@ -243,8 +244,8 @@
244245 }
245246
246247 $dbr = wfGetDB( DB_SLAVE );
247 - $res = $dbr->select( 'central_notice_templates', 'template_name',
248 - array( 'template_name' => $name ),
 248+ $res = $dbr->select( 'cn_templates', 'tmp_name',
 249+ array( 'tmp_name' => $name ),
249250 __METHOD__
250251 );
251252
@@ -253,8 +254,8 @@
254255 return;
255256 } else {
256257 $dbw = wfGetDB( DB_MASTER );
257 - $res = $dbw->insert( 'central_notice_templates',
258 - array( 'template_name' => $name ),
 258+ $res = $dbw->insert( 'cn_templates',
 259+ array( 'tmp_name' => $name ),
259260 __METHOD__
260261 );
261262
@@ -279,8 +280,8 @@
280281
281282 $templateId = $this->getTemplateId( $templateName );
282283 $dbr = wfGetDB( DB_SLAVE );
283 - $res = $dbr->select( 'central_notice_template_assignments', 'template_assignment_id',
284 - array( 'template_id' => $templateId ),
 284+ $res = $dbr->select( 'cn_assignments', 'asn_id',
 285+ array( 'tmp_id' => $templateId ),
285286 __METHOD__
286287 );
287288
@@ -289,8 +290,8 @@
290291 return;
291292 } else {
292293 $dbw = wfGetDB( DB_MASTER );
293 - $res = $dbw->delete( 'central_notice_templates',
294 - array( 'template_id' => $templateId ),
 294+ $res = $dbw->delete( 'cn_templates',
 295+ array( 'tmp_id' => $templateId ),
295296 __METHOD__
296297 );
297298 }
@@ -300,14 +301,14 @@
301302 global $wgOut, $egCentralNoticeTables;
302303
303304 $dbr = wfGetDB( DB_SLAVE );
304 - $res = $dbr->select( 'central_notice_templates', 'template_id',
305 - array( 'template_name' => $templateName ),
 305+ $res = $dbr->select( 'cn_templates', 'tmp_id',
 306+ array( 'tmp_name' => $templateName ),
306307 __METHOD__
307308 );
308309
309310 $row = $dbr->fetchObject( $res );
310311 if( $row ) {
311 - return $row->template_id;
 312+ return $row->tmp_id;
312313 }
313314 return null;
314315 }
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php
@@ -193,14 +193,16 @@
194194
195195 function chooseTemplate ( $notice ) {
196196 $dbr = wfGetDB( DB_SLAVE );
197 - $centralnotice_table = 'central_notice_template_assignments';
198 - $res = $dbr->select( array ( $centralnotice_table,"central_notice_template_assignments"),
199 - "name,weight",
200 - array ( 'notice_name' => $notice, 'campaign_id = id'),
201 - '',
202 - array('ORDER BY' => 'id'),
203 - ''
204 - );
 197+ /*
 198+ * This select statement is really wrong, and needs to be fixed.
 199+ * What's wrong is the use of just id instead of not_id, tmp_id or asn_id
 200+ */
 201+ $res = $dbr->select( 'cn_assignments',
 202+ array( 'not_name', 'not_weight' ),
 203+ array( 'not_name' => $notice, 'not_id = id'),
 204+ __METHOD__,
 205+ array('ORDER BY' => 'id')
 206+ );
205207 $templates = array();
206208 while ( $row = $dbr->fetchObject( $res )) {
207209 push ( $templates, $row->name);
Property changes on: branches/CentralNotice-SpecialPage-Integration
___________________________________________________________________
Name: svn:ignore
208210 + .project

Status & tagging log