$wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
$wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
$wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
+ $wgParser->setHook('bahnentabelle', 'bahnentabelleParserHook');
return true;
}
// Tool functions
// --------------
-/// \brief This function is used to translate WikiText to HTML. Normally it should be avoided to do this
-/// but I found situations where I did not find an other possibility.
-function wrReportSandboxParse($wikiText) {
- global $wgTitle, $wgUser;
- $myParser = new Parser();
- $myParserOptions = new ParserOptions();
- $myParserOptions->initialiseFromUser($wgUser);
- $result = $myParser->parse($wikiText, $wgTitle, $myParserOptions);
- return $result->getText();
-}
-
-
-/// List of markers - used by the functions replaceByMarker and wrReportAfterTidy
-$wrReportMarkerList = array();
-
-
-/// Returns a marker for a text and back-replaces the text in wrReportAfterTidy
-function replaceByMarker($text, $marker = 'marker') {
- $marker = $marker . mt_rand(1e5, 1e7);
- global $wrReportMarkerList;
- $wrReportMarkerList[$marker] = $text;
- return $marker;
-}
-
-
-/// Replaces the markers by its contents
-function wrReportAfterTidy(&$parser, &$text) {
- // find markers in $text
- // replace markers with actual output
- global $wrReportMarkerList;
- foreach ($wrReportMarkerList as $marker => $html) $text = str_replace($marker, $html, $text);
- return true;
-}
-
-
-/// Forces a regeneration of region overview pages
+/// Forces a regeneration of region overview pages ('Tirol', 'Vorarlberg', ...)
function wrRecacheRegions() {
- // TODO: Better implementation - it's a "quick fix" now.
- $title = Title::newFromText('Tirol');
- $title->invalidateCache();
-
- $title = Title::newFromText('Vorarlberg');
- $title->invalidateCache();
+ $dbr = wfGetDB(DB_SLAVE);
+ // SELECT cl_from FROM categorylinks where cl_to = 'Region'
+ $res = $dbr->select('categorylinks', 'cl_from', array('cl_to' => 'Region'));
+ $page_ids = array();
+ while ($row = $dbr->fetchObject($res)) $page_ids[] = $row->cl_from;
+ $dbr->freeResult($res);
- $title = Title::newFromText('Steiermark');
- $title->invalidateCache();
+ $titles = Title::newFromIDs($page_ids);
+ foreach ($titles as $title) $title->invalidateCache();
}
// $id
if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
// $page_title
- if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
+ if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrCommonSandboxParse('[[' . $page_title . ']]') . '</td>';
// $date_report
$dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
$date_report = strtotime($date_report);
// $description
$out .= '<td class="wrreportdescription">';
if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
- else $out .= wrReportSandboxParse($description);
+ else $out .= wrCommonSandboxParse($description);
$out .= '</td>';
// $author_name
$out .= '<td>';
global $wgDBtype;
if ($wgDBtype == "mysql") // "condition" is a reserved word in mysql
for ($i = 0; $i != count($columns); ++$i) $columns[$i] = sprintf('`%s`', $columns[$i]);
- $res = $dbr->select('wrreport', $columns, $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
+ $res = $dbr->select('wrreport', $columns, $conditions, 'wrReportGetReports', array('ORDER BY' => 'date_report desc, date_entry desc'));
$result = array();
while ($row = $dbr->fetchRow($res)) $result[] = $row;
$dbr->freeResult($res);
}
-/// \brief It returns an array of the "condition" (as number) and the date of the "most recent" report of the specified page (to decode as list($condition, $date);
+/// \brief It returns an array of the "condition" (as number) and the date of the "most recent" report of the specified page (to decode as list($condition, $date));
///
/// If no condition is present, array(NULL, NULL) is returned
function wrReportConditionRender($page_title) {
$dbr = wfGetDB(DB_SLAVE);
$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;
if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
- $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, "$cond is not null", 'date_invalid > now()'));
- // select condition, date_report from wrreport where id = (select max(wrreport.id) as max from wrreport where page_title='Birgitzer Alm (vom Adelshof)' and date_invalid > now() and condition is not null);
- if ($res->numRows() <= 0) {
- $dbr->freeResult($res);
- return array(NULL, NULL);
- }
- $row = $dbr->fetchObject($res);
- $dbr->freeResult($res);
- $res = $dbr->select('wrreport', array($cond, 'date_report'), array('id' => $row->max));
+ $res = $dbr->select(
+ 'wrreport',
+ array('wrreport.id as report_id', $cond, 'date_report'),
+ array('page_title' => $page_title, "$cond is not null", 'date_invalid > now()', 'delete_date is null'),
+ 'wrReportConditionRender',
+ array('ORDER BY' => 'date_report desc, date_entry desc', 'LIMIT' => '1')
+ );
if ($res->numRows() <= 0) {
$dbr->freeResult($res);
return array(NULL, NULL);
global $wgWrReportMode;
global $wgWrReportBlackListAll;
global $wgWrReportBlackListStrangers;
- if ($wgWrReportMode == 'summer') return wrReportSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n"));
- if ($wgWrReportMode == 'deny') return wrReportSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n"));
+ if ($wgWrReportMode == 'summer') return wrCommonSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n"));
+ if ($wgWrReportMode == 'deny') return wrCommonSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n"));
- if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrReportSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
+ if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrCommonSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
- if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrReportSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
- if (!$wgUser->isLoggedIn() && in_array($parser->getTitle()->getText(), $wgWrReportBlackListStrangers)) return wrReportSandboxParse(utf8_encode("''Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.''\n\n"));
+ if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrCommonSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
+ if (!$wgUser->isLoggedIn() && in_array($parser->getTitle()->getText(), $wgWrReportBlackListStrangers)) return wrCommonSandboxParse(utf8_encode("''Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.''\n\n"));
// Calling "$title = $parser->getTitle(); $title->invalidateCache();" doesn't help here to force regeneration
// However, this would not be the best solution because the page has to be re-rendered only at midnight
// In the following line, $author_name was replaced by NULL to prevent a bug, where the wrong author_name
// is shown (see ticket #35). TODO: Find reason.
- // return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
- return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL));
+ // return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name), 'wrform');
+ return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL), 'wrform');
}
$conditions = array('page_title' => $page_title, 'date_invalid > now()');
$order = 'date_report desc, date_entry desc';
$rows = wrReportGetReports($conditions, $order);
- if (count($rows) == 0) return wrReportSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
+ if (count($rows) == 0) return wrCommonSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete());
}
if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
else $wikiText = '--';
}
- return wrReportSandboxParse($wikiText);
+ return wrCommonReplaceByMarker(wrCommonSandboxParse($wikiText), 'wrreports', FALSE);
+}
+
+
+/// \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');
}
// $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
}
if ($action == 'preview') {
- $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
+ $wgOut->addWikiText(wfMsg('wrreportnewreportpreviewtop'));
$format = WRREPORT_COMPACT_PAGE;
$row = array_fill_keys(wrReportGetColumnNames(), NULL);
$row['page_title'] = $page_title;
$row['description'] = $description;
$row['author_name'] = $author_name;
$wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
- $wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
+ $wgOut->addWikiText(wfMsg('wrreportnewreportpreviewmiddle'));
$wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
+ $wgOut->addWikiText(wfMsg('wrreportnewreportpreviewbottom'));
}
}