r70473 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70472‎ | r70473 | r70474 >
Date:18:45, 4 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
updating comments to Doxygen style, additional fix for bug 16320
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -18,7 +18,10 @@
1919
2020 $this->centralNoticeDB = new CentralNoticeDB();
2121 }
22 -
 22+
 23+ /**
 24+ * Handle different types of page requests
 25+ */
2326 function execute( $sub ) {
2427 global $wgOut, $wgUser, $wgRequest, $wgScriptPath;
2528
@@ -44,27 +47,27 @@
4548 // Handle form sumissions
4649 if ( $this->editable && $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
4750
48 - // Handle removing
 51+ // Handle removing campaigns
4952 $toRemove = $wgRequest->getArray( 'removeNotices' );
5053 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 );
5457 }
5558
56 - // Show list of notices
 59+ // Show list of campaigns
5760 $this->listNotices();
5861 return;
5962 }
6063
61 - // Handle locking/unlocking
 64+ // Handle locking/unlocking campaigns
6265 $lockedNotices = $wgRequest->getArray( 'locked' );
6366 if ( isset( $lockedNotices ) ) {
6467 if ( $method == 'listNoticeDetail' ) {
6568 $notice = $wgRequest->getVal ( 'notice' );
6669 $this->updateLock( $notice, '1' );
6770 } else {
68 - // Build list of notices to lock
 71+ // Build list of campaigns to lock
6972 $unlockedNotices = array_diff( $this->getNoticesName(), $lockedNotices );
7073
7174 // Set locked/unlocked flag accordingly
@@ -77,14 +80,14 @@
7881 }
7982 }
8083
81 - // Handle enabling/disabling
 84+ // Handle enabling/disabling campaigns
8285 $enabledNotices = $wgRequest->getArray( 'enabled' );
8386 if ( isset( $enabledNotices ) ) {
8487 if ( $method == 'listNoticeDetail' ) {
8588 $notice = $wgRequest->getVal ( 'notice' );
8689 $this->updateEnabled( $notice, '1' );
8790 } else {
88 - // Build list of notices to disable
 91+ // Build list of campaigns to disable
8992 $disabledNotices = array_diff( $this->getNoticesName(), $enabledNotices );
9093
9194 // Set enabled/disabled flag accordingly
@@ -97,7 +100,7 @@
98101 }
99102 }
100103
101 - // Handle setting preferred
 104+ // Handle setting preferred campaigns
102105 $preferredNotices = $wgRequest->getArray( 'preferred' );
103106 if ( isset( $preferredNotices ) ) {
104107 // Set since this is a single display
@@ -106,7 +109,7 @@
107110 $this->centralNoticeDB->updatePreferred( $notice, '1' );
108111 }
109112 else {
110 - // Build list of notices to unset
 113+ // Build list of campaigns to unset
111114 $unsetNotices = array_diff( $this->getNoticesName(), $preferredNotices );
112115
113116 // Set flag accordingly
@@ -174,6 +177,7 @@
175178 }
176179 }
177180 }
 181+
178182 // Handle weight change
179183 $updatedWeights = $wgRequest->getArray( 'weight' );
180184 if ( isset( $updatedWeights ) ) {
@@ -183,7 +187,7 @@
184188 }
185189 }
186190
187 - // Handle adding of notice
 191+ // Handle adding of campaign
188192 $this->showAll = $wgRequest->getVal( 'showAll' );
189193 if ( $this->editable && $method == 'addNotice' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
190194 $noticeName = $wgRequest->getVal( 'noticeName' );
@@ -197,13 +201,13 @@
198202 }
199203 }
200204
201 - // Handle removing of notice
 205+ // Handle removing of campaign
202206 if ( $this->editable && $method == 'removeNotice' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
203207 $noticeName = $wgRequest->getVal ( 'noticeName' );
204208 $this->removeNotice ( $noticeName );
205209 }
206210
207 - // Handle adding of template
 211+ // Handle adding a banner to a campaign
