r42265 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42264‎ | r42265 | r42266 >
Date:15:12, 20 October 2008
Author:tomasz
Status:old
Tags:
Comment:
Updating from local branch. Picking up working notice toggling, display, setting, hour start & locking. Notice template can now be added as
desired with user specified weights. Central Notice will now only load if there is a template available within the set boundries.
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.i18n.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice_body.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php
@@ -4,7 +4,7 @@
55 /// This guy gets loaded from every page on every wiki, and is heavily cached.
66 /// Its contents are small, and just load up another cached JS page, but this
77 /// allows us to update everything with a single purge. Nice, eh?
8 -$wgNoticeLoader = 'http://tomasz.ods.org/mediawiki-1.13.0/index.php/Special:NoticeLoader';
 8+$wgNoticeLoader = 'http://192.168.250.130/mediawiki-1.13.2/index.php/Special:NoticeLoader';
99
1010 /// Override these per-wiki to pass on via the loader to the text system
1111 /// for localization by language and project.
@@ -27,7 +27,7 @@
2828 /// URL prefix to the raw-text loader special.
2929 /// Project/language and timestamp epoch keys get appended to this
3030 /// via the loader stub.
31 -$wgNoticeText = 'http://tomasz.ods.org/mediawiki-1.13.0/index.php/Special:NoticeText';
 31+$wgNoticeText = 'http://192.168.250.130/mediawiki-1.13.2/index.php/Special:NoticeText';
3232
3333 /// If true, notice only displays if 'sitenotice=yes' is in the query string
3434 $wgNoticeTestMode = false;
@@ -78,70 +78,50 @@
7979 $wgSpecialPages['CentralNotice'] = 'CentralNotice';
8080 $wgSpecialPageGroups['CentralNotice'] = 'wiki'; // Wiki data and tools"
8181
82 -function selectNotice($centralnotice_table) {
83 - $dbr = wfGetDB( DB_SLAVE );
84 - $current_date = date( 'o-m-d' );
85 - $res = $dbr->select( $centralnotice_table, "notice_name", array ( "notice_start_date <= '$current_date'", "notice_end_date >= '$current_date'", "notice_enabled = 'Y'" ));
86 - $row = $dbr->fetchObject( $res );
87 - return $row->notice_name;
88 -}
89 -
9082 function efCentralNoticeSetup() {
91 - $centralnotice_table = "central_notice_campaign";
92 - $notice = selectNotice($centralnotice_table);
93 - global $wgHooks, $wgNoticeInfrastructure;
94 - global $wgAutoloadClasses, $wgSpecialPages;
 83+ global $wgHooks, $wgNoticeInfrastructure;
 84+ global $wgAutoloadClasses, $wgSpecialPages;
9585
96 - global $wgCentralNoticeLoader;
 86+ global $wgCentralNoticeLoader;
9787
98 - if ($wgCentralNoticeLoader) {
99 - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader';
100 - }
 88+ if ($wgCentralNoticeLoader) {
 89+ $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader';
 90+ }
10191
102 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook';
103 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook';
 92+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook';
 93+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook';
10494
105 - $wgAutoloadClasses['NoticePage'] =
106 - dirname( __FILE__ ) . '/NoticePage.php';
 95+ $wgAutoloadClasses['NoticePage'] =
 96+ dirname( __FILE__ ) . '/NoticePage.php';
10797
108 - $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal';
109 - $wgAutoloadClasses['SpecialNoticeLocal'] =
110 - dirname( __FILE__ ) . '/SpecialNoticeLocal.php';
 98+ $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal';
 99+ $wgAutoloadClasses['SpecialNoticeLocal'] =
 100+ dirname( __FILE__ ) . '/SpecialNoticeLocal.php';
111101
112102 global $wgOut;
113103 if( $wgNoticeInfrastructure ) {
114 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeSaveHook';
115 - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeDeleteHook';
 104+ $wgCentralnoticeTable = "central_notice_campaign";
 105+ $wgNotice = efSelectNotice($wgCentralnoticeTable);
 106+ if ( isset( $wgNotice ) ) { //Do we have an active notice campaign
 107+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeSaveHook';
 108+ $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeDeleteHook';
116109
117 - $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader';
118 - $wgAutoloadClasses['SpecialNoticeLoader'] =
119 - dirname( __FILE__ ) . '/SpecialNoticeLoader.php';
 110+ $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader';
 111+ $wgAutoloadClasses['SpecialNoticeLoader'] =
 112+ dirname( __FILE__ ) . '/SpecialNoticeLoader.php';
120113
121 - $wgSpecialPages['NoticeText'] = 'SpecialNoticeText';
122 - $wgAutoloadClasses['SpecialNoticeText'] =
123 - dirname( __FILE__ ) . '/SpecialNoticeText.php';
 114+ $wgSpecialPages['NoticeText'] = 'SpecialNoticeText';
 115+ $wgAutoloadClasses['SpecialNoticeText'] =
 116+ dirname( __FILE__ ) . '/SpecialNoticeText.php';
124117
125 - $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate';
126 - $wgAutoloadClasses['SpecialNoticeTemplate'] =
127 - dirname( __FILE__ ) . '/SpecialNoticeTemplate.php';
 118+ $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate';
 119+ $wgAutoloadClasses['SpecialNoticeTemplate'] =
 120+ dirname( __FILE__ ) . '/SpecialNoticeTemplate.php';
128121
129 - $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate';
130 - $wgAutoloadClasses['SpecialNoticeTranslate'] =
131 - dirname( __FILE__ ) . '/SpecialNoticeTranslate.php';
132 -
133 - // The new SVG stuff
134 - /*
135 - $wgSpecialPages['NoticeRender'] = 'SpecialNoticeRender';
136 - $wgAutoloadClasses['SpecialNoticeRender'] = dirname( __FILE__ ) . '/SpecialNoticeRender.php';
137 - $wgAutoloadClasses['NoticeRender'] = dirname( __FILE__ ) . '/NoticeRender.php';
138 -
139 - global $wgNoticeRenderDirectory, $wgNoticeRenderPath;
140 - global $wgUploadDirectory, $wgUploadPath;
141 - if( !$wgNoticeRenderDirectory )
142 - $wgNoticeRenderDirectory = "$wgUploadDirectory/notice";
143 - if( !$wgNoticeRenderPath )
144 - $wgNoticeRenderPath = "$wgUploadPath/notice";
145 - */
 122+ $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate';
 123+ $wgAutoloadClasses['SpecialNoticeTranslate'] =
 124+ dirname( __FILE__ ) . '/SpecialNoticeTranslate.php';
 125+ }
146126 }
147127 }
148128
@@ -178,10 +158,30 @@
179159 }
180160 </script>
181161 EOT;
182 -
183162 return true;
184163 }
185164
 165+
 166+/**
 167+ * Lookup function for active notice under a given language and project
 168+ * Returns and id for the running notice
 169+ */
 170+function efSelectNotice( $centralnotice_table ) {
 171+ global $wgNoticeLang, $wgNoticeProject;
 172+
 173+ $dbr = wfGetDB( DB_SLAVE );
 174+ $timestamp = wfTimestampNow();
 175+ $res = $dbr->select( $centralnotice_table, "id", array ( "notice_start_date <= '$timestamp'", "notice_end_date >= '$timestamp'", "notice_enabled = 'Y'", "notice_language = '$wgNoticeLang'", "notice_project = '$wgNoticeProject'"));
 176+ if ( $dbr->numRows( $res > 1 )) {
 177+ //notice overlap! not returning anything for safety
 178+ }
 179+ else {
 180+ $row = $dbr->fetchObject( $res );
 181+ return $row->id;
 182+ }
 183+}
 184+
 185+
