Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php |
— | — | @@ -97,11 +97,8 @@ |
98 | 98 | $wgGroupPermissions['sysop']['centralnotice_translate_rights'] = true; // Only sysops can make change |
99 | 99 | |
100 | 100 | $wgSpecialPages['CentralNotice'] = 'CentralNotice'; |
101 | | -$wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate'; |
102 | 101 | $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
103 | 102 | $wgSpecialPageGroups['CentralNotice'] = 'wiki'; // Wiki data and tools" |
104 | | -$wgSpecialPageGroups['NoticeTranslate'] = 'wiki'; // Wiki data and tools" |
105 | | -$wgSpecialPageGroups['NoticeTemplate'] = 'wiki'; // Wiki data and tools" |
106 | 103 | |
107 | 104 | function efCentralNoticeSetup() { |
108 | 105 | global $wgHooks, $wgNoticeInfrastructure, $wgAutoloadClasses, $wgSpecialPages; |
— | — | @@ -133,9 +130,6 @@ |
134 | 131 | |
135 | 132 | $wgSpecialPages['NoticeTemplate'] = 'SpecialNoticeTemplate'; |
136 | 133 | $wgAutoloadClasses['SpecialNoticeTemplate'] = $dir . 'SpecialNoticeTemplate.php'; |
137 | | - |
138 | | - $wgSpecialPages['NoticeTranslate'] = 'SpecialNoticeTranslate'; |
139 | | - $wgAutoloadClasses['SpecialNoticeTranslate'] = $dir . 'SpecialNoticeTranslate.php'; |
140 | 134 | } |
141 | 135 | } |
142 | 136 | |
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php |
— | — | @@ -48,11 +48,21 @@ |
49 | 49 | foreach ( $toRemove as $template ) { |
50 | 50 | $this->removeTemplate( $template ); |
51 | 51 | } |
52 | | - |
53 | | - // Show a list of templates |
54 | | - $this->listTemplates(); |
55 | | - return; |
56 | 52 | } |
| 53 | + |
| 54 | + // Handle translation message update |
| 55 | + $update = $wgRequest->getArray('updateText'); |
| 56 | + $token = $wgRequest->getArray('token'); |
| 57 | + if (isset ( $update ) ) { |
| 58 | + foreach ( $update as $lang => $messages ) { |
| 59 | + foreach ( $messages as $text => $translation) { |
| 60 | + // If we actually have text |
| 61 | + if ( $translation ) { |
| 62 | + $this->updateMessage( $text, $translation, $lang, $token ); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
57 | 67 | } |
58 | 68 | |
59 | 69 | // Handle adding |
— | — | @@ -61,51 +71,38 @@ |
62 | 72 | $wgRequest->getVal( 'templateName' ), |
63 | 73 | $wgRequest->getVal( 'templateBody' ) |
64 | 74 | ); |
| 75 | + $sub = 'view'; |
65 | 76 | } |
66 | 77 | |
67 | | - // If this is a sub-page, show list of templates |
68 | | - if ( $sub == 'listTemplates' ) { |
69 | | - $this->listTemplates(); |
| 78 | + // Handle Editing |
| 79 | + if ( $wgRequest->getVal( 'wpMethod' ) == 'editTemplate' ) { |
| 80 | + $this->editTemplate( |
| 81 | + $wgRequest->getVal( 'template' ), |
| 82 | + $wgRequest->getVal( 'templateBody' ) |
| 83 | + ); |
| 84 | + $sub = 'view'; |
| 85 | + } |
| 86 | + |
| 87 | + // Handle viewing a specific template |
| 88 | + if ( $sub == 'view' && $wgRequest->getText( 'template' ) != '' ) { |
| 89 | + $this->showView(); |
70 | 90 | return; |
71 | 91 | } |
72 | | - if ( $sub == 'preview' ) { |
73 | | - |
74 | | - $userLang = $wgRequest->getVal( 'wpUserLanguage' ); |
75 | | - $template = $wgRequest->getText( 'template' ); |
76 | | - |
77 | | - $htmlOut = $this->previewTemplate( $template, $userLang ); |
78 | | - $wgOut->addHTML( $htmlOut ); |
79 | | - |
| 92 | + |
| 93 | + // Handle viewing a specific template |
| 94 | + if ( $sub == 'add' ) { |
| 95 | + $this->showAdd(); |
80 | 96 | return; |
81 | 97 | } |
82 | 98 | |
83 | | - $this->listTemplates(); |
| 99 | + // Show list by default |
| 100 | + $this->showList(); |
84 | 101 | } |
85 | 102 | |
86 | | - static function queryTemplates() { |
87 | | - $dbr = wfGetDB( DB_SLAVE ); |
88 | | - $res = $dbr->select( 'cn_templates', |
89 | | - array( 'tmp_name', 'tmp_id' ), |
90 | | - '', |
91 | | - __METHOD__, |
92 | | - array( 'ORDER BY' => 'tmp_id' ) |
93 | | - ); |
| 103 | + function showList() { |
| 104 | + global $wgOut, $wgTitle, $wgUser, $wgRequest; |
94 | 105 | |
95 | | - $templates = array(); |
96 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
97 | | - array_push( $templates, $row->tmp_name ); |
98 | | - } |
99 | | - |
100 | | - return $templates; |
101 | | - } |
102 | | - |
103 | | - function listTemplates() { |
104 | 106 | $templates = $this->queryTemplates(); |
105 | | - return $this->templatesForm( $templates ); |
106 | | - } |
107 | | - |
108 | | - function templatesForm( $templates ) { |
109 | | - global $wgOut, $wgTitle, $wgUser; |
110 | 107 | |
111 | 108 | // Templates |
112 | 109 | $templates = $this->queryTemplates(); |
— | — | @@ -117,54 +114,54 @@ |
118 | 115 | ) |
119 | 116 | ); |
120 | 117 | $htmlOut .= Xml::fieldset( 'Available Templates' ); |
121 | | - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ) ; |
122 | | - $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-template-name' ) ); |
123 | | - $htmlOut .= Xml::element( 'th' ); |
124 | | - $htmlOut .= Xml::element( 'th' ); |
125 | | - $htmlOut .= Xml::element( 'th', null, wfMsg ( 'centralnotice-remove' ) ); |
| 118 | + $htmlOut .= Xml::openElement( 'table', |
| 119 | + array( |
| 120 | + 'cellpadding' => 9, |
| 121 | + 'width' => '100%' |
| 122 | + ) |
| 123 | + ) ; |
| 124 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 125 | + wfMsg ( 'centralnotice-remove' ) |
| 126 | + ); |
| 127 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ), |
| 128 | + wfMsg ( 'centralnotice-template-name' ) |
| 129 | + ); |
126 | 130 | |
127 | 131 | $msgConfirmDelete = wfMsgHTML( 'centralnotice-confirm-delete' ); |
128 | 132 | foreach ( $templates as $templateName ) { |
129 | | - $templateTitle = Title::newFromText( "MediaWiki:Centralnotice-template-{$templateName}" ); |
130 | | - $translateTitle = Title::newFromText( 'Special:NoticeTranslate' ); |
131 | | - $templatePage = SpecialPage::getTitleFor( 'NoticeTemplate/preview' ); |
132 | | - $htmlOut .= Xml::tags( 'tr', null, |
133 | | - Xml::tags( 'td', null, |
134 | | - Xml::element( 'a', |
135 | | - array( |
136 | | - 'href' => $templatePage->getFullUrl( "template=$templateName" ) |
137 | | - ), |
138 | | - $templateName |
139 | | - ) |
| 133 | + $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate/view' ); |
| 134 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 135 | + |
| 136 | + // Remove box |
| 137 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 138 | + Xml::check( 'removeTemplates[]', false, |
| 139 | + array( |
| 140 | + 'value' => $templateName, |
| 141 | + 'onchange' => "if(this.checked){this.checked=confirm('{$msgConfirmDelete}')}" |
| 142 | + ) |
| 143 | + ) |
| 144 | + ); |
| 145 | + |
| 146 | + // Link and Preview |
| 147 | + $render = new SpecialNoticeText(); |
| 148 | + $render->project = 'wikipedia'; |
| 149 | + $render->language = $wgRequest->getVal( 'wpUserLanguage' ); |
| 150 | + $htmlOut .= Xml::tags( 'td', null, |
| 151 | + Xml::element( 'a', |
| 152 | + array( |
| 153 | + 'href' => $viewPage->getFullUrl( "template=$templateName" ) |
| 154 | + ), |
| 155 | + $templateName |
140 | 156 | ) . |
141 | | - Xml::tags( 'td' , null, |
142 | | - Xml::element( 'a', |
143 | | - array( |
144 | | - 'href' => $templateTitle->getEditURL(), |
145 | | - ), |
146 | | - wfMsg ( 'centralnotice-edit' ) |
147 | | - ) |
148 | | - ) . |
149 | | - Xml::tags( 'td', null, |
150 | | - Xml::element( 'a', |
151 | | - array( |
152 | | - 'href' => $translateTitle->getFullURL( "template={$templateName}" ), |
153 | | - ), |
154 | | - wfMsg ( 'centralnotice-translate' ) |
155 | | - ) |
156 | | - ) . |
157 | | - Xml::tags( 'td', null, |
158 | | - Xml::check( 'removeTemplates[]', false, |
159 | | - array( |
160 | | - 'value' => $templateName, |
161 | | - 'onchange' => "if(this.checked){this.checked=confirm('{$msgConfirmDelete}')}" |
162 | | - ) |
163 | | - ) |
164 | | - ) |
| 157 | + Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
| 158 | + $render->getHtmlNotice( $templateName ) |
| 159 | + ) |
165 | 160 | ); |
| 161 | + |
| 162 | + $htmlOut .= Xml::closeElement( 'tr' ); |
166 | 163 | } |
167 | 164 | $htmlOut .= Xml::tags( 'tr', null, |
168 | | - Xml::tags( 'td', null, |
| 165 | + Xml::tags( 'td', array( 'colspan' => 3 ), |
169 | 166 | Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
170 | 167 | ) |
171 | 168 | ); |
— | — | @@ -177,13 +174,24 @@ |
178 | 175 | $htmlOut .= XML::closeElement( 'fieldset' ); |
179 | 176 | $htmlOut .= XML::closeElement( 'form' ); |
180 | 177 | |
181 | | - // Notices |
182 | | - $htmlOut .= Xml::openElement( 'form', |
183 | | - array( |
184 | | - 'method' => 'post', |
185 | | - 'action' => SpecialPage::getTitleFor( 'NoticeTemplate' )->getFullUrl() |
186 | | - ) |
| 178 | + // Show add link |
| 179 | + $newPage = SpecialPage::getTitleFor( 'NoticeTemplate/add' ); |
| 180 | + $htmlOut .= Xml::element( 'a', |
| 181 | + array( |
| 182 | + 'href' => $newPage->getFullUrl() |
| 183 | + ), |
| 184 | + wfMsg( 'centralnotice-add-template' ) |
187 | 185 | ); |
| 186 | + |
| 187 | + // Output HTML |
| 188 | + $wgOut->addHtml( $htmlOut ); |
| 189 | + } |
| 190 | + |
| 191 | + function showAdd() { |
| 192 | + global $wgOut, $wgTitle, $wgUser; |
| 193 | + |
| 194 | + // Build HTML |
| 195 | + $htmlOut = Xml::openElement( 'form', array( 'method' => 'post' ) ); |
188 | 196 | $htmlOut .= Xml::openElement( 'fieldset' ); |
189 | 197 | $htmlOut .= Xml::element( 'legend', null, wfMsg( 'centralnotice-add-template' ) ); |
190 | 198 | $htmlOut .= Xml::hidden( 'wpMethod', 'addTemplate' ); |
— | — | @@ -208,46 +216,219 @@ |
209 | 217 | $wgOut->addHtml( $htmlOut ); |
210 | 218 | } |
211 | 219 | |
212 | | - function listTemplateDetail ( $template ) { |
213 | | - global $wgOut, $wgUser; |
| 220 | + private function showView() { |
| 221 | + global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode; |
214 | 222 | |
| 223 | + // Get token |
| 224 | + $token = $wgUser->editToken(); |
| 225 | + |
| 226 | + // Get user's language |
| 227 | + $wpUserLang = $wgRequest->getVal('wpUserLanguage') ? $wgRequest->getVal('wpUserLanguage') : $wgContLanguageCode; |
| 228 | + |
| 229 | + // Get current template |
| 230 | + $currentTemplate = $wgRequest->getText( 'template' ); |
| 231 | + |
| 232 | + // Show preview |
| 233 | + $render = new SpecialNoticeText(); |
| 234 | + $render->project = 'wikipedia'; |
| 235 | + $render->language = $wgRequest->getVal( 'wpUserLanguage' ); |
| 236 | + $htmlOut = Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
| 237 | + $render->getHtmlNotice( $wgRequest->getText( 'template' ) ) |
| 238 | + ); |
| 239 | + |
| 240 | + // Build HTML |
| 241 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 242 | + $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-translate-heading', $currentTemplate ) ); |
| 243 | + $htmlOut .= Xml::openElement( 'table', |
| 244 | + array ( |
| 245 | + 'cellpadding' => 9, |
| 246 | + 'width' => '100%' |
| 247 | + ) |
| 248 | + ); |
| 249 | + |
| 250 | + // Headers |
| 251 | + $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) ); |
| 252 | + $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses') ); |
| 253 | + $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english') ); |
| 254 | + $languages = Language::getLanguageNames(); |
| 255 | + $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), $languages[$wpUserLang] ); |
| 256 | + |
| 257 | + $body = wfMsg( "Centralnotice-template-{$currentTemplate}" ); |
| 258 | + |
| 259 | + // Generate fields from parsing the body |
| 260 | + $fields = array(); |
| 261 | + preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields ); |
| 262 | + |
| 263 | + // Remove duplicates |
| 264 | + $filteredFields = array(); |
| 265 | + foreach( $fields[1] as $field ) { |
| 266 | + $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1; |
| 267 | + } |
| 268 | + |
| 269 | + // Rows |
| 270 | + foreach( $filteredFields as $field => $count ) { |
| 271 | + // Message |
| 272 | + $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}"; |
| 273 | + |
| 274 | + // English value |
| 275 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 276 | + |
| 277 | + $title = Title::newFromText( "MediaWiki:{$message}" ); |
| 278 | + $htmlOut .= Xml::tags( 'td', null, |
| 279 | + Xml::element( 'a', array( 'href' => $title->getFullURL() ), $field ) |
| 280 | + ); |
| 281 | + |
| 282 | + $htmlOut .= Xml::element( 'td', null, $count); |
| 283 | + |
| 284 | + $htmlOut .= Xml::element( 'td', null, |
| 285 | + wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}", array( 'language' => 'en') ) |
| 286 | + ); |
| 287 | + |
| 288 | + // Input |
| 289 | + $text = ''; |
| 290 | + if( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) { |
| 291 | + $text = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}", |
| 292 | + array( 'language' => $wpUserLang ) |
| 293 | + ); |
| 294 | + } |
| 295 | + $htmlOut .= Xml::tags( 'td', null, |
| 296 | + Xml::input( "updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $text, |
| 297 | + array( 'style' => 'width:100%;' . ( $text == '' ? 'color:red' : '' ) ) |
| 298 | + ) |
| 299 | + ); |
| 300 | + |
| 301 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 302 | + } |
| 303 | + $htmlOut .= Xml::hidden( 'token', $token ); |
| 304 | + $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang ); |
| 305 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 306 | + $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ), |
| 307 | + Xml::submitButton( wfMsg('centralnotice-modify', array( 'name' => 'update') ) ) |
| 308 | + ); |
| 309 | + |
| 310 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 311 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 312 | + $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 313 | + $htmlOut .= Xml::closeElement( 'form' ); |
| 314 | + |
215 | 315 | /* |
216 | | - * What is this supposed to be? |
217 | | - * |
218 | | - $form .= 'Preview'; |
219 | | - $form .= 'Template'; |
220 | | - $form .= 'Button'; |
221 | | - $form .= 'Link'; |
| 316 | + * Show language selection form |
222 | 317 | */ |
| 318 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 319 | + $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-change-lang' ) ); |
| 320 | + $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
| 321 | + list( $lsLabel, $lsSelect) = Xml::languageSelector( $wpUserLang ); |
| 322 | + $htmlOut .= Xml::tags( 'tr', null, |
| 323 | + Xml::tags( 'td', null, $lsLabel ) . |
| 324 | + Xml::tags( 'td', null, $lsSelect ) . |
| 325 | + Xml::tags( 'td', array( 'colspan' => 2 ), |
| 326 | + Xml::submitButton( wfMsgHtml('centralnotice-modify') ) |
| 327 | + ) |
| 328 | + ); |
| 329 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 330 | + $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 331 | + $htmlOut .= Xml::closeElement( 'form' ); |
223 | 332 | |
224 | | - if ( $wgUser->isAllowed( 'centralnotice-template-edit' ) ) { |
225 | | - $form .= Xml::tags( 'tr', null, |
226 | | - Xml::tags( 'td', null, |
227 | | - Xml::submitButton( |
228 | | - wfMsgHtml( 'centralnotice-modify' ), |
229 | | - array( |
230 | | - 'id' => 'centralnoticesubmit', |
231 | | - 'name' => 'centralnoticesubmit' |
232 | | - ) |
233 | | - ) |
234 | | - ) |
| 333 | + /* |
| 334 | + * Show edit form |
| 335 | + */ |
| 336 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 337 | + $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-edit-template' ) ); |
| 338 | + $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
| 339 | + $htmlOut .= Xml::openElement( 'table', |
| 340 | + array( |
| 341 | + 'cellpadding' => 9, |
| 342 | + 'width' => '100%' |
| 343 | + ) |
| 344 | + ); |
| 345 | + $htmlOut .= Xml::tags( 'tr', null, |
| 346 | + Xml::tags( 'td', null, Xml::textarea( 'templateBody', $body, 60, 20 ) ) |
| 347 | + ); |
| 348 | + $htmlOut .= Xml::tags( 'tr', null, |
| 349 | + Xml::tags( 'td', null, Xml::submitButton( wfMsgHtml('centralnotice-modify') ) ) |
| 350 | + ); |
| 351 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 352 | + $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 353 | + $htmlOut .= Xml::closeElement( 'form' ); |
| 354 | + |
| 355 | + // Output HTML |
| 356 | + $wgOut->addHTML( $htmlOut ); |
| 357 | + } |
| 358 | + |
| 359 | + private function updateMessage( $text, $translation, $lang, $token ) { |
| 360 | + global $wgUser; |
| 361 | + |
| 362 | + $title = Title::newFromText( |
| 363 | + ( $lang == 'en' ) ? "Centralnotice-{$text}" : "Centralnotice-{$text}/{$lang}", |
| 364 | + NS_MEDIAWIKI |
| 365 | + ); |
| 366 | + $article = new Article( $title ); |
| 367 | + $article->doEdit( $translation, '' ); |
| 368 | + } |
| 369 | + |
| 370 | + static function queryTemplates() { |
| 371 | + $dbr = wfGetDB( DB_SLAVE ); |
| 372 | + $res = $dbr->select( 'cn_templates', |
| 373 | + array( 'tmp_name', 'tmp_id' ), |
| 374 | + '', |
| 375 | + __METHOD__, |
| 376 | + array( 'ORDER BY' => 'tmp_id' ) |
| 377 | + ); |
| 378 | + |
| 379 | + $templates = array(); |
| 380 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 381 | + array_push( $templates, $row->tmp_name ); |
| 382 | + } |
| 383 | + |
| 384 | + return $templates; |
| 385 | + } |
| 386 | + |
| 387 | + private function getTemplateId ( $templateName ) { |
| 388 | + global $wgOut, $egCentralNoticeTables; |
| 389 | + |
| 390 | + $dbr = wfGetDB( DB_SLAVE ); |
| 391 | + $res = $dbr->select( 'cn_templates', 'tmp_id', |
| 392 | + array( 'tmp_name' => $templateName ), |
| 393 | + __METHOD__ |
| 394 | + ); |
| 395 | + |
| 396 | + $row = $dbr->fetchObject( $res ); |
| 397 | + if( $row ) { |
| 398 | + return $row->tmp_id; |
| 399 | + } |
| 400 | + return null; |
| 401 | + } |
| 402 | + |
| 403 | + private function removeTemplate ( $name ) { |
| 404 | + global $wgOut, $egCentralNoticeTables; |
| 405 | + |
| 406 | + if ( $name == '' ) { |
| 407 | + $wgOut->addHtml( wfMsg( 'centralnotice-template-doesnt-exist' ) ); |
| 408 | + return; |
| 409 | + } |
| 410 | + |
| 411 | + $id = $this->getTemplateId( $name ); |
| 412 | + $dbr = wfGetDB( DB_SLAVE ); |
| 413 | + $res = $dbr->select( 'cn_assignments', 'asn_id', array( 'tmp_id' => $id ), __METHOD__ ); |
| 414 | + |
| 415 | + if ( $dbr->numRows( $res ) > 0 ) { |
| 416 | + $wgOut->addHtml( wfMsg( 'centralnotice-template-still-bound' ) ); |
| 417 | + return; |
| 418 | + } else { |
| 419 | + $dbw = wfGetDB( DB_MASTER ); |
| 420 | + $res = $dbw->delete( 'cn_templates', |
| 421 | + array( 'tmp_id' => $id ), |
| 422 | + __METHOD__ |
235 | 423 | ); |
236 | | - $form .= Xml::tags( 'tr', null, |
237 | | - Xml::tags( 'td', null, |
238 | | - Xml::submitButton( |
239 | | - wfMsgHtml( 'centralnotice-preview' ), |
240 | | - array( |
241 | | - 'id' => 'centralnoticepreview', |
242 | | - 'name' => 'centralnoticepreview' |
243 | | - ) |
244 | | - ) |
245 | | - ) |
| 424 | + |
| 425 | + $article = new Article( |
| 426 | + Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
246 | 427 | ); |
| 428 | + $article->doDelete( 'CentralNotice Automated Removal', true ); |
247 | 429 | } |
248 | | - $wgOut->addHTML( $form ); |
249 | 430 | } |
250 | 431 | |
251 | | - function addTemplate ( $name, $body ) { |
| 432 | + private function addTemplate ( $name, $body ) { |
252 | 433 | global $wgOut, $egCentralNoticeTables; |
253 | 434 | |
254 | 435 | if ( $body == '' || $name == '' ) { |
— | — | @@ -284,81 +465,30 @@ |
285 | 466 | return; |
286 | 467 | } |
287 | 468 | } |
288 | | - |
289 | | - function removeTemplate ( $templateName ) { |
| 469 | + |
| 470 | + private function editTemplate ( $name, $body ) { |
290 | 471 | global $wgOut, $egCentralNoticeTables; |
291 | | - |
292 | | - if ( $templateName == '' ) { |
293 | | - $wgOut->addHtml( wfMsg( 'centralnotice-template-doesnt-exist' ) ); |
| 472 | + |
| 473 | + if ( $body == '' || $name == '' ) { |
| 474 | + $wgOut->addHtml( wfMsg( 'centralnotice-null-string' ) ); |
294 | 475 | return; |
295 | 476 | } |
296 | 477 | |
297 | | - $templateId = $this->getTemplateId( $templateName ); |
298 | 478 | $dbr = wfGetDB( DB_SLAVE ); |
299 | | - $res = $dbr->select( 'cn_assignments', 'asn_id', |
300 | | - array( 'tmp_id' => $templateId ), |
| 479 | + $res = $dbr->select( 'cn_templates', 'tmp_name', |
| 480 | + array( 'tmp_name' => $name ), |
301 | 481 | __METHOD__ |
302 | 482 | ); |
303 | 483 | |
304 | | - if ( $dbr->numRows( $res ) > 0 ) { |
305 | | - $wgOut->addHtml( wfMsg( 'centralnotice-template-still-bound' ) ); |
| 484 | + if ( $dbr->numRows( $res ) > 0 ) { |
| 485 | + /* |
| 486 | + * Perhaps these should move into the db as blob |
| 487 | + */ |
| 488 | + $article = new Article( |
| 489 | + Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
| 490 | + ); |
| 491 | + $article->doEdit( $body, '' ); |
306 | 492 | return; |
307 | | - } else { |
308 | | - $dbw = wfGetDB( DB_MASTER ); |
309 | | - $res = $dbw->delete( 'cn_templates', |
310 | | - array( 'tmp_id' => $templateId ), |
311 | | - __METHOD__ |
312 | | - ); |
313 | 493 | } |
314 | 494 | } |
315 | | - |
316 | | - function getTemplateId ( $templateName ) { |
317 | | - global $wgOut, $egCentralNoticeTables; |
318 | | - |
319 | | - $dbr = wfGetDB( DB_SLAVE ); |
320 | | - $res = $dbr->select( 'cn_templates', 'tmp_id', |
321 | | - array( 'tmp_name' => $templateName ), |
322 | | - __METHOD__ |
323 | | - ); |
324 | | - |
325 | | - $row = $dbr->fetchObject( $res ); |
326 | | - if( $row ) { |
327 | | - return $row->tmp_id; |
328 | | - } |
329 | | - return null; |
330 | | - } |
331 | | - |
332 | | - public static function previewTemplate ( $template, $userLang ) { |
333 | | - $render = new SpecialNoticeText(); |
334 | | - $render->project = 'wikipedia'; |
335 | | - $render->language = $userLang; |
336 | | - $htmlOut = Xml::fieldset( wfMsg( 'centralnotice-preview' ), |
337 | | - $render->getHtmlNotice( $template ) |
338 | | - ); |
339 | | - $htmlOut .= Xml::openElement( 'form', |
340 | | - array ( |
341 | | - 'method' => 'post', |
342 | | - 'action' => SpecialPage::getTitleFor( 'NoticeTemplate','preview' )->getLocalUrl( "template=$template") |
343 | | - ) |
344 | | - ); |
345 | | - list( $lsLabel, $lsSelect) = Xml::languageSelector( $userLang ); |
346 | | - $htmlOut .= Xml::tags( 'tr', null, |
347 | | - Xml::tags( 'td', null, $lsLabel ) . |
348 | | - Xml::tags( 'td', null, $lsSelect ) |
349 | | - ); |
350 | | - $htmlOut .= Xml::tags( 'tr', null, |
351 | | - Xml::tags( 'td', null, |
352 | | - Xml::submitButton( wfMsgHtml('centralnotice-modify'), |
353 | | - array( |
354 | | - 'id' => 'centralnoticesubmit', |
355 | | - 'name' => 'centralnoticesubmit' |
356 | | - ) |
357 | | - ) |
358 | | - ) |
359 | | - ); |
360 | | - $htmlOut .= Xml::closeElement( 'form'); |
361 | | - |
362 | | - return $htmlOut; |
363 | | - |
364 | | - } |
365 | 495 | } |
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.i18n.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | 'centralnotice-locked' => 'Locked', |
40 | 40 | 'centralnotice-notices' => 'Notices', |
41 | 41 | 'centralnotice-notice-exists' => 'Notice already exists. Not adding', |
| 42 | + 'centralnotice-template-exists' => 'Template already exists. Not adding', |
42 | 43 | 'centralnotice-notice-doesnt-exist' => 'Notice doesnt exist. Nothing to remove', |
43 | 44 | 'centralnotice-template-still-bound' => 'Template is still bound to a notice. Not removing.', |
44 | 45 | 'centralnotice-template-body' => 'Template Body: ', |
— | — | @@ -67,7 +68,7 @@ |
68 | 69 | 'centralnotice-no-templates-translate' => 'There are not any templates to edit translations for', |
69 | 70 | 'centralnotice-no-templates' => 'There are no templates in the system. Create one', |
70 | 71 | 'centralnotice-number-uses' => 'Uses', |
71 | | - 'centralnotice-edit' => 'Edit', |
| 72 | + 'centralnotice-edit-template' => 'Edit Template', |
72 | 73 | 'centralnotice-message' => 'Message', |
73 | 74 | ); |
74 | 75 | |