208212 if ( $this->editable && $method == 'addTemplateTo' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
209213 $noticeName = $wgRequest->getVal( 'noticeName' );
210214 $templateName = $wgRequest->getVal( 'templateName' );
@@ -214,14 +218,14 @@
215219 return;
216220 }
217221
218 - // Handle removing of template
 222+ // Handle removing a banner from a campaign
219223 if ( $this->editable && $method == 'removeTemplateFor' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
220224 $noticeName = $wgRequest->getVal ( 'noticeName' );
221225 $templateName = $wgRequest->getVal ( 'templateName ' );
222226 $this->removeTemplateFor( $noticeName , $templateName );
223227 }
224228
225 - // Handle showing detail
 229+ // Handle showing campaign detail
226230 if ( $method == 'listNoticeDetail' ) {
227231 $notice = $wgRequest->getVal ( 'notice' );
228232 $this->listNoticeDetail( $notice );
@@ -229,14 +233,16 @@
230234 return;
231235 }
232236
233 - // Show list of notices
 237+ // Show list of campaigns
234238 $this->listNotices();
235239
236240 // End Campaigns tab content
237241 $wgOut->addHTML( Xml::closeElement( 'div' ) );
238242 }
239243
240 - // Update the enabled/disabled state of notice
 244+ /**
 245+ * Update the enabled/disabled state of a campaign
 246+ */
241247 private function updateEnabled( $notice, $state ) {
242248 $dbw = wfGetDB( DB_MASTER );
243249 $dbw->begin();
@@ -349,12 +355,9 @@
350356 return $out;
351357 }
352358
353 - /*
354 - * listNotices
355 - *
 359+ /**
356360 * Print out all campaigns found in db
357361 */
358 -
359362 function listNotices() {
360363 global $wgOut, $wgUser, $wgUserLang;
361364
@@ -367,14 +370,12 @@
368371 $readonly = array( 'disabled' => 'disabled' );
369372 }
370373
371 - /*
372 - * This is temporarily hard-coded
373 - */
 374+ // This is temporarily hard-coded
