Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -18,7 +18,10 @@ |
19 | 19 | |
20 | 20 | $this->centralNoticeDB = new CentralNoticeDB(); |
21 | 21 | } |
22 | | - |
| 22 | + |
| 23 | + /** |
| 24 | + * Handle different types of page requests |
| 25 | + */ |
23 | 26 | function execute( $sub ) { |
24 | 27 | global $wgOut, $wgUser, $wgRequest, $wgScriptPath; |
25 | 28 | |
— | — | @@ -44,27 +47,27 @@ |
45 | 48 | // Handle form sumissions |
46 | 49 | if ( $this->editable && $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
47 | 50 | |
48 | | - // Handle removing |
| 51 | + // Handle removing campaigns |
49 | 52 | $toRemove = $wgRequest->getArray( 'removeNotices' ); |
50 | 53 | if ( isset( $toRemove ) ) { |
51 | | - // Remove notices in list |
52 | | - foreach ( $toRemove as $template ) { |
53 | | - $this->removeNotice( $template ); |
| 54 | + // Remove campaigns in list |
| 55 | + foreach ( $toRemove as $notice ) { |
| 56 | + $this->removeNotice( $notice ); |
54 | 57 | } |
55 | 58 | |
56 | | - // Show list of notices |
| 59 | + // Show list of campaigns |
57 | 60 | $this->listNotices(); |
58 | 61 | return; |
59 | 62 | } |
60 | 63 | |
61 | | - // Handle locking/unlocking |
| 64 | + // Handle locking/unlocking campaigns |
62 | 65 | $lockedNotices = $wgRequest->getArray( 'locked' ); |
63 | 66 | if ( isset( $lockedNotices ) ) { |
64 | 67 | if ( $method == 'listNoticeDetail' ) { |
65 | 68 | $notice = $wgRequest->getVal ( 'notice' ); |
66 | 69 | $this->updateLock( $notice, '1' ); |
67 | 70 | } else { |
68 | | - // Build list of notices to lock |
| 71 | + // Build list of campaigns to lock |
69 | 72 | $unlockedNotices = array_diff( $this->getNoticesName(), $lockedNotices ); |
70 | 73 | |
71 | 74 | // Set locked/unlocked flag accordingly |
— | — | @@ -77,14 +80,14 @@ |
78 | 81 | } |
79 | 82 | } |
80 | 83 | |
81 | | - // Handle enabling/disabling |
| 84 | + // Handle enabling/disabling campaigns |
82 | 85 | $enabledNotices = $wgRequest->getArray( 'enabled' ); |
83 | 86 | if ( isset( $enabledNotices ) ) { |
84 | 87 | if ( $method == 'listNoticeDetail' ) { |
85 | 88 | $notice = $wgRequest->getVal ( 'notice' ); |
86 | 89 | $this->updateEnabled( $notice, '1' ); |
87 | 90 | } else { |
88 | | - // Build list of notices to disable |
| 91 | + // Build list of campaigns to disable |
89 | 92 | $disabledNotices = array_diff( $this->getNoticesName(), $enabledNotices ); |
90 | 93 | |
91 | 94 | // Set enabled/disabled flag accordingly |
— | — | @@ -97,7 +100,7 @@ |
98 | 101 | } |
99 | 102 | } |
100 | 103 | |
101 | | - // Handle setting preferred |
| 104 | + // Handle setting preferred campaigns |
102 | 105 | $preferredNotices = $wgRequest->getArray( 'preferred' ); |
103 | 106 | if ( isset( $preferredNotices ) ) { |
104 | 107 | // Set since this is a single display |
— | — | @@ -106,7 +109,7 @@ |
107 | 110 | $this->centralNoticeDB->updatePreferred( $notice, '1' ); |
108 | 111 | } |
109 | 112 | else { |
110 | | - // Build list of notices to unset |
| 113 | + // Build list of campaigns to unset |
111 | 114 | $unsetNotices = array_diff( $this->getNoticesName(), $preferredNotices ); |
112 | 115 | |
113 | 116 | // Set flag accordingly |
— | — | @@ -174,6 +177,7 @@ |
175 | 178 | } |
176 | 179 | } |
177 | 180 | } |
| 181 | + |
178 | 182 | // Handle weight change |
179 | 183 | $updatedWeights = $wgRequest->getArray( 'weight' ); |
180 | 184 | if ( isset( $updatedWeights ) ) { |
— | — | @@ -183,7 +187,7 @@ |
184 | 188 | } |
185 | 189 | } |
186 | 190 | |
187 | | - // Handle adding of notice |
| 191 | + // Handle adding of campaign |
188 | 192 | $this->showAll = $wgRequest->getVal( 'showAll' ); |
189 | 193 | if ( $this->editable && $method == 'addNotice' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
190 | 194 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
— | — | @@ -197,13 +201,13 @@ |
198 | 202 | } |
199 | 203 | } |
200 | 204 | |
201 | | - // Handle removing of notice |
| 205 | + // Handle removing of campaign |
202 | 206 | if ( $this->editable && $method == 'removeNotice' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
203 | 207 | $noticeName = $wgRequest->getVal ( 'noticeName' ); |
204 | 208 | $this->removeNotice ( $noticeName ); |
205 | 209 | } |
206 | 210 | |
207 | | - // Handle adding of template |
| 211 | + // Handle adding a banner to a campaign |
208 | 212 | if ( $this->editable && $method == 'addTemplateTo' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
209 | 213 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
210 | 214 | $templateName = $wgRequest->getVal( 'templateName' ); |
— | — | @@ -214,14 +218,14 @@ |
215 | 219 | return; |
216 | 220 | } |
217 | 221 | |
218 | | - // Handle removing of template |
| 222 | + // Handle removing a banner from a campaign |
219 | 223 | if ( $this->editable && $method == 'removeTemplateFor' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
220 | 224 | $noticeName = $wgRequest->getVal ( 'noticeName' ); |
221 | 225 | $templateName = $wgRequest->getVal ( 'templateName ' ); |
222 | 226 | $this->removeTemplateFor( $noticeName , $templateName ); |
223 | 227 | } |
224 | 228 | |
225 | | - // Handle showing detail |
| 229 | + // Handle showing campaign detail |
226 | 230 | if ( $method == 'listNoticeDetail' ) { |
227 | 231 | $notice = $wgRequest->getVal ( 'notice' ); |
228 | 232 | $this->listNoticeDetail( $notice ); |
— | — | @@ -229,14 +233,16 @@ |
230 | 234 | return; |
231 | 235 | } |
232 | 236 | |
233 | | - // Show list of notices |
| 237 | + // Show list of campaigns |
234 | 238 | $this->listNotices(); |
235 | 239 | |
236 | 240 | // End Campaigns tab content |
237 | 241 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
238 | 242 | } |
239 | 243 | |
240 | | - // Update the enabled/disabled state of notice |
| 244 | + /** |
| 245 | + * Update the enabled/disabled state of a campaign |
| 246 | + */ |
241 | 247 | private function updateEnabled( $notice, $state ) { |
242 | 248 | $dbw = wfGetDB( DB_MASTER ); |
243 | 249 | $dbw->begin(); |
— | — | @@ -349,12 +355,9 @@ |
350 | 356 | return $out; |
351 | 357 | } |
352 | 358 | |
353 | | - /* |
354 | | - * listNotices |
355 | | - * |
| 359 | + /** |
356 | 360 | * Print out all campaigns found in db |
357 | 361 | */ |
358 | | - |
359 | 362 | function listNotices() { |
360 | 363 | global $wgOut, $wgUser, $wgUserLang; |
361 | 364 | |
— | — | @@ -367,14 +370,12 @@ |
368 | 371 | $readonly = array( 'disabled' => 'disabled' ); |
369 | 372 | } |
370 | 373 | |
371 | | - /* |
372 | | - * This is temporarily hard-coded |
373 | | - */ |
| 374 | + // This is temporarily hard-coded |
374 | 375 | $this->showAll = 'Y'; |
375 | 376 | |
376 | 377 | // If all languages should be shown |
377 | 378 | if ( isset( $this->showAll ) ) { |
378 | | - // Get notices for all languages |
| 379 | + // Get campaigns for all languages |
379 | 380 | $res = $dbr->select( 'cn_notices', |
380 | 381 | array( |
381 | 382 | 'not_name', |
— | — | @@ -390,7 +391,7 @@ |
391 | 392 | array( 'ORDER BY' => 'not_id' ) |
392 | 393 | ); |
393 | 394 | } else { |
394 | | - // Get only notices for this language |
| 395 | + // Get only campaigns for this language |
395 | 396 | $res = $dbr->select( 'cn_notices', |
396 | 397 | array( |
397 | 398 | 'not_name', |
— | — | @@ -413,7 +414,7 @@ |
414 | 415 | // Begin Manage campaigns fieldset |
415 | 416 | $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
416 | 417 | |
417 | | - // If there are notices to show... |
| 418 | + // If there are campaigns to show... |
418 | 419 | if ( $dbr->numRows( $res ) >= 1 ) { |
419 | 420 | if ( $this->editable ) { |
420 | 421 | $htmlOut .= Xml::openElement( 'form', |
— | — | @@ -425,6 +426,7 @@ |
426 | 427 | } |
427 | 428 | $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage' ) ); |
428 | 429 | |
| 430 | + // Begin table of campaigns |
429 | 431 | $htmlOut .= Xml::openElement( 'table', |
430 | 432 | array( |
431 | 433 | 'cellpadding' => 9, |
— | — | @@ -433,7 +435,7 @@ |
434 | 436 | ) |
435 | 437 | ); |
436 | 438 | |
437 | | - // Headers |
| 439 | + // Table headers |
438 | 440 | $headers = array( |
439 | 441 | wfMsgHtml( 'centralnotice-notice-name' ), |
440 | 442 | wfMsgHtml( 'centralnotice-project-name' ), |
— | — | @@ -449,7 +451,7 @@ |
450 | 452 | } |
451 | 453 | $htmlOut .= $this->tableRow( $headers, 'th' ); |
452 | 454 | |
453 | | - // Rows |
| 455 | + // Table rows |
454 | 456 | while ( $row = $dbr->fetchObject( $res ) ) { |
455 | 457 | $fields = array(); |
456 | 458 | |
— | — | @@ -517,9 +519,11 @@ |
518 | 520 | |
519 | 521 | $htmlOut .= $this->tableRow( $fields ); |
520 | 522 | } |
| 523 | + // End table of campaigns |
521 | 524 | $htmlOut .= Xml::closeElement( 'table' ); |
522 | | - $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() ); |
| 525 | + |
523 | 526 | if ( $this->editable ) { |
| 527 | + $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() ); |
524 | 528 | $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-buttons' ) ); |
525 | 529 | $htmlOut .= Xml::submitButton( wfMsg( 'centralnotice-modify' ), |
526 | 530 | array( |
— | — | @@ -531,7 +535,7 @@ |
532 | 536 | $htmlOut .= Xml::closeElement( 'form' ); |
533 | 537 | } |
534 | 538 | |
535 | | - // No notices to show |
| 539 | + // No campaigns to show |
536 | 540 | } else { |
537 | 541 | $htmlOut .= wfMsg( 'centralnotice-no-notices-exist' ); |
538 | 542 | } |
— | — | @@ -544,7 +548,7 @@ |
545 | 549 | // Begin Add a campaign fieldset |
546 | 550 | $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
547 | 551 | |
548 | | - // Notice Adding |
| 552 | + // Form for adding a campaign |
549 | 553 | $htmlOut .= Xml::openElement( 'form', |
550 | 554 | array( |
551 | 555 | 'method' => 'post', |
— | — | @@ -606,7 +610,7 @@ |
607 | 611 | global $wgOut, $wgRequest, $wgUser; |
608 | 612 | if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
609 | 613 | |
610 | | - // Handle removing of templates |
| 614 | + // Handle removing of banners from the campaign |
611 | 615 | $templateToRemove = $wgRequest->getArray( 'removeTemplates' ); |
612 | 616 | if ( isset( $templateToRemove ) ) { |
613 | 617 | foreach ( $templateToRemove as $template ) { |
— | — | @@ -626,7 +630,7 @@ |
627 | 631 | $this->updateProjectLanguages( $notice, $projectLangs ); |
628 | 632 | } |
629 | 633 | |
630 | | - // Handle adding of templates |
| 634 | + // Handle adding of banners to the campaign |
631 | 635 | $templatesToAdd = $wgRequest->getArray( 'addTemplates' ); |
632 | 636 | if ( isset( $templatesToAdd ) ) { |
633 | 637 | $weight = $wgRequest->getArray( 'weight' ); |
— | — | @@ -652,9 +656,7 @@ |
653 | 657 | ); |
654 | 658 | } |
655 | 659 | |
656 | | - /* |
657 | | - * Temporarily hard coded |
658 | | - */ |
| 660 | + // Temporarily hard coded |
659 | 661 | $this->showAll = 'Y'; |
660 | 662 | |
661 | 663 | $output_detail = $this->noticeDetailForm( $notice ); |
— | — | @@ -662,12 +664,12 @@ |
663 | 665 | $output_templates = $this->addTemplatesForm( $notice ); |
664 | 666 | |
665 | 667 | if ( $output_detail == '' ) { |
666 | | - // Notice not found |
| 668 | + // Campaign not found |
667 | 669 | $htmlOut .= Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-notice-doesnt-exist' ) ); |
668 | 670 | } else { |
669 | 671 | $htmlOut .= $output_detail; |
670 | 672 | |
671 | | - // Catch for no templates so that we don't double message |
| 673 | + // Catch for no banners so that we don't double message |
672 | 674 | if ( $output_assigned == '' && $output_templates == '' ) { |
673 | 675 | $htmlOut .= wfMsg( 'centralnotice-no-templates' ); |
674 | 676 | $htmlOut .= Xml::element( 'p' ); |
— | — | @@ -705,7 +707,10 @@ |
706 | 708 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
707 | 709 | $wgOut->addHTML( $htmlOut ); |
708 | 710 | } |
709 | | - |
| 711 | + |
| 712 | + /** |
| 713 | + * Create form for managing campaign settings (start date, end date, languages, etc.) |
| 714 | + */ |
710 | 715 | function noticeDetailForm( $notice ) { |
711 | 716 | if ( $this->editable ) { |
712 | 717 | $readonly = array(); |
— | — | @@ -798,7 +803,9 @@ |
799 | 804 | } |
800 | 805 | } |
801 | 806 | |
802 | | - |
| 807 | + /** |
| 808 | + * Create form for managing banners assigned to a campaign |
| 809 | + */ |
803 | 810 | function assignedTemplatesForm( $notice ) { |
804 | 811 | global $wgUser; |
805 | 812 | $sk = $wgUser->getSkin(); |
— | — | @@ -823,12 +830,12 @@ |
824 | 831 | array( 'ORDER BY' => 'cn_notices.not_id' ) |
825 | 832 | ); |
826 | 833 | |
827 | | - // No templates found |
| 834 | + // No banners found |
828 | 835 | if ( $dbr->numRows( $res ) < 1 ) { |
829 | 836 | return; |
830 | 837 | } |
831 | 838 | |
832 | | - // Build Assigned Template HTML |
| 839 | + // Build Assigned banners HTML |
833 | 840 | $htmlOut = Xml::hidden( 'change', 'weight' ); |
834 | 841 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-assigned-templates' ) ); |
835 | 842 | $htmlOut .= Xml::openElement( 'table', |
— | — | @@ -846,7 +853,7 @@ |
847 | 854 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '70%' ), |
848 | 855 | wfMsg ( "centralnotice-templates" ) ); |
849 | 856 | |
850 | | - // Rows |
| 857 | + // Table rows |
851 | 858 | while ( $row = $dbr->fetchObject( $res ) ) { |
852 | 859 | |
853 | 860 | $htmlOut .= Xml::openElement( 'tr' ); |
— | — | @@ -900,7 +907,9 @@ |
901 | 908 | } |
902 | 909 | } |
903 | 910 | |
904 | | - |
| 911 | + /** |
| 912 | + * Create form for adding banners to a campaign |
| 913 | + */ |
905 | 914 | function addTemplatesForm( $notice ) { |
906 | 915 | global $wgUser; |
907 | 916 | $sk = $wgUser->getSkin(); |
— | — | @@ -989,7 +998,9 @@ |
990 | 999 | return $htmlOut; |
991 | 1000 | } |
992 | 1001 | |
993 | | - |
| 1002 | + /** |
| 1003 | + * Build a list of all the banners assigned to a campaign |
| 1004 | + */ |
994 | 1005 | function selectTemplatesAssigned ( $notice ) { |
995 | 1006 | $dbr = wfGetDB( DB_SLAVE ); |
996 | 1007 | $res = $dbr->select( |
— | — | @@ -1017,8 +1028,8 @@ |
1018 | 1029 | } |
1019 | 1030 | |
1020 | 1031 | /** |
1021 | | - * Lookup function for active notice under a given language and project |
1022 | | - * Returns an array of running template names with associated weights |
| 1032 | + * Lookup function for active campaigns under a given language and project |
| 1033 | + * @return An array of running campaign names with associated banner weights |
1023 | 1034 | */ |
1024 | 1035 | static function selectNoticeTemplates( $project, $language ) { |
1025 | 1036 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -1213,13 +1224,13 @@ |
1214 | 1225 | |
1215 | 1226 | $dbr = wfGetDB( DB_SLAVE ); |
1216 | 1227 | |
1217 | | - // Start / end dont line up |
| 1228 | + // Start/end don't line up |
1218 | 1229 | if ( $start > $end || $end < $start ) { |
1219 | 1230 | $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-invalid-date-range3' ) ) ); |
1220 | 1231 | return; |
1221 | 1232 | } |
1222 | 1233 | |
1223 | | - // Invalid notice name |
| 1234 | + // Invalid campaign name |
1224 | 1235 | $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) ); |
1225 | 1236 | if ( $dbr->numRows( $res ) < 1 ) { |
1226 | 1237 | $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-notice-doesnt-exist' ) ) ); |
— | — | @@ -1306,10 +1317,7 @@ |
1307 | 1318 | global $wgContLanguageCode; |
1308 | 1319 | global $wgScriptPath; |
1309 | 1320 | $scriptPath = "$wgScriptPath/extensions/CentralNotice"; |
1310 | | - /** |
1311 | | - * Make sure the site language is in the list; a custom language code |
1312 | | - * might not have a defined name... |
1313 | | - */ |
| 1321 | + // Make sure the site language is in the list; a custom language code might not have a defined name... |
1314 | 1322 | $languages = Language::getLanguageNames( $customisedOnly ); |
1315 | 1323 | if( !array_key_exists( $wgContLanguageCode, $languages ) ) { |
1316 | 1324 | $languages[$wgContLanguageCode] = $wgContLanguageCode; |
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php |
— | — | @@ -15,8 +15,8 @@ |
16 | 16 | wfLoadExtensionMessages( 'CentralNotice' ); |
17 | 17 | } |
18 | 18 | |
19 | | - /* |
20 | | - * Handle different types of page requests. |
| 19 | + /** |
| 20 | + * Handle different types of page requests |
21 | 21 | */ |
22 | 22 | function execute( $sub ) { |
23 | 23 | global $wgOut, $wgUser, $wgRequest, $wgScriptPath; |
— | — | @@ -43,10 +43,10 @@ |
44 | 44 | // Handle forms |
45 | 45 | if ( $wgRequest->wasPosted() ) { |
46 | 46 | |
47 | | - // Handle removing |
| 47 | + // Handle removing banners |
48 | 48 | $toRemove = $wgRequest->getArray( 'removeTemplates' ); |
49 | 49 | if ( isset( $toRemove ) ) { |
50 | | - // Remove templates in list |
| 50 | + // Remove banners in list |
51 | 51 | foreach ( $toRemove as $template ) { |
52 | 52 | $this->removeTemplate( $template ); |
53 | 53 | } |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | | - // Handle adding |
| 70 | + // Handle adding banner |
71 | 71 | // FIXME: getText()? weak comparison |
72 | 72 | if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) { |
73 | 73 | $this->addTemplate( |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | | - // Handle viewing of a template in all languages |
| 88 | + // Handle viewing of a banner in all languages |
89 | 89 | if ( $sub == 'view' && $wgRequest->getVal( 'wpUserLanguage' ) == 'all' ) { |
90 | 90 | $template = $wgRequest->getVal( 'template' ); |
91 | 91 | $this->showViewAvailable( $template ); |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | | - // Handle viewing a specific template |
| 96 | + // Handle viewing a specific banner |
97 | 97 | if ( $sub == 'view' && $wgRequest->getText( 'template' ) != '' ) { |
98 | 98 | $this->showView(); |
99 | 99 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | return; |
109 | 109 | } |
110 | 110 | |
111 | | - // Handle cloning a specific template |
| 111 | + // Handle cloning a specific banner |
112 | 112 | if ( $sub == 'clone' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
113 | 113 | $oldTemplate = $wgRequest->getVal( 'oldTemplate' ); |
114 | 114 | $newTemplate = $wgRequest->getVal( 'newTemplate' ); |
— | — | @@ -118,15 +118,15 @@ |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | | - // Show list by default |
| 122 | + // Show list of banners by default |
123 | 123 | $this->showList(); |
124 | 124 | |
125 | 125 | // End Banners tab content |
126 | 126 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
127 | 127 | } |
128 | 128 | |
129 | | - /* |
130 | | - * Show a list of available templates. Newer templates are shown first. |
| 129 | + /** |
| 130 | + * Show a list of available banners. Newer banners are shown first. |
131 | 131 | */ |
132 | 132 | function showList() { |
133 | 133 | global $wgOut, $wgUser; |
— | — | @@ -152,6 +152,8 @@ |
153 | 153 | ); |
154 | 154 | } |
155 | 155 | $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage-templates' ) ); |
| 156 | + |
| 157 | + // Show paginated list of banners |
156 | 158 | $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() ); |
157 | 159 | $htmlOut .= $pager->getBody(); |
158 | 160 | $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() ); |
— | — | @@ -172,7 +174,10 @@ |
173 | 175 | |
174 | 176 | $wgOut->addHTML( $htmlOut ); |
175 | 177 | } |
176 | | - |
| 178 | + |
| 179 | + /** |
| 180 | + * Show "Add a banner" interface |
| 181 | + */ |
177 | 182 | function showAdd() { |
178 | 183 | global $wgOut, $wgUser; |
179 | 184 | |
— | — | @@ -207,7 +212,10 @@ |
208 | 213 | // Output HTML |
209 | 214 | $wgOut->addHTML( $htmlOut ); |
210 | 215 | } |
211 | | - |
| 216 | + |
| 217 | + /** |
| 218 | + * View or edit an individual banner |
| 219 | + */ |
212 | 220 | private function showView() { |
213 | 221 | global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode; |
214 | 222 | |
— | — | @@ -221,7 +229,7 @@ |
222 | 230 | // Get user's language |
223 | 231 | $wpUserLang = $wgRequest->getVal( 'wpUserLanguage' ) ? $wgRequest->getVal( 'wpUserLanguage' ) : $wgContLanguageCode; |
224 | 232 | |
225 | | - // Get current template |
| 233 | + // Get current banner |
226 | 234 | $currentTemplate = $wgRequest->getText( 'template' ); |
227 | 235 | |
228 | 236 | // Begin building HTML |
— | — | @@ -232,7 +240,7 @@ |
233 | 241 | |
234 | 242 | $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-template' ) . ': ' . $currentTemplate ); |
235 | 243 | |
236 | | - // Show preview |
| 244 | + // Show preview of banner |
237 | 245 | $render = new SpecialNoticeText(); |
238 | 246 | $render->project = 'wikipedia'; |
239 | 247 | $render->language = $wgRequest->getVal( 'wpUserLanguage' ); |
— | — | @@ -246,16 +254,16 @@ |
247 | 255 | ); |
248 | 256 | } |
249 | 257 | |
250 | | - // Pull text and respect any inc: markup |
| 258 | + // Pull banner text and respect any inc: markup |
251 | 259 | $bodyPage = Title::newFromText( "Centralnotice-template-{$currentTemplate}", NS_MEDIAWIKI ); |
252 | 260 | $curRev = Revision::newFromTitle( $bodyPage ); |
253 | 261 | $body = $curRev ? $curRev->getText() : ''; |
254 | 262 | |
255 | | - // Extract message fields from the template body |
| 263 | + // Extract message fields from the banner body |
256 | 264 | $fields = array(); |
257 | 265 | preg_match_all( '/\{\{\{([A-Za-z0-9\_\-\x{00C0}-\x{017F}]+)\}\}\}/u', $body, $fields ); |
258 | 266 | |
259 | | - // If there are any messages in the template, display translation tools. |
| 267 | + // If there are any message fields in the banner, display translation tools. |
260 | 268 | if ( count( $fields[0] ) > 0 ) { |
261 | 269 | if ( $this->editable ) { |
262 | 270 | $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
— | — | @@ -272,7 +280,7 @@ |
273 | 281 | ) |
274 | 282 | ); |
275 | 283 | |
276 | | - // Headers |
| 284 | + // Table headers |
277 | 285 | $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) ); |
278 | 286 | $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses' ) ); |
279 | 287 | $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english' ) ); |
— | — | @@ -285,7 +293,7 @@ |
286 | 294 | $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1; |
287 | 295 | } |
288 | 296 | |
289 | | - // Rows |
| 297 | + // Table rows |
290 | 298 | foreach ( $filteredFields as $field => $count ) { |
291 | 299 | // Message |
292 | 300 | $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}"; |
— | — | @@ -350,9 +358,7 @@ |
351 | 359 | $htmlOut .= Xml::closeElement( 'form' ); |
352 | 360 | } |
353 | 361 | |
354 | | - /* |
355 | | - * Show language selection form |
356 | | - */ |
| 362 | + // Show language selection form |
357 | 363 | $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
358 | 364 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) ); |
359 | 365 | $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
— | — | @@ -377,9 +383,7 @@ |
378 | 384 | $htmlOut .= Xml::closeElement( 'form' ); |
379 | 385 | } |
380 | 386 | |
381 | | - /* |
382 | | - * Show edit form |
383 | | - */ |
| 387 | + // Show edit form |
384 | 388 | if ( $this->editable ) { |
385 | 389 | $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
386 | 390 | $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
— | — | @@ -408,9 +412,7 @@ |
409 | 413 | $htmlOut .= Xml::closeElement( 'form' ); |
410 | 414 | } |
411 | 415 | |
412 | | - /* |
413 | | - * Show Clone form |
414 | | - */ |
| 416 | + // Show clone form |
415 | 417 | if ( $this->editable ) { |
416 | 418 | $htmlOut .= Xml::openElement ( 'form', |
417 | 419 | array( |
— | — | @@ -439,7 +441,10 @@ |
440 | 442 | // Output HTML |
441 | 443 | $wgOut->addHTML( $htmlOut ); |
442 | 444 | } |
443 | | - |
| 445 | + |
| 446 | + /** |
| 447 | + * Preview all available translations of a banner |
| 448 | + */ |
444 | 449 | public function showViewAvailable( $template ) { |
445 | 450 | global $wgOut, $wgUser; |
446 | 451 | |
— | — | @@ -448,7 +453,7 @@ |
449 | 454 | |
450 | 455 | $sk = $wgUser->getSkin(); |
451 | 456 | |
452 | | - // Pull all available text for a template |
| 457 | + // Pull all available text for a banner |
453 | 458 | $langs = array_keys( $this->getTranslations( $template ) ); |
454 | 459 | $htmlOut = ''; |
455 | 460 | |
— | — | @@ -479,7 +484,10 @@ |
480 | 485 | |
481 | 486 | return $wgOut->addHtml( $htmlOut ); |
482 | 487 | } |
483 | | - |
| 488 | + |
| 489 | + /** |
| 490 | + * Add or update a message |
| 491 | + */ |
484 | 492 | private function updateMessage( $text, $translation, $lang ) { |
485 | 493 | $title = Title::newFromText( |
486 | 494 | ( $lang == 'en' ) ? "Centralnotice-{$text}" : "Centralnotice-{$text}/{$lang}", |
— | — | @@ -536,6 +544,9 @@ |
537 | 545 | } |
538 | 546 | } |
539 | 547 | |
| 548 | + /** |
| 549 | + * Create a new banner |
| 550 | + */ |
540 | 551 | private function addTemplate ( $name, $body ) { |
541 | 552 | global $wgOut; |
542 | 553 | |
— | — | @@ -568,9 +579,7 @@ |
569 | 580 | ); |
570 | 581 | $dbw->commit(); |
571 | 582 | |
572 | | - /* |
573 | | - * Perhaps these should move into the db as blob |
574 | | - */ |
| 583 | + // Perhaps these should move into the db as blob |
575 | 584 | $article = new Article( |
576 | 585 | Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
577 | 586 | ); |
— | — | @@ -579,6 +588,9 @@ |
580 | 589 | } |
581 | 590 | } |
582 | 591 | |
| 592 | + /** |
| 593 | + * Update a banner |
| 594 | + */ |
583 | 595 | private function editTemplate ( $name, $body ) { |
584 | 596 | global $wgOut; |
585 | 597 | |
— | — | @@ -594,9 +606,7 @@ |
595 | 607 | ); |
596 | 608 | |
597 | 609 | if ( $dbr->numRows( $res ) > 0 ) { |
598 | | - /* |
599 | | - * Perhaps these should move into the db as blob |
600 | | - */ |
| 610 | + // Perhaps these should move into the db as blob |
601 | 611 | $article = new Article( |
602 | 612 | Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |
603 | 613 | ); |
— | — | @@ -605,8 +615,8 @@ |
606 | 616 | } |
607 | 617 | } |
608 | 618 | |
609 | | - /* |
610 | | - * Copy all the data from one template to another |
| 619 | + /** |
| 620 | + * Copy all the data from one banner to another |
611 | 621 | */ |
612 | 622 | public function cloneTemplate( $source, $dest ) { |
613 | 623 | // Reset the timer as updates on meta take a long time |
— | — | @@ -633,16 +643,16 @@ |
634 | 644 | } |
635 | 645 | } |
636 | 646 | |
637 | | - /* |
638 | | - * Find all fields set for a template |
| 647 | + /** |
| 648 | + * Find all message fields set for a banner |
639 | 649 | */ |
640 | 650 | private function findFields( $template ) { |
641 | 651 | $messages = array(); |
642 | 652 | $body = wfMsg( "Centralnotice-template-{$template}" ); |
643 | 653 | |
644 | | - // Generate fields from parsing the body |
| 654 | + // Generate list of message fields from parsing the body |
645 | 655 | $fields = array(); |
646 | | - preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields ); |
| 656 | + preg_match_all( '/\{\{\{([A-Za-z0-9\_\-\x{00C0}-\x{017F}]+)\}\}\}/u', $body, $fields ); |
647 | 657 | |
648 | 658 | // Remove duplicates |
649 | 659 | $filteredFields = array(); |
— | — | @@ -653,8 +663,9 @@ |
654 | 664 | return $filteredFields; |
655 | 665 | } |
656 | 666 | |
657 | | - /* |
658 | | - * Given a template return a list of every set field in every language |
| 667 | + /** |
| 668 | + * Get all the translations of all the messages for a banner |
| 669 | + * @return a 2D array of every set message in every language for one banner |
659 | 670 | */ |
660 | 671 | public function getTranslations( $template ) { |
661 | 672 | $translations = array(); |
— | — | @@ -662,14 +673,14 @@ |
663 | 674 | // Pull all language codes to enumerate |
664 | 675 | $allLangs = array_keys( Language::getLanguageNames() ); |
665 | 676 | |
666 | | - // Lookup all the possible fields for a template |
| 677 | + // Lookup all the message fields for a banner |
667 | 678 | $fields = $this->findFields( $template ); |
668 | 679 | |
669 | 680 | // Iterate through all possible languages to find matches |
670 | 681 | foreach ( $allLangs as $lang ) { |
671 | | - // Iterate through all possible fields |
| 682 | + // Iterate through all possible message fields |
672 | 683 | foreach ( $fields as $field => $count ) { |
673 | | - // Put all fields together for a lookup |
| 684 | + // Put all message fields together for a lookup |
674 | 685 | $message = ( $lang == 'en' ) ? "Centralnotice-{$template}-{$field}" : "Centralnotice-{$template}-{$field}/{$lang}"; |
675 | 686 | if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) { |
676 | 687 | $translations[$lang][$field] = wfMsgExt( |