Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php |
— | — | @@ -67,15 +67,15 @@ |
68 | 68 | 'descriptionmsg' => 'centralnotice-desc', |
69 | 69 | ); |
70 | 70 | |
71 | | -$wgExtensionMessagesFiles['CentralNotice'] = dirname(__FILE__) . '/CentralNotice.i18n.php'; |
| 71 | +$dir = dirname( __FILE__ ) . '/'; |
72 | 72 | |
73 | | -$dir = dirname(__FILE__) . '/'; |
74 | | -$wgAutoloadClasses['CentralNotice'] = dirname(__FILE__) . '/SpecialNoticeCentral.php'; |
| 73 | +$wgExtensionMessagesFiles['CentralNotice'] = $dir . 'CentralNotice.i18n.php'; |
| 74 | +$wgAutoloadClasses['CentralNotice'] = $dir . 'SpecialNoticeCentral.php'; |
75 | 75 | |
76 | 76 | $wgAvailableRights[] = 'centralnotice_admin_rights'; |
77 | 77 | $wgGroupPermissions['sysop']['centralnotice_admin_rights'] = true; // Only sysops can make change |
78 | 78 | $wgGroupPermissions['sysop']['centralnotice_translate_rights'] = true; // Only sysops can make change |
79 | | - |
| 79 | + |
80 | 80 | $wgSpecialPages['CentralNotice'] = 'CentralNotice'; |
81 | 81 | $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate'; |
82 | 82 | $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
— | — | @@ -84,44 +84,36 @@ |
85 | 85 | $wgSpecialPageGroups['NoticeTemplate'] = 'wiki'; // Wiki data and tools" |
86 | 86 | |
87 | 87 | 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; |
96 | 90 | |
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 | + } |
102 | 94 | |
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'; |
106 | 102 | |
107 | 103 | 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'; |
118 | 106 | |
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'; |
126 | 118 | } |
127 | 119 | } |
128 | 120 | |
— | — | @@ -129,8 +121,7 @@ |
130 | 122 | global $wgScript, $wgUser; |
131 | 123 | global $wgNoticeLoader, $wgNoticeLang, $wgNoticeProject; |
132 | 124 | |
133 | | - $wgCentralnoticeTable = "central_notice_campaign"; |
134 | | - $wgNotice = efSelectNotice($wgCentralnoticeTable); |
| 125 | + $wgNotice = efSelectNotice( 'cn_notices' ); |
135 | 126 | if ( isset( $wgNotice ) ) { //Do we have an active notice campaign |
136 | 127 | $encNoticeLoader = htmlspecialchars( $wgNoticeLoader ); |
137 | 128 | $encProject = Xml::encodeJsVar( $wgNoticeProject ); |
— | — | @@ -170,15 +161,26 @@ |
171 | 162 | * Lookup function for active notice under a given language and project |
172 | 163 | * Returns and id for the running notice |
173 | 164 | */ |
174 | | -function efSelectNotice( $centralnotice_table ) { |
| 165 | +function efSelectNotice( $dbTable ) { |
175 | 166 | global $wgNoticeLang, $wgNoticeProject; |
176 | | - |
| 167 | + |
177 | 168 | $dbr = wfGetDB( DB_SLAVE ); |
178 | 169 | $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 | + ); |
180 | 179 | if ( $dbr->numRows( $res ) == 1) { |
181 | 180 | $row = $dbr->fetchObject( $res ); |
182 | | - return $row->notice_id; |
| 181 | + if( $row ) { |
| 182 | + return $row->not_id; |
| 183 | + } |
| 184 | + return null; |
183 | 185 | } |
184 | 186 | } |
185 | 187 | |
— | — | @@ -188,9 +190,11 @@ |
189 | 191 | * Trigger a purge of the notice loader when we've updated the source pages. |
190 | 192 | */ |
191 | 193 | function efCentralNoticeSaveHook( $article, $user, $text, $summary, $isMinor, |
192 | | - $isWatch, $section, $flags, $revision ) { |
| 194 | + $isWatch, $section, $flags, $revision ) { |
193 | 195 | efCentralNoticeMaybePurge( $article->getTitle() ); |
194 | | - return true; // Continue hook processing |
| 196 | + |
| 197 | + // Continue |
| 198 | + return true; |
195 | 199 | } |
196 | 200 | |
197 | 201 | /** |
— | — | @@ -198,9 +202,11 @@ |
199 | 203 | * Trigger a purge of the local notice when we've updated the source pages. |
200 | 204 | */ |
201 | 205 | function efCentralNoticeLocalSaveHook( $article, $user, $text, $summary, $isMinor, |
202 | | - $isWatch, $section, $flags, $revision ) { |
| 206 | + $isWatch, $section, $flags, $revision ) { |
203 | 207 | efCentralNoticeMaybePurgeLocal( $article->getTitle() ); |
204 | | - return true; // Continue hook processing |
| 208 | + |
| 209 | + // Continue |
| 210 | + return true; |
205 | 211 | } |
206 | 212 | |
207 | 213 | /** |
— | — | @@ -209,7 +215,9 @@ |
210 | 216 | */ |
211 | 217 | function efCentralNoticeDeleteHook( $article, $user, $reason ) { |
212 | 218 | efCentralNoticeMaybePurge( $article->getTitle() ); |
213 | | - return true; // Continue hook processing |
| 219 | + |
| 220 | + // Continue |
| 221 | + return true; |
214 | 222 | } |
215 | 223 | |
216 | 224 | /** |
— | — | @@ -218,7 +226,9 @@ |
219 | 227 | */ |
220 | 228 | function efCentralNoticeLocalDeleteHook( $article, $user, $reason ) { |
221 | 229 | efCentralNoticeMaybePurgeLocal( $article->getTitle() ); |
222 | | - return true; // Continue hook processing |
| 230 | + |
| 231 | + // Continue |
| 232 | + return true; |
223 | 233 | } |
224 | 234 | |
225 | 235 | /** |
— | — | @@ -276,6 +286,7 @@ |
277 | 287 | */ |
278 | 288 | function efCentralNoticeEpoch() { |
279 | 289 | global $wgMemc; |
| 290 | + |
280 | 291 | $epoch = $wgMemc->get( 'centralnotice-epoch' ); |
281 | 292 | if( $epoch ) { |
282 | 293 | return wfTimestamp( TS_MW, $epoch ); |
— | — | @@ -290,6 +301,7 @@ |
291 | 302 | */ |
292 | 303 | function efCentralNoticeUpdateEpoch() { |
293 | 304 | global $wgMemc, $wgNoticeServerTimeout; |
| 305 | + |
294 | 306 | $epoch = wfTimestamp( TS_MW ); |
295 | 307 | $wgMemc->set( "centralnotice-epoch", $epoch, $wgNoticeServerTimeout ); |
296 | 308 | return $epoch; |
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeCentral.php |
— | — | @@ -5,347 +5,475 @@ |
6 | 6 | exit( 1 ); |
7 | 7 | } |
8 | 8 | |
9 | | -class CentralNotice extends SpecialPage |
10 | | -{ |
| 9 | +class CentralNotice extends SpecialPage { |
| 10 | + |
| 11 | + /* Functions */ |
| 12 | + |
11 | 13 | function CentralNotice() { |
12 | | - SpecialPage::SpecialPage("CentralNotice"); |
13 | | - wfLoadExtensionMessages('CentralNotice'); |
| 14 | + // Register special page |
| 15 | + SpecialPage::SpecialPage( 'CentralNotice' ); |
| 16 | + |
| 17 | + // Internationalization |
| 18 | + wfLoadExtensionMessages( 'CentralNotice' ); |
14 | 19 | } |
15 | 20 | |
16 | 21 | function execute( $sub ) { |
17 | 22 | global $wgOut, $wgUser, $wgRequest; |
18 | 23 | |
| 24 | + // Begin output |
19 | 25 | $this->setHeaders(); |
| 26 | + |
| 27 | + // Get current skin |
20 | 28 | $sk = $wgUser->getSkin(); |
21 | | - |
22 | | - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' )) { |
| 29 | + |
| 30 | + // Check permissions |
| 31 | + if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' ) ) { |
23 | 32 | $wgOut->permissionRequired( 'centralnotice_admin_rights' ); |
24 | 33 | return; |
25 | 34 | } |
26 | 35 | |
27 | | - $wgOut->addWikiText( wfMsg( 'centralnotice-summary' )); |
| 36 | + // Show summary |
| 37 | + $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) ); |
| 38 | + |
| 39 | + // Show header |
28 | 40 | $this->printHeader(); |
29 | | - |
30 | | - |
| 41 | + |
| 42 | + // Handle form sumissions |
31 | 43 | 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 |
37 | 55 | foreach ( $toRemove as $template ) { |
38 | 56 | $this->removeNotice( $template ); |
39 | 57 | } |
| 58 | + |
| 59 | + // Show list of notices |
40 | 60 | $this->listNotices(); |
41 | 61 | return; |
42 | 62 | } |
43 | | - |
44 | | - $lockedNotices = $wgRequest->getArray('locked'); |
| 63 | + |
| 64 | + // Handle locking/unlocking |
| 65 | + $lockedNotices = $wgRequest->getArray( 'locked' ); |
45 | 66 | 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); |
48 | 69 | |
| 70 | + // Set locked/unlocked flag accordingly |
49 | 71 | foreach( $lockedNotices as $notice ) { |
50 | 72 | $this->updateLock( $notice, 'Y' ); |
51 | 73 | } |
52 | | - |
53 | | - foreach( $diff_set as $notice ) { |
| 74 | + foreach( $unlockedNotices as $notice ) { |
54 | 75 | $this->updateLock( $notice, 'N' ); |
55 | 76 | } |
56 | 77 | } |
| 78 | + |
| 79 | + // Handle enabling/disabling |
57 | 80 | $enabledNotices = $wgRequest->getArray('enabled'); |
58 | 81 | 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 |
62 | 86 | foreach ( $enabledNotices as $notice) { |
63 | 87 | $this->updateEnabled( $notice, 'Y'); |
64 | 88 | } |
65 | | - foreach ( $diff_set as $notice) { |
| 89 | + foreach ( $disabledNotices as $notice) { |
66 | 90 | $this->updateEnabled( $notice, 'N'); |
67 | 91 | } |
68 | 92 | } |
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; |
78 | 104 | } |
79 | | - $updatedStartDate .= "00"; |
| 105 | + $updatedStart .= '00'; |
80 | 106 | } |
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; |
85 | 111 | } |
86 | | - $updatedEndDate .= "000000"; |
87 | | - } |
88 | | - $this->updateNoticeDate( $noticeName, $updatedStartDate, $updatedEndDate ); |
| 112 | + $updatedEnd .= '000000'; |
| 113 | + } |
| 114 | + $this->updateNoticeDate( $noticeName, $updatedStart, $updatedEnd ); |
89 | 115 | } |
90 | | - $noticeName = $wgRequest->getVal('notice'); |
91 | | - $updatedWeights = $wgRequest->getArray('weight'); |
| 116 | + |
| 117 | + // Handle weight change |
| 118 | + $updatedWeights = $wgRequest->getArray( 'weight' ); |
92 | 119 | 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 | + } |
96 | 123 | } |
97 | 124 | } |
98 | | - |
| 125 | + |
| 126 | + // Handle adding |
99 | 127 | $method = $wgRequest->getVal('method'); |
100 | 128 | $this->showAll = $wgRequest->getVal('showAll'); |
101 | | - |
102 | 129 | 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 == '' ) { |
112 | 139 | $wgOut->addHtml( wfMsg ( 'centralnotice-null-string' ) ); |
113 | 140 | } |
114 | 141 | else { |
115 | 142 | $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $start_hour, $start_min, $project_name, $project_language ); |
116 | 143 | } |
117 | 144 | } |
| 145 | + |
| 146 | + // Handle removing |
118 | 147 | if ( $method == 'removeNotice' ) { |
119 | | - $noticeName = $wgRequest->getVal ('noticeName'); |
| 148 | + $noticeName = $wgRequest->getVal ( 'noticeName' ); |
120 | 149 | $this->removeNotice ( $noticeName ); |
121 | 150 | } |
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 ); |
126 | 157 | $this->listNoticeDetail( $noticeName ); |
127 | 158 | return; |
128 | 159 | } |
129 | | - if ( $method == 'removeTemplateFor') { |
130 | | - $noticeName = $wgRequest->getVal ( 'noticeName'); |
| 160 | + |
| 161 | + // Handle removing of template |
| 162 | + if ( $method == 'removeTemplateFor' ) { |
| 163 | + $noticeName = $wgRequest->getVal ( 'noticeName' ); |
131 | 164 | $templateName = $wgRequest->getVal ( 'templateName '); |
132 | 165 | $this->removeTemplateFor( $noticeName , $templateName ); |
133 | 166 | } |
134 | | - if ( $method == 'listNoticeDetail') { |
| 167 | + |
| 168 | + // Handle showing detail |
| 169 | + if ( $method == 'listNoticeDetail' ) { |
135 | 170 | $notice = $wgRequest->getVal ( 'notice' ); |
136 | 171 | $this->listNoticeDetail( $notice ); |
137 | 172 | return; |
138 | 173 | } |
139 | | - |
| 174 | + |
| 175 | + // Show lsit of notices |
140 | 176 | $this->listNotices(); |
141 | 177 | } |
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 ) { |
145 | 181 | $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 | + ); |
147 | 186 | } |
148 | | - |
| 187 | + |
149 | 188 | static public function printHeader() { |
150 | 189 | 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 | + } |
154 | 200 | |
155 | | - } |
156 | | - |
157 | 201 | function getNoticesName() { |
158 | | - $centralnotice_table = "central_notice_campaign"; |
159 | 202 | $dbr = wfGetDB( DB_SLAVE ); |
160 | | - $res = $dbr->select( $centralnotice_table,"notice_name" ); |
| 203 | + $res = $dbr->select( 'cn_notices', 'not_name' ); |
161 | 204 | $notices = array(); |
162 | 205 | while ( $row = $dbr->fetchObject( $res )) { |
163 | | - array_push( $notices, $row->notice_name); |
| 206 | + array_push( $notices, $row->not_name); |
164 | 207 | } |
165 | 208 | return $notices; |
166 | 209 | } |
| 210 | + |
| 211 | + /* |
| 212 | + * listNotices |
| 213 | + * |
| 214 | + * Print out all campaigns found in db |
| 215 | + */ |
167 | 216 | |
168 | | - #### |
169 | | - # listNotices |
170 | | - ### |
171 | | - # Print out all campaigns found in db |
172 | | - ### |
173 | | - |
174 | 217 | function listNotices() { |
175 | | - global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang; |
176 | | - |
177 | | - $centralnotice_table = "central_notice_campaign"; |
| 218 | + global $wgOut, $wgRequest, $wgTitle, $wgScript, $wgNoticeLang; |
| 219 | + |
178 | 220 | $dbr = wfGetDB( DB_SLAVE ); |
179 | | - $this->showAll = 'Y'; //temp |
| 221 | + |
| 222 | + /* |
| 223 | + * This is temporarily hard-coded |
| 224 | + */ |
| 225 | + $this->showAll = 'Y'; |
| 226 | + |
180 | 227 | 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 | + ); |
188 | 258 | } |
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 | | - } |
198 | 259 | |
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); |
208 | 269 | |
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¬ice=$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¬ice=$row->not_name") |
| 301 | + ), |
| 302 | + $row->not_name |
| 303 | + ) |
| 304 | + ) . |
| 305 | + Xml::tags( 'td', null, |
| 306 | + $row->not_project |
| 307 | + ) . |
| 308 | + $htmlLanguage |
| 309 | + ); |
227 | 310 | |
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 ); |
234 | 317 | |
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 ); |
237 | 320 | $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 | + ); |
248 | 342 | } |
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 | + ); |
253 | 353 | |
| 354 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 355 | + $htmlOut .= XML::closeElement( 'fieldset' ); |
| 356 | + $htmlOut .= XML::closeElement( 'form' ); |
| 357 | + |
| 358 | + // Other section |
| 359 | + |
254 | 360 | $current_day = gmdate( 'd' ); |
255 | 361 | $current_month = gmdate( 'm'); |
256 | 362 | $current_year = gmdate( 'o' ); |
257 | 363 | $action = "addNotice"; |
258 | 364 | |
259 | | - global $wgNoticeProject,$wpUserLang; |
| 365 | + global $wgNoticeProject, $wpUserLang; |
260 | 366 | |
261 | 367 | list( $lsLabel, $lsSelect) = Xml::languageSelector( $wpUserLang ); |
262 | 368 | $languagebar = $this->tableRow( $lsLabel, $lsSelect) ; |
263 | 369 | |
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 ); |
292 | 403 | } |
293 | | - |
| 404 | + |
294 | 405 | 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 | + |
301 | 412 | 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 ); |
311 | 421 | } |
312 | 422 | } |
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 ); |
320 | 435 | } |
321 | 436 | } |
322 | | - |
323 | 437 | } |
324 | | - |
325 | | - $centralnotice_table = "central_notice_campaign"; |
| 438 | + |
326 | 439 | $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 | + |
339 | 463 | $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); |
348 | 472 | |
349 | 473 | |
| 474 | + /* |
| 475 | + * Needs to be refactored to use the Xml class |
| 476 | + * |
| 477 | + */ |
350 | 478 | $table = Xml::openElement( 'form', array( |
351 | 479 | 'method' => 'post', |
352 | 480 | 'action' => '')); |
— | — | @@ -363,53 +491,57 @@ |
364 | 492 | |
365 | 493 | while ( $row = $dbr->fetchObject( $res )) { |
366 | 494 | |
367 | | - $start_timestamp = $row->notice_start_date; |
| 495 | + $start_timestamp = $row->not_start; |
368 | 496 | $start_year = substr( $start_timestamp, 0 , 4); |
369 | 497 | $start_month = substr( $start_timestamp, 4, 2); |
370 | 498 | $start_day = substr( $start_timestamp, 6, 2); |
371 | 499 | $start_hour = substr( $start_timestamp, 8, 2); |
372 | 500 | $start_min = substr( $start_timestamp, 10, 2); |
373 | 501 | |
374 | | - $end_timestamp = $row->notice_end_date; |
| 502 | + $end_timestamp = $row->not_end; |
375 | 503 | $end_year = substr( $end_timestamp, 0 , 4); |
376 | 504 | $end_month = substr( $end_timestamp, 4, 2); |
377 | 505 | $end_day = substr( $end_timestamp, 6, 2); |
378 | 506 | |
| 507 | + /* |
| 508 | + * Needs to be refactored to use the Xml class |
| 509 | + * |
| 510 | + */ |
379 | 511 | $table .= "<tr><td>" . |
380 | | - $row->notice_project . |
| 512 | + $row->not_project . |
381 | 513 | "</td>" . |
382 | 514 | "<td>" . |
383 | | - $row->notice_language . |
| 515 | + $row->not_language . |
384 | 516 | "</td>" . |
385 | 517 | "<td>" . |
386 | | - Xml::listDropDown( "start_date[$row->notice_name][year]", |
| 518 | + Xml::listDropDown( "start[$row->not_name][year]", |
387 | 519 | $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]", |
389 | 521 | $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]", |
391 | 523 | $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]", |
393 | 525 | $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]", |
395 | 527 | $this->dropDownList( wfMsg( 'centralnotice-min'), $min), '', $start_min, '', 7) . |
396 | 528 | "</td>"; |
397 | 529 | $table .= "<td>" . |
398 | | - Xml::listDropDown( "end_date[$row->notice_name][year]", |
| 530 | + Xml::listDropDown( "end[$row->not_name][year]", |
399 | 531 | $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]", |
401 | 533 | $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]", |
403 | 535 | $this->dropDownList( wfMsg( 'centralnotice-day'), $days ), '', $end_day, '', 10 ) . |
404 | 536 | "</td>"; |
405 | 537 | |
406 | | - $enabled = ( $row->notice_enabled == 'Y' ) ? true : false; |
| 538 | + $enabled = ( $row->not_enabled == 'Y' ) ? true : false; |
407 | 539 | $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; |
410 | 542 | $table .= "<td>" . |
411 | | - Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>"; |
| 543 | + Xml::check( 'locked[]', $locked, array ( 'value' => $row->not_name)) . "</td>"; |
412 | 544 | $table .= "<td>" . |
413 | | - Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>"; |
| 545 | + Xml::check( 'removeNotices[]', false, array( 'value' => $row->not_name)) . "</td>"; |
414 | 546 | } |
415 | 547 | $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) . "</tr></td"; |
416 | 548 | $table .= Xml::closeElement( 'table' ); |
— | — | @@ -417,15 +549,15 @@ |
418 | 550 | $table .= "</fieldset>"; |
419 | 551 | $wgOut->addHtml( $table ) ; |
420 | 552 | |
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'), |
428 | 560 | '', |
429 | | - array('ORDER BY' => 'notice_id'), |
| 561 | + array('ORDER BY' => 'not_id'), |
430 | 562 | '' |
431 | 563 | ); |
432 | 564 | if ( $dbr->numRows( $res ) < 1) { |
— | — | @@ -434,6 +566,10 @@ |
435 | 567 | return; |
436 | 568 | } |
437 | 569 | |
| 570 | + /* |
| 571 | + * Needs to be refactored to use the Xml class |
| 572 | + * |
| 573 | + */ |
438 | 574 | $table = "<form name='centranoticeform' id='centralnoticeform' method='post'>"; |
439 | 575 | $table .= '<fieldset><legend>' . $eNotice . "</legend>"; |
440 | 576 | $table .= "<table cellpadding=\"9\">"; |
— | — | @@ -442,9 +578,9 @@ |
443 | 579 | $table .= "<th>" . wfMsg ( "centralnotice-weight" ) . "</th>"; |
444 | 580 | $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>"; |
445 | 581 | 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>"; |
449 | 585 | } |
450 | 586 | $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify') ) . "</td></tr>"; |
451 | 587 | $table .= "</table></fieldset></form>"; |
— | — | @@ -453,13 +589,9 @@ |
454 | 590 | } |
455 | 591 | |
456 | 592 | function addTemplatesForm() { |
457 | | - $centralnotice_table = 'central_notice_templates'; |
458 | 593 | $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 | + |
464 | 596 | $table = "<form name='centranoticeform' id='centralnoticeform' method='post'>"; |
465 | 597 | $table .= '<fieldset><legend>' . wfMsg( "centralnotice-available-templates") . '</legend>'; |
466 | 598 | $table .= "<table cellpadding=\"9\">"; |
— | — | @@ -467,32 +599,36 @@ |
468 | 600 | $table .= "<th>" . wfMsg ( 'centralnotice-template-name') . "</th>"; |
469 | 601 | $table .= "<th>" . wfMsg ( 'centralnotice-add' ) . "</th>"; |
470 | 602 | 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>"; |
473 | 605 | } |
474 | 606 | $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify')) . "</td></tr>"; |
475 | 607 | $table .= "</table></fieldset></form>"; |
476 | 608 | return $table; |
477 | 609 | } |
478 | | - |
479 | | - public function getTemplatesForNotice ( $noticeName ) { |
| 610 | + |
| 611 | + public function getTemplatesForNotice ( $noticeName ) { |
480 | 612 | $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 | + ); |
495 | 631 | $templates = array(); |
496 | | - while ( $row = $dbr->fetchObject( $res )) { |
| 632 | + while ( $row = $dbr->fetchObject( $res ) ) { |
497 | 633 | $templates[$row->name] = $row->weight; |
498 | 634 | } |
499 | 635 | return $templates; |
— | — | @@ -501,58 +637,50 @@ |
502 | 638 | |
503 | 639 | function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $start_hour, $start_min, $project_name, $project_language ) { |
504 | 640 | global $wgOut; |
| 641 | + |
505 | 642 | $dbr = wfGetDB( DB_SLAVE ); |
506 | | - $centralnotice_table = 'central_notice_campaign'; |
507 | 643 | $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 ) ); |
511 | 645 | if ( $dbr->numRows( $res ) > 0 ) { |
512 | 646 | $wgOut->addHTML( wfMsg( 'centralnotice-notice-exists' ) ); |
513 | 647 | return; |
514 | 648 | } |
515 | 649 | else { |
516 | 650 | $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 ) { |
523 | 653 | $end_month = '01'; |
524 | 654 | $end_year = ($start_year + 1); |
525 | | - } |
526 | | - elseif ( $start_month == '09' ) { |
| 655 | + } elseif ( $start_month == '09' ) { |
527 | 656 | $end_month = '10'; |
528 | 657 | $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 ); |
532 | 660 | $end_year = $start_year; |
533 | 661 | } |
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 | + ); |
545 | 672 | 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 | + ); |
547 | 684 | } |
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 | | - } |
557 | 685 | return; |
558 | 686 | } |
559 | 687 | } |
— | — | @@ -560,170 +688,187 @@ |
561 | 689 | function removeNotice ( $noticeName ) { |
562 | 690 | global $wgOut; |
563 | 691 | $dbr = wfGetDB( DB_SLAVE ); |
564 | | - $centralnotice_table = 'central_notice_campaign'; |
565 | | - |
| 692 | + |
566 | 693 | $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 | + ); |
568 | 697 | if ( $dbr->numRows( $res ) < 1 ) { |
569 | 698 | $wgOut->addHTML( wfMsg( 'centralnotice-notice-doesnt-exist' ) ); |
570 | 699 | return; |
571 | 700 | } |
572 | 701 | $row = $dbr->fetchObject( $res ); |
573 | | - if ( $row->notice_locked == 'Y' ) { |
| 702 | + if ( $row->not_locked == 'Y' ) { |
574 | 703 | $wgOut->addHTML( wfMsg( 'centralnotice-notice-is-locked' ) ); |
575 | 704 | return; |
576 | | - } |
577 | | - else { |
| 705 | + } else { |
578 | 706 | $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 ) ); |
582 | 710 | return; |
583 | 711 | } |
584 | 712 | } |
585 | | - |
586 | | - function addTemplateTo( $noticeName, $templateName, $weight) { |
| 713 | + |
| 714 | + function addTemplateTo( $noticeName, $templateName, $weight ) { |
587 | 715 | global $wgOut; |
588 | | - $centralnotice_table = "central_notice_template_assignments"; |
589 | 716 | |
590 | 717 | $dbr = wfGetDB( DB_SLAVE ); |
591 | 718 | $eNoticeName = mysql_real_escape_string( $noticeName ); |
592 | 719 | $eTemplateName = mysql_real_escape_string( $templateName ); |
593 | 720 | $eWeight = mysql_real_escape_string ( $weight ); |
594 | | - |
| 721 | + |
595 | 722 | $noticeId = $this->getNoticeId( $noticeName ); |
596 | 723 | $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 ) { |
602 | 731 | $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) ); |
603 | | - } |
604 | | - else { |
| 732 | + } else { |
605 | 733 | $dbw = wfGetDB( DB_MASTER ); |
606 | 734 | $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 | + ); |
608 | 742 | } |
609 | 743 | } |
610 | 744 | |
611 | 745 | function getNoticeId ( $noticeName ) { |
612 | 746 | $dbr = wfGetDB( DB_SLAVE ); |
613 | | - $centralnotice_table = 'central_notice_campaign'; |
614 | 747 | $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 ) ); |
616 | 749 | $row = $dbr->fetchObject( $res ); |
617 | | - return $row->notice_id; |
| 750 | + return $row->not_id; |
618 | 751 | } |
619 | 752 | |
620 | 753 | function getNoticeLanguage ( $noticeName ) { |
621 | 754 | $dbr = wfGetDB( DB_SLAVE ); |
622 | | - $centralnotice_table = 'central_notice_campaign'; |
623 | 755 | $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 ) ); |
625 | 757 | $row = $dbr->fetchObject( $res ); |
626 | | - return $row->notice_language; |
| 758 | + return $row->not_language; |
627 | 759 | } |
628 | 760 | |
629 | 761 | function getNoticeProjectName ( $noticeName ) { |
630 | 762 | $dbr = wfGetDB( DB_SLAVE ); |
631 | | - $centralnotice_table = 'central_notice_campaign'; |
632 | 763 | $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 ) ); |
634 | 765 | $row = $dbr->fetchObject( $res ); |
635 | | - return $row->notice_project; |
| 766 | + return $row->not_project; |
636 | 767 | } |
637 | 768 | |
638 | 769 | function getTemplateId ( $templateName ) { |
639 | 770 | $dbr = wfGetDB( DB_SLAVE ); |
640 | | - $centralnotice_table = 'central_notice_templates'; |
641 | 771 | $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 ) ); |
643 | 773 | $row = $dbr->fetchObject( $res ); |
644 | | - return $row->template_id; |
| 774 | + return $row->tmp_id; |
645 | 775 | } |
646 | | - |
| 776 | + |
647 | 777 | function removeTemplateFor( $noticeName, $templateName) { |
648 | 778 | global $wgOut; |
649 | | - $centralnotice_table = "central_notice_template_assignments"; |
| 779 | + |
650 | 780 | $dbw = wfGetDB( DB_MASTER ); |
651 | 781 | $noticeId = $this->getNoticeId( $noticeName ); |
652 | 782 | $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 ) ); |
654 | 784 | } |
655 | 785 | |
656 | | - function updateNoticeDate ( $noticeName, $startDate, $endDate ) { |
| 786 | + function updateNoticeDate ( $noticeName, $start, $end ) { |
657 | 787 | global $wgOut; |
658 | | - $centralnotice_table = "central_notice_campaign"; |
| 788 | + |
659 | 789 | $dbr = wfGetDB( DB_SLAVE ); |
660 | 790 | $project_name = $this->getNoticeProjectname( $noticeName ); |
661 | 791 | $project_language = $this->getNoticeLanguage( $noticeName ); |
662 | 792 | |
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' ) ); |
666 | 796 | return; |
667 | 797 | } |
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' ) ); |
672 | 803 | } |
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 | + ); |
680 | 814 | if ( $dbr->numRows( $res ) > 1 ) { |
681 | | - $wgOut->addHtml( wfMsg( 'centralnotice-overlap-with-existing-notice' )); |
| 815 | + $wgOut->addHtml( wfMsg( 'centralnotice-overlap-with-existing-notice' ) ); |
682 | 816 | return; |
683 | | - } |
684 | | - else { |
| 817 | + } else { |
685 | 818 | $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 | + ); |
692 | 826 | } |
693 | 827 | } |
694 | 828 | |
695 | 829 | function updateLock ( $noticeName, $isLocked ) { |
696 | 830 | global $wgOut; |
697 | | - $centralnotice_table = 'central_notice_campaign'; |
| 831 | + |
698 | 832 | $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 { |
704 | 839 | $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 | + ); |
706 | 844 | } |
707 | 845 | } |
708 | 846 | |
709 | 847 | function updateWeight ( $noticeName, $templateName, $weight ) { |
710 | | - $centralnotice_table = 'central_notice_template_assignments'; |
711 | 848 | $dbw = wfGetDB( DB_MASTER ); |
712 | 849 | $noticeId = $this->getNoticeId( $noticeName ); |
713 | 850 | $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 | + ); |
715 | 858 | } |
716 | 859 | |
717 | 860 | function dropDownList ( $text, $values ) { |
718 | | - $dropDown = "* $text\n"; |
| 861 | + $dropDown = "* {$text}\n"; |
719 | 862 | foreach( $values as $element ) { |
720 | | - $dropDown .= "**$element\n"; |
| 863 | + $dropDown .= "**{$element}\n"; |
721 | 864 | } |
722 | 865 | return $dropDown; |
723 | 866 | } |
724 | | - |
| 867 | + |
725 | 868 | 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 | + } |
728 | 873 | return $text; |
729 | 874 | } |
730 | 875 | } |
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`) |
12 | 12 | ) /*$wgDBTableOptions*/; |
13 | 13 | |
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`) |
20 | 20 | ) /*$wgDBTableOptions*/; |
21 | 21 | |
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`) |
26 | 26 | ) /*$wgDBTableOptions*/; |
Index: branches/CentralNotice-SpecialPage-Integration/rebuildTemplates.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | echo " php extensions/CentralNotice/rebuildTemplates\n"; |
14 | 14 | } else { |
15 | 15 | echo "Rebuilding templates ...\n"; |
16 | | - $notice = efSelectNotice( 'central_notice_campaign' ); |
| 16 | + $notice = efSelectNotice( 'cn_notices' ); |
17 | 17 | $templates = array(); |
18 | 18 | $templates = CentralNotice::getTemplatesForNotice( $notice ); |
19 | 19 | |
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | $body = file_get_contents( 'php://input' ); |
49 | 49 | $wgOut->addHtml( Xml::element( 'pre', null, $body ) ); |
50 | 50 | |
51 | | - // Build list of templates to remove |
| 51 | + // Handle removing |
52 | 52 | $toRemove = $wgRequest->getArray( 'removeTemplates' ); |
53 | 53 | if ( isset( $toRemove ) ) { |
54 | 54 | // Remove templates in list |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | | - // Build a list of notices to enable |
| 64 | + // Handle enabling/disabling |
65 | 65 | $enabledNotices = $wgRequest->getArray( 'enabled' ); |
66 | 66 | if ( isset( $enabledNotices ) ) { |
67 | 67 | // Build a list of notices to disable |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | global $egCentralNoticeTables; |
99 | 99 | |
100 | 100 | $dbw = wfGetDB( DB_MASTER ); |
101 | | - $res = $dbw->update( 'central_notice_campaign', |
| 101 | + $res = $dbw->update( 'cn_notices', |
102 | 102 | array( cnc_enabled => $enabled ), |
103 | 103 | array( cnc_template => $update_notice ), |
104 | 104 | __METHOD__ |
— | — | @@ -110,16 +110,16 @@ |
111 | 111 | |
112 | 112 | function queryTemplates() { |
113 | 113 | $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' ), |
116 | 116 | '', |
117 | 117 | __METHOD__, |
118 | | - array( 'ORDER BY' => 'template_id' ) |
| 118 | + array( 'ORDER BY' => 'tmp_id' ) |
119 | 119 | ); |
120 | 120 | |
121 | 121 | $templates = array(); |
122 | 122 | while ( $row = $dbr->fetchObject( $res ) ) { |
123 | | - array_push( $templates, $row->template_name ); |
| 123 | + array_push( $templates, $row->tmp_name ); |
124 | 124 | } |
125 | 125 | |
126 | 126 | return $templates; |
— | — | @@ -162,6 +162,7 @@ |
163 | 163 | ); |
164 | 164 | $htmlOut .= Xml::closeElement( 'table' ); |
165 | 165 | $htmlOut .= XML::closeElement( 'fieldset' ); |
| 166 | + $htmlOut .= XML::closeElement( 'form' ); |
166 | 167 | |
167 | 168 | // Notices |
168 | 169 | $htmlOut .= Xml::openElement( 'form', |
— | — | @@ -243,8 +244,8 @@ |
244 | 245 | } |
245 | 246 | |
246 | 247 | $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 ), |
249 | 250 | __METHOD__ |
250 | 251 | ); |
251 | 252 | |
— | — | @@ -253,8 +254,8 @@ |
254 | 255 | return; |
255 | 256 | } else { |
256 | 257 | $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 ), |
259 | 260 | __METHOD__ |
260 | 261 | ); |
261 | 262 | |
— | — | @@ -279,8 +280,8 @@ |
280 | 281 | |
281 | 282 | $templateId = $this->getTemplateId( $templateName ); |
282 | 283 | $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 ), |
285 | 286 | __METHOD__ |
286 | 287 | ); |
287 | 288 | |
— | — | @@ -289,8 +290,8 @@ |
290 | 291 | return; |
291 | 292 | } else { |
292 | 293 | $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 ), |
295 | 296 | __METHOD__ |
296 | 297 | ); |
297 | 298 | } |
— | — | @@ -300,14 +301,14 @@ |
301 | 302 | global $wgOut, $egCentralNoticeTables; |
302 | 303 | |
303 | 304 | $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 ), |
306 | 307 | __METHOD__ |
307 | 308 | ); |
308 | 309 | |
309 | 310 | $row = $dbr->fetchObject( $res ); |
310 | 311 | if( $row ) { |
311 | | - return $row->template_id; |
| 312 | + return $row->tmp_id; |
312 | 313 | } |
313 | 314 | return null; |
314 | 315 | } |
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php |
— | — | @@ -193,14 +193,16 @@ |
194 | 194 | |
195 | 195 | function chooseTemplate ( $notice ) { |
196 | 196 | $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 | + ); |
205 | 207 | $templates = array(); |
206 | 208 | while ( $row = $dbr->fetchObject( $res )) { |
207 | 209 | push ( $templates, $row->name); |
Property changes on: branches/CentralNotice-SpecialPage-Integration |
___________________________________________________________________ |
Name: svn:ignore |
208 | 210 | + .project |