function wrReportParserInit() {
global $wgParser;
+ wfLoadExtensionMessages('WrReport');
$wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
$wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
$wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
// 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;
-}
-
+/// Forces a regeneration of region overview pages
+function wrRecacheRegions() {
+ // TODO: Better implementation - it's a "quick fix" now.
+ $title = Title::newFromText('Tirol');
+ $title->invalidateCache();
+
+ $title = Title::newFromText('Vorarlberg');
+ $title->invalidateCache();
-/// 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;
+ $title = Title::newFromText('Steiermark');
+ $title->invalidateCache();
}
if ($hide_save_button) $buttons .= ' & Speichern';
$buttons .= '" /> ';
if (!$hide_save_button) $buttons .= '<input name="store" type="submit" value="Speichern"/>';
+
+ $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
+ $title = Title::newFromText($specialPageName, NS_SPECIAL);
+ $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
- // TODO: Get rid of absolute URL
$form = <<<EOT
-<form action="/wiki/Spezial:Bahnberichte" method="post">
+<form action="$specialPageUrl" method="post">
<table class="wrreportform" summary="Formular zum Eintragen eines Rodelbahnberichtes">
<tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_title" value="$page_title"/></td></tr>
<tr class="evenrow"><th>Datum des Rodelns</th>
$delete_reason_public_html = htmlspecialchars($delete_reason_public);
$delete_person_name_html = htmlspecialchars($delete_person_name);
- // TODO: Get rid of absolute URL
+ $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
+ $title = Title::newFromText($specialPageName, NS_SPECIAL);
+ $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
+
$form = <<<EOT
-<form action="/wiki/Spezial:Bahnberichte" method="post">
+<form action="$specialPageUrl" method="post">
<table class="wrreportform" summary="$summary">
<tr class="evenrow"><th>$reason</th><td><textarea name="delete_reason_public" cols="50" rows="7">$delete_reason_public_html</textarea></td></tr>
<tr class="oddrow"><th>Name</th><td><input name="delete_person_name" maxlength="30" size="30" value="$delete_person_name" /></td></tr>
// $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>';
// wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
if ($showActions) {
$out .= '<td>';
- if (!isset($row['delete_date'])) $out .= '<a href="/wiki/Spezial:Bahnberichte?action=deletepreview&reportid=' . $row['id'] . '">' . utf8_encode('Löschen...') . '</a>'; // TODO: Get rid of absolute URL
+ if (!isset($row['delete_date'])) {
+ $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
+ $title = Title::newFromText($specialPageName, NS_SPECIAL);
+ $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
+ $out .= "<a href=\"$specialPageUrl?action=deletepreview&reportid=" . $row['id'] . '">' . utf8_encode('Löschen...') . '</a>';
+ }
$out .= '</td>';
}
return $out . "</tr>\n";
/// $order = 'date_report desc, date_entry desc';
function wrReportGetReports($conditions, $order) {
$dbr = wfGetDB(DB_SLAVE);
- $res = $dbr->select('wrreport', wrReportGetColumnNames(), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
+ $columns = wrReportGetColumnNames();
+ 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, '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);
- $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, 'condition 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) return array(NULL, NULL);
- $row = $dbr->fetchObject($res);
- $res = $dbr->select('wrreport', array('condition', 'date_report'), array('id' => $row->max));
- if ($res->numRows() <= 0) return array(NULL, NULL);
+ $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('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);
+ }
$row = $dbr->fetchObject($res);
$date = $row->date_report;
if ($date) $date = strtotime($date);
+ $dbr->freeResult($res);
return array($row->condition, $date);
}
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"));
- // Ok, we can render the form :-)
- // To prevent cache problems (old prefilled user names shown or old dates in the date list), caching is disabled when showing the form:
- $title = $parser->getTitle();
- $title->invalidateCache(); // I don't know if this helps because the caching is done _after_ the call of this function...
- return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
+ // 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 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 wrCommonSandboxParse($wikiText);
}
// Purge cache
$title->invalidateCache();
+ wrRecacheRegions();
+
// Show success message
global $wrShowReportsSection;
$wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $row['page_title'] . '#' . $wrShowReportsSection . '|' . $row['page_title'] . utf8_encode("]] wurde erfolgreich gelöscht.</div>\n"));
if (!$description) $errorMsg = utf8_encode('Bitte bei der Beschreibung eine kurze Begründung für die Bewertung abgeben.');
elseif (!(stripos($description, 'http') === FALSE)) $errorMsg = utf8_encode('Der Text "http" ist leider für nicht-angemeldete Benutzer nicht erlaubt, weil wir in der Vergangenheit Fälle hatten, bei denen externe Werbelinks automatisiert eingetragen wurden.');
}
+
+ // Chech whether identical reports are present
+ if (!$errorMsg) {
+ $dbr = wfGetDB(DB_SLAVE);
+ $cond = 'condition';
+ global $wgDBtype;
+ if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
+ $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, $cond => $condition, 'description' => $description, 'author_name' => $author_name);
+ $res = $dbr->select('wrreport', 'id', $sqlConditions);
+ if ($res->numRows() == 1) $errorMsg = utf8_encode('Der Rodelbahnbericht wurde bereits früher gespeichert.');
+ $dbr->freeResult($res);
+ }
+
+ // Show error if any
if ($errorMsg) {
$this->execute($par, 'preview', $errorMsg);
return;
'page_id' => $page_id,
'page_title' => $page_title,
'date_report' => $date_report,
- // 'date_entry' => '', // use database default
- // 'date_invalid' => '', // use database default
- 'condition' => $condition,
+ 'date_entry' => date('c'),
+ 'date_invalid' => date('c', strtotime('+9 days')),
+ $cond => $condition,
'description' => $description,
'author_name' => $author_name,
'author_ip' => $_SERVER['REMOTE_ADDR'],
// Purge cache
$title->invalidateCache();
+ wrRecacheRegions();
+
// Show success message
global $wrShowReportsSection;
$wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n"));