$wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
$wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
$wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
+ $wgParser->setHook('bahnentabelle', 'bahnentabelleParserHook');
return true;
}
if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
else $wikiText = '--';
}
- return wrCommonSandboxParse($wikiText);
+ return wrCommonReplaceByMarker(wrCommonSandboxParse($wikiText), 'wrreports');
+}
+
+
+/// \brief Is called when the tag <bahnentabelle/> is encountered.
+///
+/// Example:
+/// <bahnentabelle>
+/// Birgitzer Alm (vom Adelshof)
+/// Kemater Alm
+/// Axamer Lizum
+/// </bahnentabelle>
+function bahnentabelleParserHook($input, $args, &$parser) {
+ $page_titles = array();
+ foreach (explode("\n", $input) as $page_title) {
+ $page_title = trim($page_title);
+ if (!$page_title) continue;
+ $page_titles[] = str_replace(' ', '_', $page_title);
+ }
+
+ $dbr = wfGetDB(DB_SLAVE);
+ for ($i = 0; $i != count($page_titles); ++$i) $page_titles[$i] = "'" . mysql_escape_string($page_titles[$i]) . "'";
+ // SELECT p.page_id,p.page_title, c.length, c.walktime, c.height_top, c.height_bottom, c.walkup_separate, c.lift, c.night_light, c.public_transport, c.sledge_rental, c.information FROM `page` p, wrsleddingcache 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
+ $res = $dbr->select(array('page', 'wrsleddingcache'), array('page.page_id', 'page.page_title', 'page_namespace', 'length', 'walktime', 'height_top', 'height_bottom', 'walkup_separate', 'lift', 'night_light', 'public_transport', 'sledge_rental', 'information'), array('page.page_title in (' . implode(', ', $page_titles) . ')', 'page.page_id = wrsleddingcache.page_id'), 'bahnentabelleParserHook', array('ORDER BY' => 'page.page_title'));
+
+ global $wrConditions;
+ global $wrNewReportSection; // = utf8_encode('Eintragen');
+ global $wrShowReportsSection; // = utf8_encode('Einträge');
+ 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()));
+ $cond = 'condition';
+ if ($wgDBtype == 'mysql') $cond = "`$cond`"; // "condition" is a reserved word in mysql
+
+ // Title
+ $html = "<table class=\"wikitable\">\n";
+ $html .= utf8_encode('<tr><th>V</th><th>B</th><th>L</th<th>A</th><th>Ö</th><th>Rodelbahn</th>') .
+ ($wgWrReportMode == 'summer' ? '' : '<th>Schneelage</th>') .
+ utf8_encode("<th>Auskunft</th><th>Gehzeit</th><th>Höhe unten</th><th>Höhe oben</th><th>Länge</th></tr>\n");
+
+ // Rows
+ while ($row = $dbr->fetchObject($res)) {
+ $title = Title::newFromRow($row);
+
+ $html .= '<tr><td>' . ($row->sledge_rental ? '<img src="/vorlagen/s_rental.png" alt="Verleih"/>' : '') . '</td>' .
+ '<td>' . ($row->night_light ? '<img src="/vorlagen/s_light.png" alt="Licht"/>' : '') . '</td>' .
+ '<td>' . ($row->lift ? '<img src="/vorlagen/s_lift.png" alt="Lift"/>' : '') . '</td>' .
+ '<td>' . ($row->walkup_separate ? '<img src="/vorlagen/s_walk.png" alt="Aufstieg"/>' : '') . '</td>' .
+ '<td>' . ($row->public_transport ? '<img src="/vorlagen/s_bus.png" alt="Bus/Bahn"/>' : '') . '</td>' .
+ '<td><a href="' . $title->escapeLocalURL() . '">' . $title->getEscapedText() . '</a></td>';
+ if ($wgWrReportMode != 'summer') {
+ // Check rights
+ $userMayReportThis = $userMayReport;
+ if ($userMayReportThis) {
+ if (in_array($title->getText(), $wgWrReportBlackListAll)) $userMayReportThis = FALSE;
+ if (!$wgUser->isLoggedIn() && in_array($title->getText(), $wgWrReportBlackListStrangers)) $userMayReportThis = FALSE; // TODO: Check getText() whether it uses _ or spaces
+ }
+
+ // Select condition
+ // 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;
+ $cres = $dbr->select(
+ 'wrreport',
+ array('wrreport.id as report_id', $cond, 'date_report'),
+ array('page_id' => $row->page_id, "$cond is not null", 'date_invalid > now()', 'delete_date is null'),
+ 'wrReportConditionRender',
+ array('ORDER BY' => 'date_report desc, date_entry desc', 'LIMIT' => '1')
+ );
+ if ($cres->numRows() <= 0) {
+ $condition = NULL;
+ $date = '';
+ } else {
+ $crow = $dbr->fetchObject($cres);
+ $condition = $crow->condition;
+ $date = strftime('%d.%m.', strtotime($crow->date_report));
+ }
+ $dbr->freeResult($cres);
+
+ $html .= '<td>';
+ if (isset($wrConditions[$condition])) {
+ $html .= '<a href="' . $title->escapeLocalURL() . '#' . Title::escapeFragmentForURL($wrShowReportsSection) . '">' . htmlspecialchars($wrConditions[$condition]) . "</a> <small>$date";
+ if ($userMayReportThis) $html .= ' <em><a href="' . $title->escapeLocalURL() . '#' . $wrNewReportSection . '">Neu</a></em>';
+ $html .= '</small>';
+ } else {
+ if ($userMayReportThis) $html .= '<small><em><a href="' . $title->escapeLocalURL() . '#' . $wrNewReportSection . '">Bitte eintragen</em></small>';
+ else $html .= '--';
+ }
+ $html .= '</td>';
+ }
+ $info = $row->information;
+ if ($info) {
+ $info_parts = explode('(', $info, 2);
+ if (count($info_parts) == 2) {
+ $info = htmlspecialchars($info_parts[0]) . '<small>(' . htmlspecialchars($info_parts[1]) . '</small>';
+ } else $info = htmlspecialchars($info);
+ }
+ $html .= "<td>$info</td>" .
+ '<td>' . ($row->walktime ? $row->walktime . ' min' : '') . '</td>' .
+ '<td>' . ($row->height_bottom ? $row->height_bottom . ' m' : '') . '</td>' .
+ '<td>' . ($row->height_top ? $row->height_top . ' m' : '') . '</td>' .
+ '<td>' . ($row->length ? $row->length . ' m' : '') . "</td></tr>\n";
+ }
+ $dbr->freeResult($res);
+
+ $html .= "</table>\n";
+ return wrCommonReplaceByMarker($html, 'wrtable');
}