186186 /**
187187 * 'ArticleSaveComplete' hook
188188 * Trigger a purge of the notice loader when we've updated the source pages.
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php
@@ -46,8 +46,6 @@
4747
4848 $diff_set = array_diff( $allNotices, $enabledNotices);
4949
50 - $wgOut->addHtml("<p>diff set is $diff_set[1]");
51 -
5250 foreach ( $enabledNotices as $notice) {
5351 $this->updateEnabled( $notice, 'Y');
5452 }
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice_body.php
@@ -31,7 +31,7 @@
3232 $body = file_get_contents('php://input');
3333 $wgOut->addHtml("Body of post: $body");
3434
35 - $toRemove = $wgRequest->getArray('removeTemplate');
 35+ $toRemove = $wgRequest->getArray('removeNotices');
3636 if ( isset($toRemove) ){
3737 foreach ( $toRemove as $template ) {
3838 $this->removeNotice( $template );
@@ -40,14 +40,24 @@
4141 return;
4242 }
4343
 44+ $lockedNotices = $wgRequest->getArray('locked');
 45+ if ( isset( $lockedNotices ) ) {
 46+ $allNotices = $this->getNoticesName();
 47+ $diff_set = array_diff( $allNotices, $lockedNotices);
 48+
 49+ foreach( $lockedNotices as $notice ) {
 50+ $this->updateLock( $notice, 'Y' );
 51+ }
 52+
 53+ foreach( $diff_set as $notice ) {
 54+ $this->updateLock( $notice, 'N' );
 55+ }
 56+ }
4457 $enabledNotices = $wgRequest->getArray('enabled');
4558 if ( isset( $enabledNotices ) ) {
4659 $allNotices = $this->getNoticesName();
47 -
4860 $diff_set = array_diff( $allNotices, $enabledNotices);
4961
50 - $wgOut->addHtml("<p>diff set is $diff_set[1]");
51 -
5262 foreach ( $enabledNotices as $notice) {
5363 $this->updateEnabled( $notice, 'Y');
5464 }
@@ -55,19 +65,54 @@
5666 $this->updateEnabled( $notice, 'N');
5767 }
5868 }
 69+ $start_date = $wgRequest->getArray('start_date');
 70+ if ( isset( $start_date ) ) {
 71+ foreach( $start_date as $noticeName => $date_value ) {
 72+ $updatedStartDate = '';
 73+ foreach ( $date_value as $date_portion => $value) {
 74+ $updatedStartDate .= $value;
 75+ }
 76+ $updatedStartDate .= "000000";
 77+ $this->updateStartDate( $noticeName, $updatedStartDate);
 78+ }
 79+ }
 80+ $end_date = $wgRequest->getArray('end_date');
 81+ if ( isset( $end_date ) ) {
 82+ foreach( $end_date as $noticeName => $date_value ) {
 83+ $updatedEndDate = '';
 84+ foreach ( $date_value as $date_portion => $value) {
 85+ $updatedEndDate .= $value;
 86+ }
 87+ $updatedEndDate .= "000000";
 88+ $this->updateEndDate( $noticeName, $updatedEndDate);
 89+ }
 90+ }
 91+ $noticeName = $wgRequest->getVal('notice');
 92+ $updatedWeights = $wgRequest->getArray('weight');
 93+ if ( isset( $updatedWeights ) ) {
 94+ foreach( $updatedWeights as $templateName => $weight) {
 95+ $this->updateWeight( $noticeName, $templateName, $weight);
 96+ }
 97+ }
5998 }
6099
61100 $method = $wgRequest->getVal('method');
 101+ $this->showAll = $wgRequest->getVal('showAll');
62102 $wgOut->addHtml("<p>got method $method");
63103 $wgOut->addHtml("<p>got sub $sub");
64104
65105 if ( $method == 'addNotice' ) {
66 - $noticeName = $wgRequest->getVal ('noticeName');
 106+ $noticeName = $wgRequest->getVal('noticeName');
 107+ $start_day = $wgRequest->getVal('start_day');
 108+ $start_month = $wgRequest->getVal('start_month');
 109+ $start_year = $wgRequest->getVal('start_year');
 110+ $project_name = $wgRequest->getVal('project_name');
 111+ $project_language = $wgRequest->getVal('project_lang');
67112 if ( $noticeName == '') {
68113 $wgOut->addHtml("Can't add a null string");
69114 }
70115 else {
71 - $this->addNotice( $noticeName );
 116+ $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $project_name, $project_language );
72117 }
73118 }
74119 if ( $method == 'removeNotice' ) {
@@ -115,12 +160,11 @@
116161 $res = $dbr->select( $centralnotice_table,"notice_name" );
117162 $notices = array();
118163 while ( $row = $dbr->fetchObject( $res )) {
119 - array_push( $notices, $row->notice_names);
 164+ array_push( $notices, $row->notice_name);
120165 }
121166 return $notices;
122167 }
123168
124 -
125169 ####
126170 # listNotices
127171 ###
@@ -128,47 +172,90 @@
129173 ###
130174
131175 function listNotices() {
132 - global $wgOut,$wgRequest,$wgTitle,$wgScript;
 176+ global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang;
133177
134178 $centralnotice_table = "central_notice_campaign";
135179 $dbr = wfGetDB( DB_SLAVE );
136 - $res = $dbr->select( $centralnotice_table,
137 - "notice_name, notice_start_date, notice_end_date, notice_enabled",
138 - '',
139 - '',
140 - array('ORDER BY' => 'id'),
141 - ''
142 - );
 180+ $this->showAll = 'Y'; //temp
 181+ if ( isset( $this->showAll )) {
 182+ $res = $dbr->select( $centralnotice_table,
 183+ "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_language, notice_locked",
 184+ '',
 185+ '',
 186+ array('ORDER BY' => 'id'),
 187+ ''
 188+ );
 189+ }
 190+ else { //show only notices for this language
 191+ $res = $dbr->select( $centralnotice_table,
 192+ "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_locked",
 193+ array ( "notice_language = '$wgNoticeLang'"),
 194+ '',
 195+ array('ORDER BY' => 'id'),
 196+ ''
 197+ );
 198+ }
143199 $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
144200 $table .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-manage" ) . "</legend>";
145 - $table .= "<table cellpadding=\"9\">";
146 - $table .= "<tr><th colspan = \"4\"><br></th></tr>";
 201+ $table .= "<table cellpadding=\"9\">";
 202+ $table .= "<tr><th colspan = \"9\"></th></tr>";
147203 $table .= "<th>" . wfMsg ( 'centralnotice-notice-name') . "</th>";
 204+ $table .= "<th>" . wfMsg ( 'centralnotice-project-name') . "</th>";
 205+ if ( isset ( $this->showAll ) )
 206+ $table .= "<th>" . wfMsg ( 'centralnotice-project-lang') . "</th>";
148207 $table .= "<th>" . wfMsg ( 'centralnotice-start-date') . "</th>";
149208 $table .= "<th>" . wfMsg ( 'centralnotice-end-date') . "</th>";
150209 $table .= "<th>" . wfMsg ( 'centralnotice-enabled') . "</th>";
 210+ $table .= "<th>" . wfMsg ( 'centralnotice-locked') . "</th>";
151211 $table .= "<th>" . wfMsg ( 'centralnotice-remove') . "</th>";
152 - $table .= "<th>" . wfMsg ( 'centralnotice-metrics') . "</th>";
153212 while ( $row = $dbr->fetchObject( $res )) {
154 - #$table .= "<tr><td><a href=\"" . SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl() . "&method=listCampaignDetail&campaign=$row->notice_name" . "\">$row->notice_name</a></td>";
155 - $table .= "<tr><td><a href=\"" . $this->getTitle()->getLocalUrl("method=listNoticeDetail&campaign=$row->notice_name") . "\">$row->notice_name</a></td>";
156 - $table .= "<td>$row->notice_start_date</td>";
157 - $table .= "<td>$row->notice_end_date</td>";
 213+ $table .= "<tr><td><a href=\"" . $this->getTitle()->getLocalUrl("method=listNoticeDetail&notice=$row->notice_name") . "\">$row->notice_name</a></td>";
 214+ $table .= "<td>$row->notice_project</td>";
 215+ if ( isset ( $this->showAll ))
 216+ $table .= "<td>" . $row->notice_language . "</td>";
 217+
 218+ $start_timestamp = $row->notice_start_date;
 219+ $start_year = substr( $start_timestamp, 0 , 4);
 220+ $start_month = substr( $start_timestamp, 4, 2);
 221+ $start_day = substr( $start_timestamp, 6, 2);
 222+ $start_hour = substr( $start_timestamp, 8, 2) . ":00";
 223+
 224+ $end_timestamp = $row->notice_end_date;
 225+ $end_year = substr( $end_timestamp, 0 , 4);
 226+ $end_month = substr( $end_timestamp, 4, 2);
 227+ $end_day = substr( $end_timestamp, 6, 2);
 228+
 229+ $table .= "<td>" . Xml::listDropDown( "start_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $start_year, '', 3)
 230+ . Xml::listDropDown( "start_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $start_month, '', 4 )
 231+ . Xml::listDropDown( "start_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $start_day, '', 5)
 232+ . Xml::listDropDown( "start_date[$row->notice_name][hour]", wfMsg( 'centralnotice-hours'), '', $start_hour, '', 6)
 233+ . "</td>";
 234+ $table .= "<td>" . Xml::listDropDown( "end_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $end_year, '', 7)
 235+ . Xml::listDropDown( "end_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $end_month, '', 8 )
 236+ . Xml::listDropDown( "end_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $end_day, '9')
 237+ . "</td>";
158238 $enabled = ( $row->notice_enabled == 'Y' ) ? true : false;
159239 $table .= "<td>" . Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->notice_name)) . "</td>";
 240+ // lock down to certain users
 241+ $locked = ( $row->notice_locked == 'Y' ) ? true : false;
 242+ $table .= "<td>" . Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>";
160243 $table .= "<td>" . Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>";
161244 }
162245 $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify'),
163246 array('id' => 'centralnoticesubmit','name' => 'centralnoticesubmit') ) . "</td></tr>";
164 - // Need to add a preview button
165247 $table .= "</table></fieldset></form>";
166248 $wgOut->addHTML( $table);
167249
 250+ $current_day = date( 'd' );
 251+ $current_month = date( 'm');
 252+ $current_year = date( 'o' );
168253 $action = "addNotice";
 254+
 255+ global $wgNoticeProject,$wgNoticeLang;
 256+
169257 $wgOut->addHtml(
170258 Xml::openElement( 'form', array(
171259 'method' => 'post',
172 - //'action' => $this->getTitle( $this->mUserName )->getLocalUrl( /* 'method=addNotice' */ ) )) .
173260 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl())) .
174261 '<fieldset>' .
175262 Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-notice' ) ) .
@@ -177,6 +264,16 @@
178265 '<p>' .
179266 Xml::inputLabel( wfMsg( 'centralnotice-notice-name' ),
180267 'noticeName', 'noticeName', 25, $this->mNoticeName) .
 268+ " " . Xml::label( wfMsg('centralnotice-start-date'), 'start-date') . ": " .
 269+ Xml::listDropDown( 'start_month', wfMsg( 'centralnotice-months'), '', $current_month, '', 6 ) .
 270+ Xml::listDropDown( 'start_day', wfMsg( 'centralnotice-days'), '', $current_day, '', 7 ) .
 271+ Xml::listDropDown( 'start_year', wfMsg( 'centralnotice-years'), '', $current_year, '', 8) .
 272+ " " . wfMsg( 'centralnotice-start-hour' ) . ": " .
 273+ Xml::listDropDown( 'start_hour', wfMsg( 'centralnotice-hours'), '', "00:00", '', 9) .
 274+ " " . wfMsg( 'centralnotice-project-name' ) . ": " .
 275+ Xml::listDropDown( 'project_name', wfMsg( 'centralnotice-project-name-list'), '', $wgNoticeProject, '', 10) .
 276+ " " . wfMsg( 'centralnotice-project-lang') . ": " .
 277+ Xml::listDropDown( 'project_lang', wfMsg( 'centralnotice-project-lang-list'), '', $wgNoticeLang, '', 11) .
