Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | /// This guy gets loaded from every page on every wiki, and is heavily cached. |
6 | 6 | /// Its contents are small, and just load up another cached JS page, but this |
7 | 7 | /// 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'; |
9 | 9 | |
10 | 10 | /// Override these per-wiki to pass on via the loader to the text system |
11 | 11 | /// for localization by language and project. |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | /// URL prefix to the raw-text loader special. |
29 | 29 | /// Project/language and timestamp epoch keys get appended to this |
30 | 30 | /// 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'; |
32 | 32 | |
33 | 33 | /// If true, notice only displays if 'sitenotice=yes' is in the query string |
34 | 34 | $wgNoticeTestMode = false; |
— | — | @@ -78,70 +78,50 @@ |
79 | 79 | $wgSpecialPages['CentralNotice'] = 'CentralNotice'; |
80 | 80 | $wgSpecialPageGroups['CentralNotice'] = 'wiki'; // Wiki data and tools" |
81 | 81 | |
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 | | - |
90 | 82 | 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; |
95 | 85 | |
96 | | - global $wgCentralNoticeLoader; |
| 86 | + global $wgCentralNoticeLoader; |
97 | 87 | |
98 | | - if ($wgCentralNoticeLoader) { |
99 | | - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader'; |
100 | | - } |
| 88 | + if ($wgCentralNoticeLoader) { |
| 89 | + $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader'; |
| 90 | + } |
101 | 91 | |
102 | | - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook'; |
103 | | - $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook'; |
| 92 | + $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalSaveHook'; |
| 93 | + $wgHooks['ArticleSaveComplete'][] = 'efCentralNoticeLocalDeleteHook'; |
104 | 94 | |
105 | | - $wgAutoloadClasses['NoticePage'] = |
106 | | - dirname( __FILE__ ) . '/NoticePage.php'; |
| 95 | + $wgAutoloadClasses['NoticePage'] = |
| 96 | + dirname( __FILE__ ) . '/NoticePage.php'; |
107 | 97 | |
108 | | - $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal'; |
109 | | - $wgAutoloadClasses['SpecialNoticeLocal'] = |
110 | | - dirname( __FILE__ ) . '/SpecialNoticeLocal.php'; |
| 98 | + $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal'; |
| 99 | + $wgAutoloadClasses['SpecialNoticeLocal'] = |
| 100 | + dirname( __FILE__ ) . '/SpecialNoticeLocal.php'; |
111 | 101 | |
112 | 102 | global $wgOut; |
113 | 103 | 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'; |
116 | 109 | |
117 | | - $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader'; |
118 | | - $wgAutoloadClasses['SpecialNoticeLoader'] = |
119 | | - dirname( __FILE__ ) . '/SpecialNoticeLoader.php'; |
| 110 | + $wgSpecialPages['NoticeLoader'] = 'SpecialNoticeLoader'; |
| 111 | + $wgAutoloadClasses['SpecialNoticeLoader'] = |
| 112 | + dirname( __FILE__ ) . '/SpecialNoticeLoader.php'; |
120 | 113 | |
121 | | - $wgSpecialPages['NoticeText'] = 'SpecialNoticeText'; |
122 | | - $wgAutoloadClasses['SpecialNoticeText'] = |
123 | | - dirname( __FILE__ ) . '/SpecialNoticeText.php'; |
| 114 | + $wgSpecialPages['NoticeText'] = 'SpecialNoticeText'; |
| 115 | + $wgAutoloadClasses['SpecialNoticeText'] = |
| 116 | + dirname( __FILE__ ) . '/SpecialNoticeText.php'; |
124 | 117 | |
125 | | - $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
126 | | - $wgAutoloadClasses['SpecialNoticeTemplate'] = |
127 | | - dirname( __FILE__ ) . '/SpecialNoticeTemplate.php'; |
| 118 | + $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
| 119 | + $wgAutoloadClasses['SpecialNoticeTemplate'] = |
| 120 | + dirname( __FILE__ ) . '/SpecialNoticeTemplate.php'; |
128 | 121 | |
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 | + } |
146 | 126 | } |
147 | 127 | } |
148 | 128 | |
— | — | @@ -178,10 +158,30 @@ |
179 | 159 | } |
180 | 160 | </script> |
181 | 161 | EOT; |
182 | | - |
183 | 162 | return true; |
184 | 163 | } |
185 | 164 | |
| 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 | + |
186 | 186 | /** |
187 | 187 | * 'ArticleSaveComplete' hook |
188 | 188 | * 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 @@ |
47 | 47 | |
48 | 48 | $diff_set = array_diff( $allNotices, $enabledNotices); |
49 | 49 | |
50 | | - $wgOut->addHtml("<p>diff set is $diff_set[1]"); |
51 | | - |
52 | 50 | foreach ( $enabledNotices as $notice) { |
53 | 51 | $this->updateEnabled( $notice, 'Y'); |
54 | 52 | } |
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice_body.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | $body = file_get_contents('php://input'); |
33 | 33 | $wgOut->addHtml("Body of post: $body"); |
34 | 34 | |
35 | | - $toRemove = $wgRequest->getArray('removeTemplate'); |
| 35 | + $toRemove = $wgRequest->getArray('removeNotices'); |
36 | 36 | if ( isset($toRemove) ){ |
37 | 37 | foreach ( $toRemove as $template ) { |
38 | 38 | $this->removeNotice( $template ); |
— | — | @@ -40,14 +40,24 @@ |
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
| 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 | + } |
44 | 57 | $enabledNotices = $wgRequest->getArray('enabled'); |
45 | 58 | if ( isset( $enabledNotices ) ) { |
46 | 59 | $allNotices = $this->getNoticesName(); |
47 | | - |
48 | 60 | $diff_set = array_diff( $allNotices, $enabledNotices); |
49 | 61 | |
50 | | - $wgOut->addHtml("<p>diff set is $diff_set[1]"); |
51 | | - |
52 | 62 | foreach ( $enabledNotices as $notice) { |
53 | 63 | $this->updateEnabled( $notice, 'Y'); |
54 | 64 | } |
— | — | @@ -55,19 +65,54 @@ |
56 | 66 | $this->updateEnabled( $notice, 'N'); |
57 | 67 | } |
58 | 68 | } |
| 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 | + } |
59 | 98 | } |
60 | 99 | |
61 | 100 | $method = $wgRequest->getVal('method'); |
| 101 | + $this->showAll = $wgRequest->getVal('showAll'); |
62 | 102 | $wgOut->addHtml("<p>got method $method"); |
63 | 103 | $wgOut->addHtml("<p>got sub $sub"); |
64 | 104 | |
65 | 105 | 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'); |
67 | 112 | if ( $noticeName == '') { |
68 | 113 | $wgOut->addHtml("Can't add a null string"); |
69 | 114 | } |
70 | 115 | else { |
71 | | - $this->addNotice( $noticeName ); |
| 116 | + $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $project_name, $project_language ); |
72 | 117 | } |
73 | 118 | } |
74 | 119 | if ( $method == 'removeNotice' ) { |
— | — | @@ -115,12 +160,11 @@ |
116 | 161 | $res = $dbr->select( $centralnotice_table,"notice_name" ); |
117 | 162 | $notices = array(); |
118 | 163 | while ( $row = $dbr->fetchObject( $res )) { |
119 | | - array_push( $notices, $row->notice_names); |
| 164 | + array_push( $notices, $row->notice_name); |
120 | 165 | } |
121 | 166 | return $notices; |
122 | 167 | } |
123 | 168 | |
124 | | - |
125 | 169 | #### |
126 | 170 | # listNotices |
127 | 171 | ### |
— | — | @@ -128,47 +172,90 @@ |
129 | 173 | ### |
130 | 174 | |
131 | 175 | function listNotices() { |
132 | | - global $wgOut,$wgRequest,$wgTitle,$wgScript; |
| 176 | + global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang; |
133 | 177 | |
134 | 178 | $centralnotice_table = "central_notice_campaign"; |
135 | 179 | $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 | + } |
143 | 199 | $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>"; |
144 | 200 | $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>"; |
147 | 203 | $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>"; |
148 | 207 | $table .= "<th>" . wfMsg ( 'centralnotice-start-date') . "</th>"; |
149 | 208 | $table .= "<th>" . wfMsg ( 'centralnotice-end-date') . "</th>"; |
150 | 209 | $table .= "<th>" . wfMsg ( 'centralnotice-enabled') . "</th>"; |
| 210 | + $table .= "<th>" . wfMsg ( 'centralnotice-locked') . "</th>"; |
151 | 211 | $table .= "<th>" . wfMsg ( 'centralnotice-remove') . "</th>"; |
152 | | - $table .= "<th>" . wfMsg ( 'centralnotice-metrics') . "</th>"; |
153 | 212 | 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¬ice=$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>"; |
158 | 238 | $enabled = ( $row->notice_enabled == 'Y' ) ? true : false; |
159 | 239 | $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>"; |
160 | 243 | $table .= "<td>" . Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>"; |
161 | 244 | } |
162 | 245 | $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify'), |
163 | 246 | array('id' => 'centralnoticesubmit','name' => 'centralnoticesubmit') ) . "</td></tr>"; |
164 | | - // Need to add a preview button |
165 | 247 | $table .= "</table></fieldset></form>"; |
166 | 248 | $wgOut->addHTML( $table); |
167 | 249 | |
| 250 | + $current_day = date( 'd' ); |
| 251 | + $current_month = date( 'm'); |
| 252 | + $current_year = date( 'o' ); |
168 | 253 | $action = "addNotice"; |
| 254 | + |
| 255 | + global $wgNoticeProject,$wgNoticeLang; |
| 256 | + |
169 | 257 | $wgOut->addHtml( |
170 | 258 | Xml::openElement( 'form', array( |
171 | 259 | 'method' => 'post', |
172 | | - //'action' => $this->getTitle( $this->mUserName )->getLocalUrl( /* 'method=addNotice' */ ) )) . |
173 | 260 | 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl())) . |
174 | 261 | '<fieldset>' . |
175 | 262 | Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-notice' ) ) . |
— | — | @@ -177,6 +264,16 @@ |
178 | 265 | '<p>' . |
179 | 266 | Xml::inputLabel( wfMsg( 'centralnotice-notice-name' ), |
180 | 267 | '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) . |
181 | 278 | '</p>' . |
182 | 279 | '<p>' . |
183 | 280 | Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) . |
— | — | @@ -192,12 +289,21 @@ |
193 | 290 | $eNotice = htmlspecialchars( $notice ); |
194 | 291 | |
195 | 292 | if ($wgRequest->wasPosted()) { |
196 | | - $templateToRemove = $wgRequest->getVal('removeTemplates'); |
197 | | - if (isset($templateToRemove)) { |
| 293 | + $templateToRemove = $wgRequest->getArray('removeTemplates'); |
| 294 | + if (isset( $templateToRemove )) { |
198 | 295 | foreach ($templateToRemove as $template) { |
199 | 296 | $this->removeTemplateFor( $eNotice, $template); |
200 | 297 | } |
201 | 298 | } |
| 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 | + } |
202 | 308 | |
203 | 309 | } |
204 | 310 | |
— | — | @@ -210,12 +316,13 @@ |
211 | 317 | array('ORDER BY' => 'id'), |
212 | 318 | '' |
213 | 319 | ); |
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>"; |
220 | 327 | $table .= "<table cellpadding=\"9\">"; |
221 | 328 | $table .= "<tr><th colspan = \"3\"></th></tr>"; |
222 | 329 | $table .= "<th>" . wfMsg ( "centralnotice-templates" ) . "</th>"; |
— | — | @@ -223,51 +330,55 @@ |
224 | 331 | $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>"; |
225 | 332 | while ( $row = $dbr->fetchObject( $res )) { |
226 | 333 | $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>"; |
229 | 336 | } |
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>"; |
234 | 339 | $wgOut->addHTML( $table ); |
| 340 | + $wgOut->addHTML( $this->addTemplatesForm() ); |
| 341 | + } |
235 | 342 | |
236 | | - $wgOut->addHtml( |
237 | | - Xml::openElement( 'form', array( |
238 | | - 'method' => 'post', |
239 | | - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl( "method=addTemplateTo¬iceName=$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; |
254 | 360 | } |
255 | 361 | |
256 | | - function getTemplatesForNotice ( $noticeName ) { |
| 362 | +public function getTemplatesForNotice ( $noticeName ) { |
257 | 363 | $dbr = wfGetDB( DB_SLAVE ); |
258 | 364 | $centralnotice_table = 'central_notice_template_assignments'; |
259 | 365 | |
260 | 366 | $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" ), |
262 | 368 | "name,weight", |
263 | 369 | array ( 'notice_name' => $eNoticeName, 'campaign_id = id'), |
264 | 370 | '', |
265 | 371 | array('ORDER BY' => 'id'), |
266 | 372 | '' |
267 | 373 | ); |
| 374 | + $templates = array(); |
| 375 | + while ( $row = $dbr->fetchObject( $res )) { |
| 376 | + $tempaltes[$row->name] = $row->weight; |
| 377 | + } |
| 378 | + return $templates; |
268 | 379 | |
269 | 380 | } |
270 | 381 | |
271 | | - function addNotice( $noticeName ) { |
| 382 | + function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $project_name, $project_language ) { |
272 | 383 | global $wgOut; |
273 | 384 | $dbr = wfGetDB( DB_SLAVE ); |
274 | 385 | $centralnotice_table = 'central_notice_campaign'; |
— | — | @@ -280,7 +391,9 @@ |
281 | 392 | } |
282 | 393 | else { |
283 | 394 | $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)); |
285 | 398 | return; |
286 | 399 | } |
287 | 400 | } |
— | — | @@ -298,6 +411,8 @@ |
299 | 412 | } |
300 | 413 | else { |
301 | 414 | $dbw = wfGetDB( DB_MASTER ); |
| 415 | + $noticeId = htmlspecialchars($this->getNoticeId( $noticeName )); |
| 416 | + $res = $dbw->delete( "central_notice_template_assignments", array ( campaign_id => $noticeId)); |
302 | 417 | $res = $dbw->delete( $centralnotice_table, array ( notice_name => "$noticeName")); |
303 | 418 | return; |
304 | 419 | } |
— | — | @@ -311,9 +426,11 @@ |
312 | 427 | $eNoticeName = mysql_real_escape_string( $noticeName ); |
313 | 428 | $eTemplateName = mysql_real_escape_string( $templateName ); |
314 | 429 | $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)); |
316 | 433 | if ( $dbr->numRows( $res ) > 0) { |
317 | | - $wgOut->addHTML( wfMsg( 'centralnotice-notice-template-already-exist' ) ); |
| 434 | + $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) ); |
318 | 435 | } |
319 | 436 | else { |
320 | 437 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -338,4 +455,51 @@ |
339 | 456 | $eTemplateName = mysql_real_escape_string( $templateName ); |
340 | 457 | $res = $dbw->delete( $centralnotice_table, array ( name => "$eTemplateName", campaign_id => $noticeId)); |
341 | 458 | } |
| 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 | + } |
342 | 506 | } |
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | |
22 | 22 | function getJsOutput( $par ) { |
23 | 23 | $this->setLanguage( $par ); |
| 24 | + //need to return all site notices here |
24 | 25 | return |
25 | 26 | 'wgNotice="' . |
26 | 27 | strtr( |
— | — | @@ -68,6 +69,12 @@ |
69 | 70 | $encShowStyle = Xml::encodeJsVar( $showStyle ); |
70 | 71 | $encHideStyle = Xml::encodeJsVar( $hideStyle ); |
71 | 72 | $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 | + |
72 | 79 | $script = <<<END |
73 | 80 | var wgNoticeToggleState = (document.cookie.indexOf("hidesnmessage=1")==-1); |
74 | 81 | document.writeln( |
— | — | @@ -101,21 +108,21 @@ |
102 | 109 | document.cookie = work; |
103 | 110 | } |
104 | 111 | 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; |
110 | 117 | |
111 | 118 | while (currentTemplate < templates.length) { |
112 | 119 | for (i=0; i<weights[currentTemplate]; i++) { |
113 | | - weightedTemplates[weightedTemplates.length] = templates[currentTemplate] |
| 120 | + weightedTemplates[weightedTemplates.length] = templates[currentTemplate]; |
114 | 121 | } |
115 | | - currentTemplate++ |
| 122 | + currentTemplate++; |
116 | 123 | } |
117 | 124 | |
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]); |
120 | 127 | } |
121 | 128 | END; |
122 | 129 | return $script; |
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.i18n.php |
— | — | @@ -14,9 +14,8 @@ |
15 | 15 | 'noticetemplate' => 'Central Notice Template', |
16 | 16 | 'noticetranslate' => 'Central Notice Translate', |
17 | 17 | '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', |
21 | 20 | 'centralnotice-enabled' => 'Enabled', |
22 | 21 | 'centralnotice-modify' => 'Submit', |
23 | 22 | 'centralnotice-preview' => 'Preview', |
— | — | @@ -24,7 +23,7 @@ |
25 | 24 | 'centralnotice-remove' => 'Remove', |
26 | 25 | 'centralnotice-translate-heading' => 'Translate Text', |
27 | 26 | 'centralnotice-manage' => 'Manage Central Notice', |
28 | | - 'centralnotice-add' => 'Add a Central Notice', |
| 27 | + 'centralnotice-add' => 'Add', |
29 | 28 | 'centralnotice-add-notice' => 'Add a notice', |
30 | 29 | 'centralnotice-add-template' => 'Add a template', |
31 | 30 | 'centralnotice-show-notices' => 'Show notices', |
— | — | @@ -35,11 +34,127 @@ |
36 | 35 | 'centralnotice-template-name' => 'Template Name: ', |
37 | 36 | 'centralnotice-templates' => 'Templates', |
38 | 37 | 'centralnotice-weight' => 'Weight', |
| 38 | + 'centralnotice-locked' => 'Locked', |
39 | 39 | 'centralnotice-notices' => 'Notices', |
40 | 40 | 'centralnotice-notice-exists' => 'Notice already exists. Not adding', |
41 | 41 | 'centralnotice-notice-doesnt-exist' => 'Notice doesnt exist. Nothing to remove', |
42 | 42 | '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' |
44 | 159 | ); |
45 | 160 | |
46 | 161 | /** Afrikaans (Afrikaans) |