374375 $this->showAll = 'Y';
375376
376377 // If all languages should be shown
377378 if ( isset( $this->showAll ) ) {
378 - // Get notices for all languages
 379+ // Get campaigns for all languages
379380 $res = $dbr->select( 'cn_notices',
380381 array(
381382 'not_name',
@@ -390,7 +391,7 @@
391392 array( 'ORDER BY' => 'not_id' )
392393 );
393394 } else {
394 - // Get only notices for this language
 395+ // Get only campaigns for this language
395396 $res = $dbr->select( 'cn_notices',
396397 array(
397398 'not_name',
@@ -413,7 +414,7 @@
414415 // Begin Manage campaigns fieldset
415416 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
416417
417 - // If there are notices to show...
 418+ // If there are campaigns to show...
418419 if ( $dbr->numRows( $res ) >= 1 ) {
419420 if ( $this->editable ) {
420421 $htmlOut .= Xml::openElement( 'form',
@@ -425,6 +426,7 @@
426427 }
427428 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage' ) );
428429
 430+ // Begin table of campaigns
429431 $htmlOut .= Xml::openElement( 'table',
430432 array(
431433 'cellpadding' => 9,
@@ -433,7 +435,7 @@
434436 )
435437 );
436438
437 - // Headers
 439+ // Table headers
438440 $headers = array(
439441 wfMsgHtml( 'centralnotice-notice-name' ),
440442 wfMsgHtml( 'centralnotice-project-name' ),
@@ -449,7 +451,7 @@
450452 }
451453 $htmlOut .= $this->tableRow( $headers, 'th' );
452454
453 - // Rows
 455+ // Table rows
454456 while ( $row = $dbr->fetchObject( $res ) ) {
455457 $fields = array();
456458
@@ -517,9 +519,11 @@
518520
519521 $htmlOut .= $this->tableRow( $fields );
520522 }
 523+ // End table of campaigns
521524 $htmlOut .= Xml::closeElement( 'table' );
522 - $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() );
 525+
523526 if ( $this->editable ) {
 527+ $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() );
524528 $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-buttons' ) );
525529 $htmlOut .= Xml::submitButton( wfMsg( 'centralnotice-modify' ),
526530 array(
@@ -531,7 +535,7 @@
532536 $htmlOut .= Xml::closeElement( 'form' );
533537 }
534538
535 - // No notices to show
 539+ // No campaigns to show
536540 } else {
537541 $htmlOut .= wfMsg( 'centralnotice-no-notices-exist' );
538542 }
@@ -544,7 +548,7 @@
545549 // Begin Add a campaign fieldset
546550 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
547551
548 - // Notice Adding
 552+ // Form for adding a campaign
549553 $htmlOut .= Xml::openElement( 'form',
550554 array(
551555 'method' => 'post',
@@ -606,7 +610,7 @@
607611 global $wgOut, $wgRequest, $wgUser;
608612 if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
609613
610 - // Handle removing of templates
 614+ // Handle removing of banners from the campaign
611615 $templateToRemove = $wgRequest->getArray( 'removeTemplates' );
612616 if ( isset( $templateToRemove ) ) {
613617 foreach ( $templateToRemove as $template ) {
@@ -626,7 +630,7 @@
627631 $this->updateProjectLanguages( $notice, $projectLangs );
628632 }
629633
630 - // Handle adding of templates
 634+ // Handle adding of banners to the campaign
631635 $templatesToAdd = $wgRequest->getArray( 'addTemplates' );
632636 if ( isset( $templatesToAdd ) ) {
633637 $weight = $wgRequest->getArray( 'weight' );
@@ -652,9 +656,7 @@
653657 );
654658 }
655659
656 - /*
657 - * Temporarily hard coded
658 - */
 660+ // Temporarily hard coded
659661 $this->showAll = 'Y';
660662
661663 $output_detail = $this->noticeDetailForm( $notice );
@@ -662,12 +664,12 @@
663665 $output_templates = $this->addTemplatesForm( $notice );
664666
665667 if ( $output_detail == '' ) {
666 - // Notice not found
 668+ // Campaign not found
667669 $htmlOut .= Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-notice-doesnt-exist' ) );
668670 } else {
669671 $htmlOut .= $output_detail;
670672
671 - // Catch for no templates so that we don't double message
 673+ // Catch for no banners so that we don't double message
672674 if ( $output_assigned == '' && $output_templates == '' ) {
673675 $htmlOut .= wfMsg( 'centralnotice-no-templates' );
674676 $htmlOut .= Xml::element( 'p' );
@@ -705,7 +707,10 @@
706708 $htmlOut .= Xml::closeElement( 'fieldset' );
707709 $wgOut->addHTML( $htmlOut );
708710 }
709 -
 711+
 712+ /**
 713+ * Create form for managing campaign settings (start date, end date, languages, etc.)
 714+ */
710715 function noticeDetailForm( $notice ) {
711716 if ( $this->editable ) {
712717 $readonly = array();
@@ -798,7 +803,9 @@
799804 }
800805 }
801806
802 -
 807+ /**
 808+ * Create form for managing banners assigned to a campaign
 809+ */
803810 function assignedTemplatesForm( $notice ) {
804811 global $wgUser;
805812 $sk = $wgUser->getSkin();
@@ -823,12 +830,12 @@
824831 array( 'ORDER BY' => 'cn_notices.not_id' )
825832 );
826833
827 - // No templates found
 834+ // No banners found
828835 if ( $dbr->numRows( $res ) < 1 ) {
829836 return;
830837 }
831838
832 - // Build Assigned Template HTML
 839+ // Build Assigned banners HTML
833840 $htmlOut = Xml::hidden( 'change', 'weight' );
834841 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-assigned-templates' ) );
835842 $htmlOut .= Xml::openElement( 'table',
@@ -846,7 +853,7 @@
847854 $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '70%' ),
848855 wfMsg ( "centralnotice-templates" ) );
849856
850 - // Rows
 857+ // Table rows
851858 while ( $row = $dbr->fetchObject( $res ) ) {
852859
853860 $htmlOut .= Xml::openElement( 'tr' );
@@ -900,7 +907,9 @@
901908 }
902909 }
903910
904 -
 911+ /**
 912+ * Create form for adding banners to a campaign
 913+ */
905914 function addTemplatesForm( $notice ) {
906915 global $wgUser;
907916 $sk = $wgUser->getSkin();
@@ -989,7 +998,9 @@
990999 return $htmlOut;
9911000 }
9921001
993 -
 1002+ /**
 1003+ * Build a list of all the banners assigned to a campaign
 1004+ */
9941005 function selectTemplatesAssigned ( $notice ) {
9951006 $dbr = wfGetDB( DB_SLAVE );
9961007 $res = $dbr->select(
@@ -1017,8 +1028,8 @@
10181029 }
10191030
10201031 /**
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
10231034 */
10241035 static function selectNoticeTemplates( $project, $language ) {
10251036 $dbr = wfGetDB( DB_SLAVE );
@@ -1213,13 +1224,13 @@
12141225
12151226 $dbr = wfGetDB( DB_SLAVE );
12161227
1217 - // Start / end dont line up
 1228+ // Start/end don't line up
12181229 if ( $start > $end || $end < $start ) {
12191230 $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-invalid-date-range3' ) ) );
12201231 return;
12211232 }
12221233
1223 - // Invalid notice name
 1234+ // Invalid campaign name
12241235 $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) );
12251236 if ( $dbr->numRows( $res ) < 1 ) {
12261237 $wgOut->addHTML( Xml::element( 'div', array( 'class' => 'cn-error' ), wfMsg( 'centralnotice-notice-doesnt-exist' ) ) );
@@ -1306,10 +1317,7 @@
13071318 global $wgContLanguageCode;
13081319 global $wgScriptPath;
13091320 $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...
13141322 $languages = Language::getLanguageNames( $customisedOnly );
13151323 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
13161324 $languages[$wgContLanguageCode] = $wgContLanguageCode;
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -15,8 +15,8 @@
1616 wfLoadExtensionMessages( 'CentralNotice' );
1717 }
1818
19 - /*
20 - * Handle different types of page requests.
 19+ /**
 20+ * Handle different types of page requests
2121 */
2222 function execute( $sub ) {
2323 global $wgOut, $wgUser, $wgRequest, $wgScriptPath;
@@ -43,10 +43,10 @@
4444 // Handle forms
4545 if ( $wgRequest->wasPosted() ) {
4646
47 - // Handle removing
 47+ // Handle removing banners
4848 $toRemove = $wgRequest->getArray( 'removeTemplates' );
4949 if ( isset( $toRemove ) ) {
50 - // Remove templates in list
 50+ // Remove banners in list
5151 foreach ( $toRemove as $template ) {
5252 $this->removeTemplate( $template );
5353 }
@@ -66,7 +66,7 @@
6767 }
6868 }
6969
70 - // Handle adding
 70+ // Handle adding banner
7171 // FIXME: getText()? weak comparison
7272 if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) {
7373 $this->addTemplate(
@@ -84,7 +84,7 @@
8585 }
8686 }
8787
88 - // Handle viewing of a template in all languages
 88+ // Handle viewing of a banner in all languages
8989 if ( $sub == 'view' && $wgRequest->getVal( 'wpUserLanguage' ) == 'all' ) {
9090 $template = $wgRequest->getVal( 'template' );
9191 $this->showViewAvailable( $template );
@@ -92,7 +92,7 @@
9393 return;
9494 }
9595
96 - // Handle viewing a specific template
 96+ // Handle viewing a specific banner
9797 if ( $sub == 'view' && $wgRequest->getText( 'template' ) != '' ) {
9898 $this->showView();
9999 $wgOut->addHTML( Xml::closeElement( 'div' ) );
@@ -107,7 +107,7 @@
108108 return;
109109 }
110110
111 - // Handle cloning a specific template
 111+ // Handle cloning a specific banner
112112 if ( $sub == 'clone' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
113113 $oldTemplate = $wgRequest->getVal( 'oldTemplate' );
114114 $newTemplate = $wgRequest->getVal( 'newTemplate' );
@@ -118,15 +118,15 @@
119119 }
120120 }
121121
122 - // Show list by default
 122+ // Show list of banners by default
123123 $this->showList();
124124
125125 // End Banners tab content
126126 $wgOut->addHTML( Xml::closeElement( 'div' ) );
127127 }
128128
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.
131131 */
132132 function showList() {
133133 global $wgOut, $wgUser;
@@ -152,6 +152,8 @@
153153 );
154154 }
155155 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage-templates' ) );
 156+
 157+ // Show paginated list of banners
156158 $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() );
157159 $htmlOut .= $pager->getBody();
158160 $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ), $pager->getNavigationBar() );
@@ -172,7 +174,10 @@
173175
174176 $wgOut->addHTML( $htmlOut );
175177 }
176 -
 178+
 179+ /**
 180+ * Show "Add a banner" interface
 181+ */