181278 '</p>' .
182279 '<p>' .
183280 Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
@@ -192,12 +289,21 @@
193290 $eNotice = htmlspecialchars( $notice );
194291
195292 if ($wgRequest->wasPosted()) {
196 - $templateToRemove = $wgRequest->getVal('removeTemplates');
197 - if (isset($templateToRemove)) {
 293+ $templateToRemove = $wgRequest->getArray('removeTemplates');
 294+ if (isset( $templateToRemove )) {
198295 foreach ($templateToRemove as $template) {
199296 $this->removeTemplateFor( $eNotice, $template);
200297 }
201298 }
 299+ $weights = $wgRequest->getArray('weights');
 300+ if (isset( $weights )) {
 301+ }
 302+ $templatesToAdd = $wgRequest->getArray('addTemplates');
 303+ if (isset( $templatesToAdd )) {
 304+ foreach ($templatesToAdd as $template) {
 305+ $this->addTemplateTo( $notice, $template, 0);
 306+ }
 307+ }
202308
203309 }
204310
@@ -210,12 +316,13 @@
211317 array('ORDER BY' => 'id'),
212318 ''
213319 );
214 -
215 - $table .= Xml::openElement( 'form', array(
216 - 'method' => 'post',
217 - 'action' => SpecialPage::getTitleFor( 'CentralNotice/listNoticeDetail' )->getLocalUrl()));
218 - $table .= '<fieldset>';
219 - $table .= Xml::element( 'legend', array() , $eNotice);
 320+ if ( $dbr->numRows( $res ) < 1) {
 321+ $wgOut->addHtml( wfMsg ("centralnotice-no-templates"));
 322+ $wgOut->addHtml( $this->addTemplatesForm());
 323+ return;
 324+ }
 325+ $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
 326+ $table .= '<fieldset><legend>' . $eNotice . "</legend>";
