Whitespace corrections.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 04d32e155f46a454906dec9a6ddcde2a68f475c6..0e44cc041c2cb7b8827a6b5f20d5d48ed5af4f33 100644 (file)
@@ -171,7 +171,7 @@ class WrServicesLibravatar extends Services_Libravatar {
 
 /// Forces a regeneration of region overview pages ('Tirol', 'Vorarlberg', ...)
 function wrRecacheRegions() {
-       $dbr = wfGetDB(DB_SLAVE);
+       $dbr = wfGetDB(DB_REPLICA);
        // SELECT cl_from FROM categorylinks where cl_to = 'Region'
        $res = $dbr->select('categorylinks', 'cl_from', array('cl_to' => 'Region'));
        $page_ids = array();
@@ -185,7 +185,7 @@ function wrRecacheRegions() {
 
 /// Returns the tuple ($report_id, $sledrun_condition, $date_report)
 /// $date_report is NULL or a time as returned by strtotime
-/// Expects a database connection ($dbr = wfGetDB(DB_SLAVE);)
+/// Expects a database connection ($dbr = wfGetDB(DB_REPLICA);)
 /// and a page_id describung the page where the condition should be returned.
 /// If no condition is found, (NULL, NULL, NULL) is returned.
 function wrGetSledrunCondition($dbr, $page_id) {
@@ -215,13 +215,12 @@ function wrGetSledrunCondition($dbr, $page_id) {
 /// Updates the line of the wrreportcache table that corresponds to the $page_id parameter
 function wrUpdateWrReportCacheTable($page_id) {
        // Determine the new content for the row that should be updated
-       $dbr = wfGetDB(DB_SLAVE);
+       $dbr = wfGetDB(DB_REPLICA);
        list($report_id, $condition, $date_report) = wrGetSledrunCondition($dbr, $page_id);
        $rows = wrReportGetReports(array('id' => $report_id), 1);
 
        // Delete the old content (if any)
        $dbw = wfGetDB(DB_MASTER);
-       $dbw->begin();
        $dbw->delete('wrreportcache', array('page_id' => $page_id));
 
        // Insert the updated row
@@ -237,7 +236,6 @@ function wrUpdateWrReportCacheTable($page_id) {
                        'author_name' => $row['author_name'],
                        'author_username' => (is_null($row['author_userid']) ? NULL : $row['author_username'])));
        }
-       $dbw->commit();
 }
 
 
@@ -305,7 +303,7 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-time')->text());
        $td = $tr->appendElement('td');
-       $td->appendElement('input', array('name' => 'time_report', 'maxlength' => '5', 'size' => '5', 'value' => $time_report));
+       $td->appendElement('input', array('name' => 'time_report', 'maxlength' => '5', 'size' => '5', 'class' => 'mw-ui-input mw-ui-input-inline', 'value' => $time_report));
        $td->appendText(' ');
        $td->appendText('Uhr');
        $td->appendText(' ');
@@ -318,10 +316,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');
@@ -330,12 +328,12 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        // description
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-description')->text());
-       $tr->appendElement('td')->appendElement('textarea', array('name' => 'description', 'class' => 'fullwidth', 'rows' => '7', 'required' => 'required'))->appendText($description);
+       $tr->appendElement('td')->appendElement('textarea', array('name' => 'description', 'class' => /* 'fullwidth' */ 'mw-ui-input', 'rows' => '7', 'required' => 'required'))->appendText($description);
 
        // author
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-author')->text());
-       $tr->appendElement('td')->appendElement('input', array('name' => 'author_name', 'class' => 'fullwidth', 'maxlength' => '30', 'value' => $author_name));
+       $tr->appendElement('td')->appendElement('input', array('name' => 'author_name', 'class' => /* fullwidth */ 'mw-ui-input', 'maxlength' => '30', 'value' => $author_name));
 
        // Buttons
        // I would like to do it this way, but due to a bug of internet explorer, the <button> element is not useable.
@@ -347,13 +345,11 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-submit')->text());
        $td = $tr->appendElement('td');
-       $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit'));
-       if ($hide_save_button)
-               $input->setAttribute('value', wfMessage('wrreport-newreport-next')->text());
-       else {
-               $input->setAttribute('value', wfMessage('wrreport-newreport-preview')->text());
-
-               $td->appendElement('input', array('name' => 'store', 'type' => 'submit', 'value' => wfMessage('wrreport-newreport-save')->text()));
+       if ($hide_save_button) {
+               $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-progressive', 'value' => wfMessage('wrreport-newreport-next')->text()));
+       } else {
+               $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit', 'class' => 'mw-ui-button', 'value' => wfMessage('wrreport-newreport-preview')->text()));
+               $td->appendElement('input', array('name' => 'store', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-constructive', 'value' => wfMessage('wrreport-newreport-save')->text()));
        }
 
        return $doc->saveHTML($form);
@@ -397,8 +393,8 @@ function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-reports-action')->text());
        $td = $tr->appendElement('td');
-       $td->appendElement('input', array('name' => 'deletepreview', 'type' => 'submit', 'value' => wfMessage('wrreport-newreport-preview')->text()));
-       $td->appendElement('input', array('name' => 'delete', 'type' => 'submit', 'value' => wfMessage('wrreport-deletereport-delete')->text()));
+       $td->appendElement('input', array('name' => 'deletepreview', 'type' => 'submit', 'class' => 'mw-ui-button', 'value' => wfMessage('wrreport-newreport-preview')->text()));
+       $td->appendElement('input', array('name' => 'delete', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-destructive', 'value' => wfMessage('wrreport-deletereport-delete')->text()));
 
        // hidden field
        $input = $td->appendElement('input', array('name' => 'reportid', 'type' => 'hidden', 'value' => (string) $reportid));
@@ -457,7 +453,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 (in_array($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);
@@ -556,7 +552,7 @@ function wrReportGetColumnNames() {
 ///   $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
 ///   $limit = 1; // or NULL for no limit
 function wrReportGetReports($conditions, $limit=NULL) {
-       $dbr = wfGetDB(DB_SLAVE);
+       $dbr = wfGetDB(DB_REPLICA);
        $columns = wrReportGetColumnNames();
        global $wgDBtype;
        if ($wgDBtype == "mysql") // "condition" is a reserved word in mysql
@@ -575,7 +571,7 @@ function wrReportGetReports($conditions, $limit=NULL) {
 ///
 /// If no condition is present, array(NULL, NULL) is returned
 function wrReportConditionRender($page_title) {
-       $dbr = wfGetDB(DB_SLAVE);
+       $dbr = wfGetDB(DB_REPLICA);
        $cond = 'condition';
        global $wgDBtype;
        // select wrreport.id as report_id, `condition`, date_report from wrreport where page_title='Axamer Lizum' and `condition` is not null and date_invalid > now() and delete_date is null order by date_report desc, date_entry desc limit 1;
@@ -612,19 +608,19 @@ 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();
        }
 
 
        /// Returns the number of sledrun reports issued by a user with the given id.
        public static function getUserSeldrunReportCount($user_id) {
-               $dbr = wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_REPLICA);
                // select count(*) from wrreport where author_userid = 1 and delete_date is null and `condition` is not null;
                $res = $dbr->select('wrreport', 'count(*)', array('author_userid' => $user_id, 'delete_date' => null, '`condition` is not null'));
                $row = $res->fetchRow();
@@ -637,7 +633,7 @@ class WrReport {
        // Parser Hook Functions
        // ---------------------
 
-       public static function ParserFirstCallInitHook(&$parser) {
+       public static function ParserFirstCallInitHook(Parser &$parser) {
                $parser->setHook('bahnberichtformular', 'WrReport::bahnberichtformularParserHook');
                $parser->setHook('bahnberichte', 'WrReport::bahnberichteParserHook');
                $parser->setHook('bahnentabelle', 'WrReport::bahnentabelleParserHook');
@@ -650,9 +646,9 @@ class WrReport {
        /// \brief Is called when the tag <bahnberichtformular/> is encountered.
        ///
        /// The current page name is taken.
-       public static function bahnberichtformularParserHook($input, $args, $parser) {
+       public static function bahnberichtformularParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                // Username
-               global $wgUser;
+               $wgUser = $parser->getUser();
                $author_name = NULL;
                if ($wgUser->isLoggedIn()) {
                        $author_name = $wgUser->getRealName();
@@ -690,7 +686,7 @@ class WrReport {
        /// \brief Is called when the tag <bahnberichte/> is encountered.
        ///
        /// The current page name is taken.
-       public static function bahnberichteParserHook($input, $args, $parser) {
+       public static function bahnberichteParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport'); // getOutput() returns class ParserOutput
                $title = $parser->getTitle();
                $page_id = $title->getArticleID();
@@ -714,7 +710,7 @@ class WrReport {
        /// conditions is an array that's given to the where clause
        private static function getRegionDetails($conditions) {
                // Example: SELECT name FROM wrregion WHERE page_id = 882;
-               $dbr = wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_REPLICA);
                $res = $dbr->select('wrregion', array('id', 'name', 'aswkb(border)'), $conditions);
                if ($dbr->numRows($res) == 1) {
                        $row = $dbr->fetchRow($res);
@@ -750,22 +746,33 @@ class WrReport {
 
        /// Creates the HTML of the <bahnentabelle>, <bahnenregiontabelle> and <rodelbahntabelle> tags.
        private static function createBahnentabelle($page_titles) {
-               $dbr = wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_REPLICA);
 
-               // SELECT p.page_id,p.page_title, c.length, c.walkup_time, c.top_elevation, c.bottom_elevation, c.walkup_separate, c.lift, c.night_light, c.public_transport, c.sled_rental, c.information_phone FROM `page` p, wrsledruncache c WHERE (p.page_title in ('Birgitzer_Alm_(vom_Adelshof)', 'Kemater_Alm', 'Axamer_Lizum') and p.page_id=c.page_id) ORDER BY page_title
-               $where_array = array('page.page_id = wrsledruncache.page_id');
+               // SELECT p.page_id, p.page_title, c.length, c.walkup_time, c.top_elevation, c.bottom_elevation, c.walkup_separate, c.lift, c.night_light, c.public_transport,
+               // c.sled_rental, c.information_phone, s.show_status, r.status, r.last_check, r.last_update
+               // FROM (`page` p JOIN  wrsledruncache c ON p.page_id=c.page_id) LEFT OUTER JOIN (wrintermapssledrun s JOIN wrintermapsreport r ON s.intermaps_sledrun_id=r.intermaps_sledrun_id) ON p.page_id=s.wr_page_id
+               // WHERE p.page_title in ('Birgitzer_Alm_(vom_Adelshof)', 'Mutterer_Alm_-_Sportrodelbahn', 'Axamer_Lizum') ORDER BY page_title;
+               $where_array = array();
                if (count($page_titles) > 0) {
                        $mysql_page_ids = array();
                        foreach ($page_titles as $page_title) $mysql_page_ids[] = $page_title->getArticleID();
-                       $where_array[] = 'page.page_id in (' . implode(', ', $mysql_page_ids) . ')';
+                       $where_array[] = 'p.page_id in (' . implode(', ', $mysql_page_ids) . ')';
                } else $where_array[] = 'false';
-               $res = $dbr->select(array('page', 'wrsledruncache'), array('page.page_id', 'page.page_title', 'page_namespace', 'length', 'walkup_time', 'top_elevation', 'bottom_elevation', 'walkup_possible', 'walkup_separate', 'lift', 'night_light', 'public_transport', 'sled_rental', 'information_phone', 'information_web'), $where_array, 'bahnentabelleParserHook', array('ORDER BY' => 'page.page_title'));
+               $res = $dbr->select(['AA' => ['p' => 'page', 'c' => 'wrsledruncache'], 'BB' => ['r' => 'wrintermapsreport', 's' => 'wrintermapssledrun']],
+                                                       ['p.page_id', 'p.page_title', 'p.page_namespace',
+                                                        'c.length', 'c.walkup_time', 'c.top_elevation', 'c.bottom_elevation', 'c.walkup_possible', 'c.walkup_separate',
+                                                        'c.lift', 'c.night_light', 'c.public_transport', 'c.sled_rental', 'c.information_phone', 'c.information_web',
+                                                        's.show_status', 'r.status', 'r.last_check', 'r.last_update'],
+                                                       $where_array,
+                                                       'bahnentabelleParserHook',
+                                                       ['ORDER BY' => 'p.page_title'],
+                                                       ['p' => ['JOIN', 'p.page_id=c.page_id'], 'r' => ['JOIN', 's.intermaps_sledrun_id=r.intermaps_sledrun_id'], 'AA' => ['LEFT OUTER JOIN', 'p.page_id=s.wr_page_id']]
+                                               );
 
                global $wgUser;
                global $wgWrReportMode; // e.g. 'summer'
                global $wgWrReportBlackListAll;
                global $wgWrReportBlackListStrangers;
-               global $wgDBtype;
 
                // Determine, whether the user is allowed to make a new report
                $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
@@ -781,6 +788,7 @@ class WrReport {
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_lift.png', 'alt' => wfMessage('wrreport-icon-lift')->text(), 'title' => wfMessage('wrreport-icon-lift')->text()));
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_walk.png', 'alt' => wfMessage('wrreport-icon-walkupseparate')->text(), 'title' => wfMessage('wrreport-icon-walkupseparate')->text()));
                $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_bus.png', 'alt' => wfMessage('wrreport-icon-publictransport')->text(), 'title' => wfMessage('wrreport-icon-publictransport')->text()));
+               if ($wgWrReportMode != 'summer') $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_opened.png', 'alt' => wfMessage('wrreport-icon-intermaps-status')->text(), 'title' => wfMessage('wrreport-icon-intermaps-status')->text()));
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun')->text());
                if ($wgWrReportMode != 'summer') $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-condition')->text());
                $tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-information')->text());
@@ -812,6 +820,22 @@ class WrReport {
                        $td = $tr->appendElement('td');
                        if ($row->public_transport and $row->public_transport != 5) $td->appendElement('img', array('src' => '/vorlagen/s_bus.png', 'alt' => wfMessage('wrreport-icon-publictransport')->text(), 'title' => wfMessage('wrreport-icon-publictransport')->text()));
 
+                       if ($wgWrReportMode != 'summer') {
+                               $td = $tr->appendElement('td');
+                               if ($row->show_status) {
+                                       if ($row->status == 'open') {
+                                               $td->appendElement('img', array('src' => '/vorlagen/s_opened.png', 'alt' => wfMessage('wrreport-icon-intermaps-opened')->text(), 'title' => wfMessage('wrreport-icon-intermaps-opened')->text()));
+                                       } elseif ($row->status == 'closed') {
+                                               $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => wfMessage('wrreport-icon-intermaps-closed')->text(), 'title' => wfMessage('wrreport-icon-intermaps-closed')->text()));
+                                       } else {
+                                               $td->appendText($row->status);
+                                       }
+                               }
+                               // s_closed
+                               // no info
+                               // check whether info should be shown at all
+                       }
+
                        $tr->appendElement('td')->appendElement('a', array('href' => $title->getLocalURL()))->appendText($title->getPrefixedText());
 
                        if ($wgWrReportMode != 'summer') {
@@ -828,18 +852,18 @@ 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() . '#' . Title::escapeFragmentForURL(wfMessage('wrreport-reports-sectionname')->text())))->appendText(WrReport::$wrConditions[$condition]);
+                               if (in_array($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);
                                        if ($userMayReportThis) {
                                                $small->appendText(' ');
-                                               $small->appendElement('em')->appendElement('a', array('href' =>$title->getLocalURL() . '#' . Title::escapeFragmentForURL(wfMessage('wrreport-newreport-sectionname')->text())))->appendText(wfMessage('wrreport-newreport-new')->text());
+                                               $small->appendElement('em')->appendElement('a', array('href' =>$title->getLocalURL() . '#' . Sanitizer::escapeIdForLink(wfMessage('wrreport-newreport-sectionname'))))->appendText(wfMessage('wrreport-newreport-new')->text());
                                        }
                                } else {
                                        if ($userMayReportThis)
-                                               $td->appendElement('small')->appendElement('em')->appendElement('a', array('href' =>$title->getLocalURL() . '#' . Title::escapeFragmentForURL(wfMessage('wrreport-newreport-sectionname')->text())))->appendText(wfMessage('wrreport-newreport-please')->text());
+                                               $td->appendElement('small')->appendElement('em')->appendElement('a', array('href' =>$title->getLocalURL() . '#' . Sanitizer::escapeIdForLink(wfMessage('wrreport-newreport-sectionname'))))->appendText(wfMessage('wrreport-newreport-please')->text());
                                        else $td->appendText('--');
                                }
                        }
@@ -886,7 +910,7 @@ class WrReport {
        /// Kemater Alm
        /// Axamer Lizum
        /// </bahnentabelle>
-       public static function bahnentabelleParserHook($input, $args, $parser) {
+       public static function bahnentabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                // Add feed
@@ -916,7 +940,7 @@ class WrReport {
        /// <bahnenregiontabelle wiki="Innsbruck" /> (refers to region represented by the MediaWiki Title name)
        /// <bahnenregiontabelle region_id="3" /> (refers to id in the wrregion table)
        /// <bahnenregiontabelle region_name="Innsbruck" /> (refers to name in the wrregion table)
-       public static function bahnenregiontabelleParserHook($input, $args, $parser) {
+       public static function bahnenregiontabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                try {
@@ -945,7 +969,7 @@ class WrReport {
 
                        // get titles that are in the region
                        $page_titles = array();
-                       $dbr = wfGetDB(DB_SLAVE);
+                       $dbr = wfGetDB(DB_REPLICA);
                        // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
                        // $res = $dbr->select('wrsledruncache', 'page_id', array('CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))', 'NOT under_construction'), __METHOD__, 'page_title');
                        $res = $dbr->select(array('wrsledruncache', 'wrregioncache'), array('page_id' => 'wrregioncache.page_id'), array('wrregioncache.region_id' => $region_id, 'wrregioncache.page_id=wrsledruncache.page_id', 'NOT under_construction'), __METHOD__, 'page_title');
@@ -968,14 +992,14 @@ class WrReport {
        /// \brief Is called when the tag <rodelbahntabelle/> is encountered.
        ///
        /// Description: See description of wrreport.php
-       public static function rodelbahntabelleParserHook($input, $args, $parser) {
+       public static function rodelbahntabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                // Add feed
                // Note: As (of MediaWiki 1.19), only one feed can be added and each feed added replaces the previous one, the following is possible without risk of having duplicated feed entries.
                WrReport::addRegionFeedLink($parser->getTitle());
 
-               $dbr = wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_REPLICA);
                try {
                        libxml_use_internal_errors(true); // without that, we get PHP Warnings if the $input is not well-formed
                        try {
@@ -1079,7 +1103,7 @@ class WrReport {
 
 
        /// \brief Is called when the tag <avatar>username</avatar> is encountered.
-       public static function avatarParserHook($input, $args, $parser, $frame) {
+       public static function avatarParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $doc = new WrDOMDocument();
                $sla = new WrServicesLibravatar();
 
@@ -1111,9 +1135,34 @@ class WrReport {
        }
 
 
+       public static function MobileMenuHook($name, \MediaWiki\Minerva\MenuBuilder &$menu) {
+               if ($name === 'discovery') {
+                       // delete "Random page". As a removeEntry function is missing,
+                       // a new menu is built here without the random page.
+                       $new_menu = new \MediaWiki\Minerva\MenuBuilder();
+                       foreach ($menu->getEntries() as $menuEntryRepresentation) {
+                               $new_entry_name = $menuEntryRepresentation['name'];
+                               if ($new_entry_name == 'random') continue;
+                               $new_entry_components = $menuEntryRepresentation['components'];
+                               $new_entry_isjsonly = isset($menuEntryRepresentation['class']) and $menuEntryRepresentation['class'] === 'jsonly';
+                               $new_entry = $new_menu->insert($new_entry_name, $new_entry_isjsonly);
+                               foreach ($new_entry_components as $new_entry_component) {
+                                       $label = $new_entry_component['text'];
+                                       $url = $new_entry_component['href'];
+                                       $className = $new_entry_component['class'];
+                                       $new_entry->addComponent($label, $url, $className, $new_entry_components);
+                               }
+                       }
+                       $menu = $new_menu;
+
+                       // add region menu entry
+                       $icon = MobileUI::iconClass('random', 'before');
+                       $title = Title::newFromText('Region', NS_CATEGORY);
+                       $menu->insert('region')->addComponent('Regionen', $title->getLocalURL(), $icon, array('id' => 'regionButton', 'data-event-name' => 'region'));
+               }
+       }
 
 }
-WrReport::initWrConditions();
 
 
 
@@ -1127,15 +1176,6 @@ class SpecialWrReport extends SpecialPage {
        }
 
 
-       static function LanguageGetSpecialPageAliasesHook(&$specialPageArray, $languageCode) {
-               $text = wfMessage('wrreport')->text(); // 'Bahnberichte'
-               $title = Title::newFromText($text); // 'Bahnberichte'
-               $specialPageArray['wrreport'][] = $title->getDBKey(); // 'Bahnberichte'
-               return true;
-       }
-
-
-
        /// \param $par Possibilities:
        /// - action == 'view' (default)
        /// - action == 'preview': Preview new report
@@ -1150,6 +1190,7 @@ class SpecialWrReport extends SpecialPage {
                $output = $this->getOutput();
        
                global $wgParser;
+               $output->addWikiText(''); // this is necessary because otherwise $wgParser is not properly initialized
 
                $output->addModules('ext.wrreport');
                $this->setHeaders();
@@ -1179,7 +1220,6 @@ class SpecialWrReport extends SpecialPage {
                        $rows = wrReportGetReports($conditions);
                        if (count($rows) == 0) $output->addHTML(wfMessage('wrreport-reports-none')->text());
                        else {
-                               $output->addWikiText(''); // this is necessary because otherwise $wgParser is not properly initialized but $wgParser is needed in the next line
                                $output->addHTML(wrReportTableRender($rows, WRREPORT_DETAIL, wrReportUserMayDelete(), $wgParser));
                        }
                }
@@ -1249,18 +1289,18 @@ class SpecialWrReport extends SpecialPage {
                                $output->addWikiText(wfMessage('wrreport-deletereport-success', '[[' . $row['page_title'] . '#' . wfMessage('wrreport-reports-sectionname')->text() . '|' . $row['page_title'] . ']]')->text());
                        }
                        if ($action == 'deletepreview') {
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-before')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-before');
                                $format = WRREPORT_COMPACT_PAGE;
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-after')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-after');
                                $row['delete_date'] = date('c');
                                $row['delete_reason_public'] = $delete_reason_public;
                                $row['delete_person_name'] = $delete_person_name;
                                $row['delete_invisible'] = $delete_invisible;
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-form')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-form');
                                $output->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-bottom')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-bottom');
                        }
                }
 
@@ -1343,7 +1383,7 @@ class SpecialWrReport extends SpecialPage {
 
                                // Chech whether identical reports are present
                                if (!$errorMsg) {
-                                       $dbr = wfGetDB(DB_SLAVE);
+                                       $dbr = wfGetDB(DB_REPLICA);
                                        $cond = 'condition';
                                        global $wgDBtype;
                                        if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
@@ -1391,7 +1431,7 @@ class SpecialWrReport extends SpecialPage {
                                // $output->redirect($title->getFullURL() . '#' . wfMessage('wrreport-reports-sectionname')->text());
                        }
                        if ($action == 'preview') {
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-top')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-top');
                                $format = WRREPORT_COMPACT_PAGE;
                                $row = array_fill_keys(wrReportGetColumnNames(), NULL);
                                $row['page_id'] = $page_id;
@@ -1405,13 +1445,13 @@ class SpecialWrReport extends SpecialPage {
                                $row['author_username'] = $author_username;
 
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-middle')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-middle');
                                $output->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $time_report, $condition, $description, $author_name));
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-bottom');
                                if ($wgUser->isLoggedIn())
-                                       $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom-loggedin')->text());
+                                       $output->addWikiMsg('wrreport-newreport-preview-bottom-loggedin');
                                else
-                                       $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom-anonymous')->text());
+                                       $output->addWikiMsg('wrreport-newreport-preview-bottom-anonymous');
                        }
 
                }