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();
}
function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
if ($page_title) $page_title = htmlspecialchars($page_title);
// Date options
- $tagnamen = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
+ $daynames = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
$date_options = '';
- $date_selected = FALSE;
- for ($tag=0; $tag!=5; ++$tag) {
- $datum = time() - $tag*24*60*60;
- $datum_f = strftime("%Y-%m-%d", $datum);
- $date_options .= '<option value="' . $datum_f . '"';
- // var_dump($date_report);
- // var_dump($datum_f);
- if ((is_null($date_report) && $tag == 0) || (!is_null($date_report) && $date_report == $datum_f)) {
+ $date_selected = false;
+ $time = time(); // number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
+ for ($day=0; $day!=5; ++$day) {
+ $date = strtotime("-$day days", $time);
+ $date_f = strftime("%Y-%m-%d", $date); // Formats it according to locale, that is set to CET.
+ $date_options .= '<option value="' . $date_f . '"';
+ if ((is_null($date_report) && $day == 0) || (!is_null($date_report) && $date_report == $date_f)) {
$date_options .= ' selected="selected"';
- $date_selected = TRUE;
+ $date_selected = true;
}
- $date_options .= '>' . htmlspecialchars($tagnamen[$tag]) . ' (' . strftime('%d.%m.', $datum) . ')</option>' . "\n";
+ $date_options .= '>' . htmlspecialchars($daynames[$day]) . ' (' . strftime('%d.%m.', $date) . ')</option>' . "\n";
}
if (!$date_selected) {
$date_options = '<option value="' . $date_report . '" selected="selected">' . htmlspecialchars($date_report) . "</option>\n" . $date_options;
// Condition options
$condition_options = '';
- $condition_array = array(1 => 'Sehr gut', 2 => 'Gut', 3 => 'Mittelmäßig', 4 => 'Schlecht', 5 => 'Geht nicht');
- $condition_options .= '<option value="">(keine Beurteilung)</option>' . "\n";
- foreach ($condition_array as $condition_num => $condition_text) {
+ global $wrConditions; // $wrConditions = array(1 => 'Sehr gut', 2 => 'Gut', 3 => utf8_encode('Mittelmäßig'), 4 => 'Schlecht', 5 => 'Geht nicht');
+ $condition_options .= utf8_encode('<option value="">(keine Beurteilung)</option>') . "\n";
+ foreach ($wrConditions as $condition_num => $condition_text) {
$condition_options .= "<option value=\"$condition_num\"";
if ($condition == $condition_num) $condition_options .= ' selected="selected"';
- $condition_options .= '>' . htmlspecialchars(utf8_encode($condition_text)) . "</option>\n";
+ $condition_options .= '>' . htmlspecialchars($condition_text) . "</option>\n";
}
- $description = htmlspecialchars($description);
+ $description_html = htmlspecialchars($description);
// Buttons
- $buttons = '<button name="action" type="submit" value="preview">Vorschau';
- if ($hide_save_button) $buttons .= ' & Speichern';
- $buttons .= '</button>';
- if (!$hide_save_button) $buttons .= '<button name="action" type="submit" value="store">Speichern</button>';
+ // I would like to do it this way, but due to a bug of internet explorer, the <button> element is not useable.
+ // $buttons = '<button name="action" type="submit" value="preview">Vorschau';
+ // if ($hide_save_button) $buttons .= ' & Speichern';
+ // $buttons .= '</button>';
+ // if (!$hide_save_button) $buttons .= '<button name="action" type="submit" value="store">Speichern</button>';
+ // Workaround: User <input type="submit"/>
+ $buttons = '<input name="preview" type="submit" value="Vorschau';
+ 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'
$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>
<tr class="oddrow"><th>Bahnzustand*</th><td><select name="condition">
$condition_options
</select></td></tr>
- <tr class="evenrow"><th>Meinung</th><td><textarea name="description" cols="50" rows="7">$description</textarea></td></tr>
+ <tr class="evenrow"><th>Meinung</th><td><textarea name="description" cols="50" rows="7">$description_html</textarea></td></tr>
<tr class="oddrow"><th>Autor/in</th><td><input name="author_name" maxlength="30" size="30" value="$author_name" /></td></tr>
<tr class="evenrow"><th>Bericht abschicken</th><td>$buttons</td></tr>
</table>
}
+/// \brief Renders the form to delete a report
+///
+/// All in and output strings should be/are UTF-8 encoded.
+function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible) {
+ // Buttons
+ $buttons = '<input name="deletepreview" type="submit" value="Vorschau" /> ';
+ $buttons .= utf8_encode('<input name="delete" type="submit" value="Löschen"/>');
+ $buttons .= '<input name="reportid" type="hidden" value="' . $reportid . '"/>';
+ // $buttons .= '<input name="delete_invisible" type="hidden" value="' . $delete_invisible . '"/>'; // who is allowed to do so?
+ $summary = utf8_encode('Formular zum Löschen eines Schneelageberichtes');
+ $reason = utf8_encode('Begründung');
+ $delete_reason_public_html = htmlspecialchars($delete_reason_public);
+ $delete_person_name_html = htmlspecialchars($delete_person_name);
+
+ $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
+ $title = Title::newFromText($specialPageName, NS_SPECIAL);
+ $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
+
+ $form = <<<EOT
+<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>
+ <tr class="evenrow"><th>Aktion</th><td>$buttons</td></tr>
+</table>
+</form>
+EOT;
+ return $form;
+}
+
+
+
+// Constants for wrReportTableRender2
+define(WRREPORT_COMPACT_PAGE, 1); ///< includes the page name
+define(WRREPORT_COMPACT, 2); ///< shown on a single page
+define(WRREPORT_DETAIL, 3); ///< more columns
-/// \brief sub-function of wrRenderReportTable
+/// \brief Renders a table header ("private" sub-function of wrReportTableRender2)
+///
+/// \param $format row format like WRREPORT_COMPACT
+/// \param $showActions boolean to indicate whether an actions column should be created
/// \return UTF-8 encoded titles of HTML table
-function wrReportTableTitleRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
+function wrReportTableTitleRender2($format, $showActions) {
$out = '<tr>';
- if ($page_id) $out .= '<th>ID</th>';
- if ($page_title) $out .= '<th>Bahn</th>';
- if ($date_report) $out .= '<th>Datum</th>';
- if ($date_entry) $out .= '<th>Datum Eintrag</th>';
- if ($date_invalid) $out .= '<th>Datum Ungültig</th>';
- if ($condition) $out .= '<th>Zustand</th>';
- if ($description) $out .= '<th>Beschreibung</th>';
- if ($author_name) $out .= '<th>Autor</th>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>ID</th>';
+ if ($format != WRREPORT_COMPACT) $out .= '<th>Bahn</th>';
+ $out .= '<th>Datum</th>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Eintrag</th>';
+ if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Ungültig</th>';
+ $out .= '<th>Zustand</th>';
+ $out .= '<th>Beschreibung</th>';
+ $out .= '<th>Autor</th>';
+ if ($showActions) $out .= '<th>Aktion</th>';
return utf8_encode($out . "</tr>\n");
}
-/// sub-function of wrRenderReportTable
-/// The in- and output parameters are expected to be UTF-8 encoded
-function wrReportTableRowRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
- $out = "<tr>";
- if (!is_null($page_id)) $out .= '<td>' . $page_id . '</td>';
- if (!is_null($page_title)) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
+/// \brief Renders a table row ("private" sub-function of wrReportTableRender2)
+///
+/// \param $row associative array of table columns like one row in the wrreport table
+/// \param $format row format like WRREPORT_COMPACT
+/// \param $showActions boolean to indicate whether an actions column should be created
+/// \return UTF-8 encoded titles of HTML table
+function wrReportTableRowRender2($row, $format, $showActions) {
+ extract($row);
+
+ $out = '<tr>';
+ // $id
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
+ // $page_title
+ 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);
+ $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
$out .= '<td>' . $date_report . '</td>';
- if (!is_null($date_entry)) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
- if (!is_null($date_invalid)) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
- $out .= '<td>' . $condition . '</td>';
- $out .= '<td>' . htmlspecialchars($description) . '</td>';
- $out .= '<td>' . htmlspecialchars($author_name) . '</td>';
- $out .= "</tr>\n";
- return $out;
+ // $date_entry
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
+ // $date_invalid
+ if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
+ // $condition
+ global $wrConditions;
+ $condition_text = '---';
+ if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
+ $out .= '<td>';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= htmlspecialchars($condition_text);
+ $out .= '</td>';
+ // $description
+ $out .= '<td class="wrreportdescription">';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= wrCommonSandboxParse($description);
+ $out .= '</td>';
+ // $author_name
+ $out .= '<td>';
+ if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
+ else $out .= htmlspecialchars($author_name);
+ $out .= '</td>';
+ // actions
+ // wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
+ if ($showActions) {
+ $out .= '<td>';
+ 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";
}
-/// \brief It returns a table (string containing HTML) showing the results.
+/// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
///
-/// Is called when the tag <bahnberichte/> is encounted and renders a table /
-/// \param $page_title If the name is specified (UTF-8 encoded), only reports of this "page" (e.g. 'Birgitzer Alm') is shown. Default: NULL
-/// \return UTF-8 encoded HTML result table
-function wrReportTableRender($page_title = NULL) {
- $out = '';
+/// \param $rows array of associative row arrays
+/// \param $format row format like WRREPORT_TABLE_SHORT
+function wrReportTableRender2($rows, $format, $showActions) {
+ $out = "<table class=\"wrreporttable\">\n" . wrReportTableTitleRender2($format, $showActions);
+ foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
+ return $out . "</table>\n";
+}
+
+
+/// Returns an array with column names
+function wrReportGetColumnNames() {
+ return array('id', 'page_id', 'page_title', 'date_report', 'date_entry', 'date_invalid', 'condition', 'description', 'author_name', 'author_username', 'delete_date', 'delete_person_name', 'delete_person_ip', 'delete_person_userid', 'delete_person_username', 'delete_reason_public', 'delete_invisible');
+}
+
+
+/// \brief Returns reports as associative array.
+///
+/// Examples:
+/// $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
+/// $order = 'date_report desc, date_entry desc';
+function wrReportGetReports($conditions, $order) {
$dbr = wfGetDB(DB_SLAVE);
- $conditions = array();
- if ($page_title) $conditions['page_title'] = $page_title;
- $res = $dbr->select('wrreport', array('id', 'page_title', 'date_report', 'date_entry', 'date_invalid', 'condition', 'description', 'author_name', 'author_username'), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report, date_entry'));
- $admin = is_null($page_title);
- if ($res->numRows() > 0) {
- $out .= "<table class=\"wrreporttable\">\n";
- $out .= wrReportTableTitleRender($admin, $admin, TRUE, $admin, $admin, TRUE, TRUE, TRUE);
- while ($row = $dbr->fetchObject($res)) {
- $author = $row->author_name;
- $out .= wrReportTableRowRender($admin ? $row->id : NULL, $admin ? $row->page_title : NULL, $row->date_report, $admin ? $row->date_entry : NULL, $admin ? $row->date_invalid : NULL, $row->condition, $row->description, $author);
- }
- $out .= "</table>\n";
- } else {
- $out .= "<p>Es wurden keine Bahnberichte in der Datenbank gefunden.</p>\n";
- }
+ $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);
- return $out;
+ return $result;
}
-/// \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);
- return array($row->condition, $row->date_report);
+ $date = $row->date_report;
+ if ($date) $date = strtotime($date);
+ $dbr->freeResult($res);
+ return array($row->condition, $date);
+}
+
+
+/// \brief Returns true if the user is allowed to delete reports (in general)
+function wrReportUserMayDelete() {
+ global $wgUser;
+ global $wgWrReportDeleteMode;
+ return $wgWrReportDeleteMode == 'allow' || ($wgWrReportDeleteMode == 'loggedin' && $wgUser->isLoggedIn());
}
+
// Parser Hook Functions
// ---------------------
///
/// The current page name is taken.
function bahnberichtformularParserHook($input, $args, $parser) {
+ // Username
global $wgUser;
$author_name = NULL;
if ($wgUser->isLoggedIn()) {
$author_name = $wgUser->getRealName();
if (!$author_name) $author_name = $wgUser->getName();
}
- return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
+
+ global $wgWrReportMode;
+ global $wgWrReportBlackListAll;
+ global $wgWrReportBlackListStrangers;
+ 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 wrCommonSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\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 wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name), 'wrform');
+ return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL), 'wrform');
}
///
/// The current page name is taken.
function bahnberichteParserHook($input, $args, &$parser) {
- return wrReportTableRender($parser->getTitle()->getText());
+ $page_title = $parser->getTitle()->getText();
+ $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 wrCommonSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
+ return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete());
}
/// * <bahnbewertung/>: The current page name is taken.
/// * <bahnbewertung>page_name</bahnbewertung>: The given page name is taken.
function bahnbewertungParserHook($input, $args, &$parser) {
- if (!$input) $input = $parser->getTitle()->getText();
- list($condition, $date) = wrReportConditionRender($input);
- return "$condition ($date)";
+ $titleText = $input;
+ if (!$titleText) $titleText = $parser->getTitle()->getText();
+ list($condition, $date) = wrReportConditionRender($titleText);
+ if ($date) $date = strftime('%d.%m.', $date);
+ global $wrConditions;
+ global $wrNewReportSection; // = utf8_encode('Eintragen');
+ global $wrShowReportsSection; // = utf8_encode('Einträge');
+ global $wgUser;
+ global $wgWrReportMode; // e.g. 'summer'
+ global $wgWrReportBlackListAll;
+ global $wgWrReportBlackListStrangers;
+
+ // Determine, whether the user is allowed to make a new report
+ $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
+ if ($userMayReport) {
+ if (in_array($titleText, $wgWrReportBlackListAll)) $userMayReport = false;
+ if (!$wgUser->isLoggedIn() && in_array($titleText, $wgWrReportBlackListStrangers)) $userMayReport = false;
+ }
+
+ // Get the condition and create the response wiki text
+ if (isset($wrConditions[$condition])) {
+ $wikiText = '[['. $titleText . '#' . $wrShowReportsSection . '|'. $wrConditions[$condition] . "]] <small>$date";
+ if ($userMayReport) $wikiText .= " ''[[" . $titleText . '#' . $wrNewReportSection . "|Neu]]''";
+ $wikiText .= "</small>";
+ } else {
+ if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
+ else $wikiText = '--';
+ }
+ return wrCommonSandboxParse($wikiText);
}
/// - action == 'view' (default)
/// - action == 'preview': Preview new report
/// - action == 'store': Store new report
- /// \param $override_action If not NULL (defualt), it overrides the action in $par
+ /// - action == 'deletepreview': Preview the deleted record
+ /// - action == 'delete': Delete an existing report
+ /// - action == 'showerror': Shows the error and exits
+ /// \param $override_action If not NULL (default), it overrides the action in $par
/// \param $errorMsg UFT-8 encoded error message (in WikiText) to show on top of the page or NULL (default):
function execute($par, $override_action = NULL, $errorMsg = NULL) {
global $wgRequest, $wgOut;
// Get request data
$action = $wgRequest->getText('action');
- if ($action === '') $action = 'view';
+ if (!$action) {
+ if ($wgRequest->getVal('preview')) $action = 'preview';
+ elseif ($wgRequest->getVal('store')) $action = 'store';
+ elseif ($wgRequest->getVal('deletepreview')) $action = 'deletepreview';
+ elseif ($wgRequest->getVal('delete')) $action = 'delete';
+ else $action = 'view';
+ }
if ($override_action) $action = $override_action;
// Show error message
- if ($errorMsg) {
- $wgOut->addWikiText(utf8_encode('<div class="errorbox">') . $errorMsg . utf8_encode("</div>\n\n"));
+ if ($errorMsg || $action == 'showerror') {
+ $wgOut->addWikiText('<div class="errorbox">' . $errorMsg . "</div>\n");
+ if ($action == 'showerror') return;
}
// Action view
if ($action == 'view') {
- $wgOut->addHTML(wrRenderReportTable());
+ $conditions = array('date_invalid > now()');
+ $order = 'date_entry desc, date_report desc';
+ $rows = wrReportGetReports($conditions, $order);
+ if (count($rows) == 0) $wgOut->addWikiText("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
+ $wgOut->addHTML(wrReportTableRender2($rows, WRREPORT_DETAIL, wrReportUserMayDelete()));
+ }
+
+ // Action deletepreview or delete
+ elseif ($action == 'deletepreview' || $action == 'delete') {
+ $reportid = (int) $wgRequest->getText('reportid');
+ if ($reportid == 0) {
+ $this->execute($par, 'showerror', utf8_encode('Es wurde kein Bericht zum Löschen ausgewählt.'));
+ return;
+ }
+ $rows = wrReportGetReports(array('id' => $reportid), '');
+ if (count($rows) != 1) {
+ $this->execute($par, 'showerror', utf8_encode('Es wurde ein ungültiger Bericht zum Löschen ausgewählt.'));
+ return;
+ }
+ $row = $rows[0];
+ if (!is_null($row['delete_date'])) {
+ $this->execute($par, 'showerror', utf8_encode('Der angegebende Bericht ist bereits gelöscht.'));
+ return;
+ }
+ $delete_reason_public = $wgRequest->getText('delete_reason_public');
+ $delete_person_name = $wgRequest->getText('delete_person_name');
+ $delete_invisible = $wgRequest->getText('delete_invisible') ? TRUE : FALSE;
+ if ($action == 'delete') {
+ // page
+ $title = Title::newFromId($row['page_id']);
+
+ // user
+ global $wgUser;
+ $delete_person_userid = $wgUser->getId();
+ if ($delete_person_userid == 0) $delete_person_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
+ $delete_person_username = $wgUser->getName();
+
+ // Check permissions - see also function wrReportUserMayDelete, that does also check permissions but does not return an error message.
+ $errorMsg = NULL;
+ global $wgWrReportDeleteMode;
+ if ($wgWrReportDeleteMode == 'deny') $errorMsg = utf8_encode('Das Löschen von Rodelbahnberichten ist derzeit leider nicht erlaubt.');
+ elseif ($wgWrReportDeleteMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit dürfen nur angemeldete Benutzer Rodelbahnberichte löschen.');
+ elseif (!$delete_person_name || !$delete_reason_public) $errorMsg = utf8_encode('Es müssen sowohl die Begründung als auch der Name angegeben werden.');
+ if ($errorMsg) {
+ $this->execute($par, 'deletepreview', $errorMsg);
+ return;
+ }
+
+ // "Delete" (update) entry
+ $dbr = wfGetDB(DB_MASTER);
+ $dbr->update(
+ 'wrreport',
+ array(
+ 'delete_date' => date('c'),
+ 'delete_person_name' => $delete_person_name,
+ 'delete_person_ip' => $_SERVER['REMOTE_ADDR'],
+ 'delete_person_userid' => $delete_person_userid,
+ 'delete_person_username' => $delete_person_username,
+ 'delete_reason_public' => $delete_reason_public,
+ 'delete_invisible' => $delete_invisible ? 't' : 'f'
+ ),
+ array('id' => $reportid)
+ );
+
+ // 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 ($action == 'deletepreview') {
+ $preview_msg = "Bitte nur dann einen Bericht löschen, wenn Gründe vorliegen wie\n" .
+ "* Beschimpfungen, Verleumdungen (wir wollen ''Rodelbahnen'' bewerten, nicht Personen)\n" .
+ "* Werbung oder Spam (wenn jemand allerdings ''werbend'' zu gute Noten vergibt, lieber eigenen Bericht eintragen als löschen).\n\n";
+ $wgOut->addWikiText(utf8_encode($preview_msg));
+ $wgOut->addWikiText(utf8_encode("== Schneelagebericht, um den es beim Löschen geht ==\n"));
+ $format = WRREPORT_COMPACT_PAGE;
+ $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
+ $wgOut->addWikiText(utf8_encode("\n\n== Vorschau (derzeit noch nicht gelöscht) ==\n"));
+ $row['delete_date'] = date('c');
+ $row['delete_reason_public'] = $delete_reason_public;
+ $row['delete_person_name'] = $delete_person_name;
+ $row['delete_invisible'] = $delete_invisible;
+ $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
+ $wgOut->addWikiText(utf8_encode("== Löschen ==\n"));
+ $wgOut->addWikiText(utf8_encode("Die Begründung und der Name scheinen nicht in den normalen Listen auf, allerdings dienen sie den Administratoren dazu, sich schnell einen Überblick zu verschaffen, wer was warum gelöscht hat.\n"));
+ $wgOut->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
+ }
}
// Action preview or store
// check conditions/permissions
$errorMsg = NULL;
- if (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
+ global $wgWrReportMode;
+ global $wgWrReportBlackListAll;
+ global $wgWrReportBlackListStrangers;
+ if ($wgWrReportMode == 'summer') $errorMsg = utf8_encode('Rodelbahnberichte sind in der schneefreien Zeit nicht erlaubt.');
+ elseif ($wgWrReportMode == 'deny') $errorMsg = utf8_encode('Rodelbahnberichte sind derzeit leider nicht erlaubt.');
+ elseif ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.');
+ elseif (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
+ elseif (in_array($page_title, $wgWrReportBlackListAll)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit keine Rodelbahnberichte abgegeben werden.');
+ elseif (!$wgUser->isLoggedIn() && in_array($page_title, $wgWrReportBlackListStrangers)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.');
+ elseif (!$condition && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung leer/nicht vergeben.');
elseif (!$wgUser->isLoggedIn()) {
- if (!(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.');
+ 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'],
'author_userid' => $author_userid,
'author_username' => $author_username
+ // 'delete_*' => // use database defaults (NULL)
)
);
// Purge cache
$title->invalidateCache();
+ wrRecacheRegions();
+
// Show success message
- $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . utf8_encode('#Einträge|') . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n\n"));
+ 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"));
// We could redirect to result with the following line but we don't want to.
// $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
}
if ($action == 'preview') {
$wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
- $wgOut->addHTML("<table class=\"wrreporttable\">\n");
- $wgOut->addHTML(wrReportTableTitleRender(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE));
- $wgOut->addHTML(wrReportTableRowRender(NULL, $page_title, $date_report, NULL, NULL, $condition, $description, $author_name));
- $wgOut->addHTML("</table>");
- $wgOut->addWikiText("\n");
+ $format = WRREPORT_COMPACT_PAGE;
+ $row = array_fill_keys(wrReportGetColumnNames(), NULL);
+ $row['page_title'] = $page_title;
+ $row['date_report'] = $date_report;
+ $row['condition'] = $condition;
+ $row['description'] = $description;
+ $row['author_name'] = $author_name;
+ $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
$wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
$wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
}