220327 $table .= "<table cellpadding=\"9\">";
221328 $table .= "<tr><th colspan = \"3\"></th></tr>";
222329 $table .= "<th>" . wfMsg ( "centralnotice-templates" ) . "</th>";
@@ -223,51 +330,55 @@
224331 $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>";
225332 while ( $row = $dbr->fetchObject( $res )) {
226333 $table .= "<tr><td>" . Xml::label($row->name, 'name') . "</td>";
227 - $table .= "<td>" . Xml::input( 'weight', '', $row->weight) . "</td>";
228 - $table .= "<td>" . Xml::check( 'removeNotices[]', false) . "</td>";
 334+ $table .= "<td>" . Xml::listDropDown( "weight[$row->name]", wfMsg( 'centralnotice-weights'), '', $row->weight, '', 1) . "</td>";
 335+ $table .= "<td>" . Xml::check( 'removeTemplates[]', false, array( 'value' => $row->name)) . "</td></tr>";
229336 }
230 - $table .= "</tr>";
231 - $table .= Xml::submitButton( wfMsg( 'centralnotice-update-weights' ) ) .
232 - $table .= "</table></fieldset>";
233 - $table .= Xml::closeElement( 'form');
 337+ $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify') ) . "</td></tr>";
 338+ $table .= "</table></fieldset></form>";
