// $wgWrReportBlackListAll = array(); // array of page names where reports disallowed for all users. Example: array('Birgitzer Alm (vom Adelshof)');
// $wgWrReportBlackListStrangers = array(); // array of page names where reports are disallowed for not logged in users
// $wgWrReportDeleteMode = 'loggedin'; // 'allow', 'loggedin', 'deny'
-// $wgWrReportFeedRoot = 'http://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
+// $wgWrReportFeedRoot = 'https://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
+// $wgWrReportEnableIntermaps = true; // show Intermaps sledrun information column
+// $wgWrReportIntermapsValidDays = 1; // number of days the last check of the Intermaps data may be in the past
//
//
// The following tags are supported:
/// 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();
/// 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) {
/// 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
'author_name' => $row['author_name'],
'author_username' => (is_null($row['author_userid']) ? NULL : $row['author_username'])));
}
- $dbw->commit();
}
$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');
// $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);
/// $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
///
/// 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;
// -------------------
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();
/// 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);
/// 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'],
+ ['c' => ['JOIN', 'p.page_id=c.page_id'], 's' => ['JOIN', 's.intermaps_sledrun_id=r.intermaps_sledrun_id'], 'BB' => ['LEFT OUTER JOIN', 'p.page_id=s.wr_page_id']]
+ );
global $wgUser;
global $wgWrReportMode; // e.g. 'summer'
global $wgWrReportBlackListAll;
global $wgWrReportBlackListStrangers;
- global $wgDBtype;
+ global $wgWrReportEnableIntermaps;
+ global $wgWrReportIntermapsValidDays;
// Determine, whether the user is allowed to make a new report
$userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
$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' && $wgWrReportEnableIntermaps) $tr->appendElement('th')->appendElement('img', array('src' => '/vorlagen/s_open.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());
$tr->appendElement('th')->appendText(wfMessage('wrreport-sledrun-length')->text());
// Rows
+ $now = new DateTime();
while ($row = $dbr->fetchObject($res)) {
$title = Title::newFromRow($row);
$tr = $table->appendElement('tr');
$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' && $wgWrReportEnableIntermaps) {
+ $td = $tr->appendElement('td');
+ if ($row->show_status) {
+ $date_last_check = new DateTime($row->last_check);
+ if ($date_last_check->diff($now)->days <= $wgWrReportIntermapsValidDays) {
+ if ($row->status == 'open') {
+ $msg = wfMessage('wrreport-icon-intermaps-open', $row->last_update)->text();
+ $td->appendElement('img', array('src' => '/vorlagen/s_open.png', 'alt' => $msg, 'title' => $msg));
+ } elseif ($row->status == 'closed') {
+ $msg = wfMessage('wrreport-icon-intermaps-closed', $row->last_update)->text();
+ $td->appendElement('img', array('src' => '/vorlagen/s_closed.png', 'alt' => $msg, 'title' => $msg));
+ }
+ }
+ }
+ }
+
$tr->appendElement('td')->appendElement('a', array('href' => $title->getLocalURL()))->appendText($title->getPrefixedText());
if ($wgWrReportMode != 'summer') {
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 (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);
// 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');
// 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 {
}
- public static function MobileMenuHook($name, \MobileFrontend\MenuBuilder &$menu) {
+ 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 MobileFrontend\MenuBuilder();
+ $new_menu = new \MediaWiki\Minerva\MenuBuilder();
foreach ($menu->getEntries() as $menuEntryRepresentation) {
$new_entry_name = $menuEntryRepresentation['name'];
if ($new_entry_name == 'random') continue;
}
}
-WrReport::initWrConditions();
}
- 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
// 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