Don't initialize translations of conditions at initialization as the session might...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 27 May 2019 19:30:18 +0000 (19:30 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 27 May 2019 19:30:18 +0000 (19:30 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrreport/trunk@2830 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport_body.php

index 59d3997c75ddcfa8a282d2abbc8272430e68e97d..c847e862b105a4b06675bc2c6572229810084ac3 100644 (file)
@@ -318,10 +318,10 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        $select = $td->appendElement('select', array('name' => 'condition', 'required' => 'required'));
        $option = $select->appendElement('option', array('value' => '0'));
        $option->appendText(wfMessage('wrreport-condition-select')->text());
-       foreach (WrReport::$wrConditions as $condition_num => $condition_text) {
+       foreach (WrReport::$wrConditions as $condition_num) {
                $option = $select->appendElement('option', array('value' => (string) $condition_num));
                if ($condition == $condition_num) $option->setAttribute('selected', 'selected');
-               $option->appendText($condition_text);
+               $option->appendText(WrReport::getWrConditionText($condition_num));
        }
        $option = $select->appendElement('option', array('value' => '-1'));
        if ($condition == -1) $option->setAttribute('selected', 'selected');
@@ -455,7 +455,7 @@ function wrReportTableRowRender($table, $row, $format, $showActions, $parser) {
 
        // $row['condition']
        $condition_text = '---';
-       if (isset(WrReport::$wrConditions[$row['condition']])) $condition_text = WrReport::$wrConditions[$row['condition']];
+       if (array_key_exists($row['condition'], WrReport::$wrConditions)) $condition_text = WrReport::getWrConditionText($row['condition']);
        $td = $tr->appendElement('td');
        if ($row['delete_date']) $td->appendElement('em')->appendText(wfMessage('wrreport-deletereport-deleted')->text());
        else $td->appendText($condition_text);
@@ -610,13 +610,13 @@ function wrReportUserMayDelete() {
 // -------------------
 
 class WrReport {
-       // Conditions: array(1 => 'Sehr gut', 2 => 'Gut', 3 => 'Mittelmäßig', 4 => 'Schlecht', 5 => 'Geht nicht');
-       public static $wrConditions;
+       // Conditions: 1 => 'Sehr gut', 2 => 'Gut', 3 => 'Mittelmäßig', 4 => 'Schlecht', 5 => 'Geht nicht'
+       public static $wrConditions = array(1, 2, 3, 4, 5);
 
 
-       public static function initWrConditions() {
-               WrReport::$wrConditions = array();
-               for ($i = 1; $i != 6; ++$i) WrReport::$wrConditions[$i] = wfMessage('wrreport-condition-' . $i)->text();
+       /// Returns the translated text of a specified numeric condition
+       public static function getWrConditionText(int $condition): string {
+               return wfMessage('wrreport-condition-' . $condition)->text();
        }
 
 
@@ -826,8 +826,8 @@ class WrReport {
                                else $date = strftime('%d.%m.', $date_report);
 
                                $td = $tr->appendElement('td');
-                               if (isset(WrReport::$wrConditions[$condition])) {
-                                       $td->appendElement('a', array('href' => $title->getLocalURL() . '#' . Sanitizer::escapeIdForLink(wfMessage('wrreport-reports-sectionname'))))->appendText(WrReport::$wrConditions[$condition]);
+                               if (array_key_exists($condition, WrReport::$wrConditions)) {
+                                       $td->appendElement('a', array('href' => $title->getLocalURL() . '#' . Sanitizer::escapeIdForLink(wfMessage('wrreport-reports-sectionname'))))->appendText(WrReport::getWrConditionText($condition));
                                        $td->appendText(' ');
                                        $small = $td->appendElement('small');
                                        $small->appendText($date);
@@ -1137,7 +1137,6 @@ class WrReport {
        }
 
 }
-WrReport::initWrConditions();