234339 $wgOut->addHTML( $table );
 340+ $wgOut->addHTML( $this->addTemplatesForm() );
 341+ }
235342
236 - $wgOut->addHtml(
237 - Xml::openElement( 'form', array(
238 - 'method' => 'post',
239 - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl( "method=addTemplateTo&noticeName=$eNotice&template=$templateName"))) .
240 - '<fieldset>' .
241 - Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-template' ) ) .
242 - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
243 - Xml::hidden( 'method', $action ) .
244 - '<p>' .
245 - Xml::inputLabel( wfMsg( 'centralnotice-template-name' ),
246 - 'templateName', 'templateName', 25, $this->mTemplateName) .
247 - '</p>' .
248 - '<p>' .
249 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
250 - '</p>' .
251 - '</fieldset>' .
252 - '</form>'
253 - );
 343+ function addTemplatesForm() {
 344+ $centralnotice_table = 'central_notice_templates';
 345+ $dbr = wfGetDB( DB_SLAVE );
 346+ $res = $dbr->select( $centralnotice_table, name, '', '', array('ORDER BY' => 'id'));
 347+ $table = "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
 348+ $table .= '<fieldset><legend>' . wfMsg( "centralnotice-available-templates") . '</legend>';
 349+ $table .= "<table cellpadding=\"9\">";
 350+ $table .= "<tr><th colspan = \"2\"></th></tr>";
 351+ $table .= "<th>" . wfMsg ( 'centralnotice-template-name') . "</th>";
 352+ $table .= "<th>" . wfMsg ( 'centralnotice-add' ) . "</th>";
 353+ while ( $row = $dbr->fetchObject( $res )) {
 354+ $table .= "<tr><td>" . $row->name . "</td>";
 355+ $table .= "<td>" . Xml::check( 'addTemplates[]', '', array ( 'value' => $row->name)) . "</td></tr>";
 356+ }
 357+ $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify')) . "</td></tr>";
 358+ $table .= "</table></fieldset></form>";
 359+ return $table;
254360 }
255361
256 - function getTemplatesForNotice ( $noticeName ) {
 362+public function getTemplatesForNotice ( $noticeName ) {
257363 $dbr = wfGetDB( DB_SLAVE );
258364 $centralnotice_table = 'central_notice_template_assignments';
259365
260366 $eNoticeName = mysql_real_escape_string( $noticeName ) ;
261 - $res = $dbr->select( array ( $centralnotice_table,"central_notice_template_assignments"),
 367+ $res = $dbr->select( array ( $centralnotice_table, "central_notice_campaign" ),
262368 "name,weight",
263369 array ( 'notice_name' => $eNoticeName, 'campaign_id = id'),
264370 '',
265371 array('ORDER BY' => 'id'),
266372 ''
267373 );
 374+ $templates = array();
 375+ while ( $row = $dbr->fetchObject( $res )) {
 376+ $tempaltes[$row->name] = $row->weight;
 377+ }
 378+ return $templates;
268379
269380 }
270381
271 - function addNotice( $noticeName ) {
 382+ function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $project_name, $project_language ) {
272383 global $wgOut;
273384 $dbr = wfGetDB( DB_SLAVE );
274385 $centralnotice_table = 'central_notice_campaign';
@@ -280,7 +391,9 @@
281392 }
282393 else {
283394 $dbw = wfGetDB( DB_MASTER );
284 - $res = $dbw->insert( $centralnotice_table, array( notice_name => "$noticeName"));
 395+ $start_date = wfTimeStamp( TS_MW, $start_year . $start_month . $start_day . $start_hour . "000000");
 396+ $end_date = wfTimeStamp( TS_MW, $start_year . ($start_month + 1) . $start_day . $start_hour . "000000");
 397+ $res = $dbw->insert( $centralnotice_table, array( notice_name => "$noticeName", notice_enabled => "$enabled", notice_start_date => "$start_date" , notice_end_date => $end_date, notice_project => $project_name, notice_language => $project_language));
285398 return;
286399 }
287400 }
@@ -298,6 +411,8 @@
299412 }
300413 else {
301414 $dbw = wfGetDB( DB_MASTER );
 415+ $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
 416+ $res = $dbw->delete( "central_notice_template_assignments", array ( campaign_id => $noticeId));
302417 $res = $dbw->delete( $centralnotice_table, array ( notice_name => "$noticeName"));
303418 return;
304419 }
@@ -311,9 +426,11 @@
312427 $eNoticeName = mysql_real_escape_string( $noticeName );
313428 $eTemplateName = mysql_real_escape_string( $templateName );
314429 $eWeight = mysql_real_escape_string ( $weight );
315 - $res = $dbr->select( $centralnotice_table, 'name', "name = '$eTemplateName'");
 430+
 431+ $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
 432+ $res = $dbr->select( $centralnotice_table, 'name', array( name => $eTemplateName, campaign_id => $noticeId));