177182 function showAdd() {
178183 global $wgOut, $wgUser;
179184
@@ -207,7 +212,10 @@
208213 // Output HTML
209214 $wgOut->addHTML( $htmlOut );
210215 }
211 -
 216+
 217+ /**
 218+ * View or edit an individual banner
 219+ */
212220 private function showView() {
213221 global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode;
214222
@@ -221,7 +229,7 @@
222230 // Get user's language
223231 $wpUserLang = $wgRequest->getVal( 'wpUserLanguage' ) ? $wgRequest->getVal( 'wpUserLanguage' ) : $wgContLanguageCode;
224232
225 - // Get current template
 233+ // Get current banner
226234 $currentTemplate = $wgRequest->getText( 'template' );
227235
228236 // Begin building HTML
@@ -232,7 +240,7 @@
233241
234242 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-template' ) . ': ' . $currentTemplate );
235243
236 - // Show preview
 244+ // Show preview of banner
237245 $render = new SpecialNoticeText();
238246 $render->project = 'wikipedia';
239247 $render->language = $wgRequest->getVal( 'wpUserLanguage' );
@@ -246,16 +254,16 @@
247255 );
248256 }
249257
250 - // Pull text and respect any inc: markup
 258+ // Pull banner text and respect any inc: markup
251259 $bodyPage = Title::newFromText( "Centralnotice-template-{$currentTemplate}", NS_MEDIAWIKI );
252260 $curRev = Revision::newFromTitle( $bodyPage );
253261 $body = $curRev ? $curRev->getText() : '';
254262
255 - // Extract message fields from the template body
 263+ // Extract message fields from the banner body