316433 if ( $dbr->numRows( $res ) > 0) {
317 - $wgOut->addHTML( wfMsg( 'centralnotice-notice-template-already-exist' ) );
 434+ $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) );
318435 }
319436 else {
320437 $dbw = wfGetDB( DB_MASTER );
@@ -338,4 +455,51 @@
339456 $eTemplateName = mysql_real_escape_string( $templateName );
340457 $res = $dbw->delete( $centralnotice_table, array ( name => "$eTemplateName", campaign_id => $noticeId));
341458 }
 459+
 460+ function updateNotice ( $noticeName, $startDate, $endDate , $enabled) {
 461+ $centralnotice_table = "central_notice_template_assignments";
 462+ $dbr = wfGetDB( DB_SLAVE );
 463+ $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
 464+ if ($dbr->numRows( $res ) < 1) {
 465+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
 466+ }
 467+ else {
 468+ $dbw = wfGetDB( DB_MASTER );
 469+ $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate, notice_end_Date => $endDate, notice_enabled => $enabled), "notice_name = '$noticeName'");
 470+ }
 471+ }
 472+
 473+ function updateStartDate ( $noticeName, $startDate ) {
 474+ $centralnotice_table = 'central_notice_campaign';
 475+ $dbw = wfGetDB( DB_MASTER );
 476+ $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate), array( notice_name => $noticeName));
 477+ }
 478+
 479+
 480+ function updateEndDate ( $noticeName, $endDate ) {
 481+ $centralnotice_table = 'central_notice_campaign';
 482+ $dbw = wfGetDB( DB_MASTER );
 483+ $res = $dbw->update( $centralnotice_table, array( notice_end_date => $endDate), array( notice_name => $noticeName));
 484+ }
 485+
 486+ function updateLock ( $noticeName, $isLocked ) {
 487+ global $wgOut;
 488+ $centralnotice_table = 'central_notice_campaign';
 489+ $dbr = wfGetDB( DB_SLAVE );
 490+ $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
 491+ if ($dbr->numRows( $res ) < 1) {
 492+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
 493+ }
 494+ else {
 495+ $dbw = wfGetDB( DB_MASTER );
 496+ $res = $dbw->update( $centralnotice_table, array( notice_locked => $isLocked ), array( notice_name => $noticeName));
 497+ }
 498+ }
 499+
 500+ function updateWeight ( $noticeName, $templateName, $weight ) {
 501+ $centralnotice_table = 'central_notice_template_assignments';
 502+ $dbw = wfGetDB( DB_MASTER );
 503+ $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
 504+ $res = $dbw->update( $centralnotice_table, array ( weight => $weight ), array( name => $templateName, campaign_id => $noticeId));
 505+ }