256264 $fields = array();
257265 preg_match_all( '/\{\{\{([A-Za-z0-9\_\-\x{00C0}-\x{017F}]+)\}\}\}/u', $body, $fields );
258266
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.
260268 if ( count( $fields[0] ) > 0 ) {
261269 if ( $this->editable ) {
262270 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
@@ -272,7 +280,7 @@
273281 )
274282 );
275283
276 - // Headers
 284+ // Table headers
277285 $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) );
278286 $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses' ) );
279287 $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english' ) );
@@ -285,7 +293,7 @@
286294 $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1;
287295 }
288296
289 - // Rows
 297+ // Table rows
290298 foreach ( $filteredFields as $field => $count ) {
291299 // Message
292300 $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
@@ -350,9 +358,7 @@
351359 $htmlOut .= Xml::closeElement( 'form' );
352360 }
353361
354 - /*
355 - * Show language selection form
356 - */
 362+ // Show language selection form
357363 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
358364 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) );
359365 $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
@@ -377,9 +383,7 @@
378384 $htmlOut .= Xml::closeElement( 'form' );
379385 }
380386
381 - /*
382 - * Show edit form
383 - */
 387+ // Show edit form
384388 if ( $this->editable ) {
385389 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
386390 $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' );
@@ -408,9 +412,7 @@
409413 $htmlOut .= Xml::closeElement( 'form' );
410414 }
411415
412 - /*
413 - * Show Clone form
414 - */
 416+ // Show clone form
415417 if ( $this->editable ) {
416418 $htmlOut .= Xml::openElement ( 'form',
417419 array(
@@ -439,7 +441,10 @@
440442 // Output HTML
441443 $wgOut->addHTML( $htmlOut );
442444 }
443 -
 445+
 446+ /**
 447+ * Preview all available translations of a banner
 448+ */
444449 public function showViewAvailable( $template ) {
445450 global $wgOut, $wgUser;
446451
@@ -448,7 +453,7 @@
449454
450455 $sk = $wgUser->getSkin();
451456
452 - // Pull all available text for a template
 457+ // Pull all available text for a banner
453458 $langs = array_keys( $this->getTranslations( $template ) );
454459 $htmlOut = '';
455460
@@ -479,7 +484,10 @@
480485
481486 return $wgOut->addHtml( $htmlOut );
482487 }
483 -
 488+
 489+ /**
 490+ * Add or update a message
 491+ */
484492 private function updateMessage( $text, $translation, $lang ) {
485493 $title = Title::newFromText(
486494 ( $lang == 'en' ) ? "Centralnotice-{$text}" : "Centralnotice-{$text}/{$lang}",
@@ -536,6 +544,9 @@
537545 }
538546 }
539547
 548+ /**
 549+ * Create a new banner
 550+ */
540551 private function addTemplate ( $name, $body ) {
541552 global $wgOut;
542553
@@ -568,9 +579,7 @@
569580 );
570581 $dbw->commit();
571582
572 - /*
573 - * Perhaps these should move into the db as blob
574 - */
 583+ // Perhaps these should move into the db as blob
575584 $article = new Article(
576585 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
577586 );
@@ -579,6 +588,9 @@
580589 }
581590 }
582591
 592+ /**
 593+ * Update a banner
 594+ */
583595 private function editTemplate ( $name, $body ) {
584596 global $wgOut;
585597
@@ -594,9 +606,7 @@
595607 );
596608
597609 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
601611 $article = new Article(
602612 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
603613 );
@@ -605,8 +615,8 @@
606616 }
607617 }
608618
609 - /*
610 - * Copy all the data from one template to another
 619+ /**
 620+ * Copy all the data from one banner to another
611621 */
612622 public function cloneTemplate( $source, $dest ) {
613623 // Reset the timer as updates on meta take a long time
@@ -633,16 +643,16 @@
634644 }
635645 }
636646
637 - /*
638 - * Find all fields set for a template
 647+ /**
 648+ * Find all message fields set for a banner
639649 */
640650 private function findFields( $template ) {
641651 $messages = array();
642652 $body = wfMsg( "Centralnotice-template-{$template}" );
643653
644 - // Generate fields from parsing the body
 654+ // Generate list of message fields from parsing the body
645655 $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 );
647657
648658 // Remove duplicates
649659 $filteredFields = array();
@@ -653,8 +663,9 @@
654664 return $filteredFields;
655665 }
656666
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
659670 */
660671 public function getTranslations( $template ) {
661672 $translations = array();
@@ -662,14 +673,14 @@
663674 // Pull all language codes to enumerate
664675 $allLangs = array_keys( Language::getLanguageNames() );
665676
666 - // Lookup all the possible fields for a template
 677+ // Lookup all the message fields for a banner
667678 $fields = $this->findFields( $template );
668679
669680 // Iterate through all possible languages to find matches
670681 foreach ( $allLangs as $lang ) {
671 - // Iterate through all possible fields
 682+ // Iterate through all possible message fields
672683 foreach ( $fields as $field => $count ) {
673 - // Put all fields together for a lookup
 684+ // Put all message fields together for a lookup
674685 $message = ( $lang == 'en' ) ? "Centralnotice-{$template}-{$field}" : "Centralnotice-{$template}-{$field}/{$lang}";
675686 if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) {
676687 $translations[$lang][$field] = wfMsgExt(

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68458adding extended Latin to allowable chars for template message names per bug 1...kaldari17:19, 23 June 2010

Status & tagging log