342506 }
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php
@@ -20,6 +20,7 @@
2121
2222 function getJsOutput( $par ) {
2323 $this->setLanguage( $par );
 24+ //need to return all site notices here
2425 return
2526 'wgNotice="' .
2627 strtr(
@@ -68,6 +69,12 @@
6970 $encShowStyle = Xml::encodeJsVar( $showStyle );
7071 $encHideStyle = Xml::encodeJsVar( $hideStyle );
7172 $encHideToggleStyle = Xml::encodeJsVar( $hideToggleStyle );
 73+
 74+ $noticeName = '2008 Fundraiser';
 75+ $templates = CentralNotice::getTemplatesForNotice( $noticeName );
 76+ $templateNames = array_keys( $templates );
 77+ $weights = array_values( $templates );
 78+
7279 $script = <<<END
7380 var wgNoticeToggleState = (document.cookie.indexOf("hidesnmessage=1")==-1);
7481 document.writeln(
@@ -101,21 +108,21 @@
102109 document.cookie = work;
103110 }
104111 function pickTemplate() {
105 - var templates = ["2007donationcount","2007donationcount-variant","2009-variant-c"]
106 - var weights = [20, 80, 0]
107 - var totalWeight = eval(weights.join("+"))
108 - var weightedTemplates = new Array()
109 - var currentTemplate = 0
 112+ var templates = $templateNames;
 113+ var weights = $weights;
 114+ var totalWeight = eval(weights.join("+"));
 115+ var weightedTemplates = new Array();
 116+ var currentTemplate = 0;
110117
111118 while (currentTemplate < templates.length) {
112119 for (i=0; i<weights[currentTemplate]; i++) {
113 - weightedTemplates[weightedTemplates.length] = templates[currentTemplate]
 120+ weightedTemplates[weightedTemplates.length] = templates[currentTemplate];
114121 }
115 - currentTemplate++
 122+ currentTemplate++;
116123 }
117124
118 - var randomnumber=Math.floor(Math.random()*totalWeight)
119 - document.write(weightedTemplates[randomnumber])
 125+ var randomnumber=Math.floor(Math.random()*totalWeight);
 126+ document.write(weightedTemplates[randomnumber]);
120127 }
121128 END;
122129 return $script;
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.i18n.php
@@ -14,9 +14,8 @@
1515 'noticetemplate' => 'Central Notice Template',
1616 'noticetranslate' => 'Central Notice Translate',
1717 'centralnotice-query' => 'Modify Current Notices',
18 - 'centralnotice-notice-name' => 'Notice Name: ',
19 - 'centralnotice-start-date' => 'Start',
20 - 'centralnotice-end-date' => 'End',
 18+ 'centralnotice-notice-name' => 'Notice Name',
 19+ 'centralnotice-end-date' => 'End Date',
2120 'centralnotice-enabled' => 'Enabled',
2221 'centralnotice-modify' => 'Submit',
2322 'centralnotice-preview' => 'Preview',
@@ -24,7 +23,7 @@
2524 'centralnotice-remove' => 'Remove',
2625 'centralnotice-translate-heading' => 'Translate Text',
2726 'centralnotice-manage' => 'Manage Central Notice',
28 - 'centralnotice-add' => 'Add a Central Notice',
 27+ 'centralnotice-add' => 'Add',
2928 'centralnotice-add-notice' => 'Add a notice',
3029 'centralnotice-add-template' => 'Add a template',
3130 'centralnotice-show-notices' => 'Show notices',
@@ -35,11 +34,127 @@
3635 'centralnotice-template-name' => 'Template Name: ',
3736 'centralnotice-templates' => 'Templates',
3837 'centralnotice-weight' => 'Weight',
 38+ 'centralnotice-locked' => 'Locked',
3939 'centralnotice-notices' => 'Notices',
4040 'centralnotice-notice-exists' => 'Notice already exists. Not adding',
4141 'centralnotice-notice-doesnt-exist' => 'Notice doesnt exist. Nothing to remove',
4242 'centralnotice-template-body' => 'Template Body: ',
43 -
 43+ 'centralnotice-days' => '* Day
 44+**01
 45+**02
 46+**03
 47+**04
 48+**05
 49+**06
 50+**07
 51+**08
 52+**09
 53+**10
 54+**11
 55+**12
 56+**13
 57+**14
 58+**15
 59+**16
 60+**17
 61+**18
 62+**19
 63+**20
 64+**21
 65+**22
 66+**23
 67+**24
 68+**25
 69+**26
 70+**27
 71+**28
 72+**29
 73+**30
 74+**31',
 75+ 'centralnotice-years' => '* Year
 76+**2007
 77+**2008
 78+**2009
 79+**2010
 80+**2011
 81+**2012',
 82+ 'centralnotice-months' => '* Month
 83+**01
 84+**02
 85+**03
 86+**04
 87+**05
 88+**06
 89+**07
 90+**08
 91+**09
 92+**10
 93+**11
 94+**12',
 95+ 'centralnotice-hours' => '* Hour
 96+**00:00
 97+**01:00
 98+**02:00
 99+**03:00
 100+**04:00
 101+**05:00
 102+**06:00
 103+**07:00
 104+**08:00
 105+**09:00
 106+**10:00
 107+**11:00
 108+**12:00
 109+**13:00
 110+**14:00
 111+**15:00
 112+**16:00
 113+**17:00
 114+**18:00
 115+**19:00
 116+**20:00
 117+**21:00
 118+**22:00
 119+**23:00
 120+',
 121+ 'centralnotice-project-lang' => 'Project Language',
 122+ 'centralnotice-project-lang-list' => '* Project Language
 123+** en
 124+** pl
 125+** vt
 126+** jp',
 127+ 'centralnotice-project-name' => 'Project Name',
 128+ 'centralnotice-project-name-list' => '* Project Name
 129+** wikipedia
 130+** wikinews
 131+** wikitionary',
 132+ 'centralnotice-start-date' => 'Start date',
 133+ 'centralnotice-no-templates' => 'No templates found. Add some!',
 134+ 'centralnotice-available-templates' => 'Available Templates',
 135+ 'centralnotice-template-already-exists' => 'Template is already tied to campaing. Not adding',
 136+ 'centralnotice-start-hour' => 'Start Hour',
 137+ 'centralnotice-weights' => '* Weights
 138+**0
 139+**5
 140+**10
 141+**15
 142+**20
 143+**25
 144+**30
 145+**35
 146+**40
 147+**45
 148+**50
 149+**55
 150+**60
 151+**65
 152+**70
 153+**75
 154+**80
 155+**85
 156+**90
 157+**95
 158+**100'
44159 );
45160
46161 /** Afrikaans (Afrikaans)

Status & tagging log