}
+/// \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);
+
+ $form = <<<EOT
+<form action="/wiki/Spezial:Bahnberichte" 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;
+}
+
+
/// \brief sub-function of wrReportTableRender - renders the table head
///
/// The input variables are either NULL (-> the column is not present) or a UTF-8 encoded string (that is ignored ;-) ).
/// \return UTF-8 encoded titles of HTML table
-function wrReportTableTitleRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
+/// \todo: Delete
+function wrReportTableTitleRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name, $delete = NULL) {
$out = '<tr>';
if ($page_id) $out .= '<th>ID</th>';
if ($page_title) $out .= '<th>Bahn</th>';
if ($condition) $out .= '<th>Zustand</th>';
if ($description) $out .= '<th>Beschreibung</th>';
if ($author_name) $out .= '<th>Autor</th>';
+ if ($delete) $out .= '<th>Aktion</th>';
return utf8_encode($out . "</tr>\n");
}
/// \brief sub-function of wrReportTableRender - renders a table row
///
-/// 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) {
+/// * The in- and output parameters are expected to be UTF-8 encoded.
+/// * If one parameter is NULL, the corresponding column is omitted.
+/// \param $page_id
+/// \param $page_title
+/// \param $date_report
+/// \param $date_entry
+/// \param $date_invalid
+/// \param $condition
+/// \param $description
+/// \param $author_name
+/// \param $delete
+/// \todo delete
+function wrReportTableRowRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name, $delete = NULL) {
$out = "<tr>";
if (!is_null($page_id)) $out .= '<td>' . $page_id . '</td>';
if (!is_null($page_title)) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
$out .= '<td>' . htmlspecialchars($condition_text) . '</td>';
$out .= '<td class="wrreportdescription">' . wrReportSandboxParse($description) . '</td>';
$out .= '<td>' . htmlspecialchars($author_name) . '</td>';
+ if (!is_null($delete)) $out .= '<td>(Löschen)</td>';
$out .= "</tr>\n";
return $out;
}
/// 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
+/// \todo delte
function wrReportTableRender($page_title = NULL) {
$out = '';
$dbr = wfGetDB(DB_SLAVE);
}
+// 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 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 wrReportTableTitleRender2($format, $showActions) {
+ $out = '<tr>';
+ 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");
+}
+
+
+/// \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>' . wrReportSandboxParse('[[' . $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>';
+ // $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 .= wrReportSandboxParse($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
+ if ($showActions) $out .= '<td>' . utf8_encode('(Löschen)') . '</td>';
+ return $out . "</tr>\n";
+}
+
+
+/// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
+///
+/// \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);
+ $res = $dbr->select('wrreport', wrReportGetColumnNames(), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
+ $result = array();
+ while ($row = $dbr->fetchRow($res)) $result[] = $row;
+ $dbr->freeResult($res);
+ 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);
///
/// If no condition is present, array(NULL, NULL) is returned
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 == 'loggedin' && !$wgUser->isLoggedIn()) return wrReportSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
+
+ // The following was changed because for testing purposes, we have 'loggedin' instead of 'summer' in the $wgWrReportMode. TODO: Change back!
+ // 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 wrReportSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\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"));
return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
///
/// The current page name is taken.
function bahnberichteParserHook($input, $args, &$parser) {
- return wrReportTableRender($parser->getTitle()->getText());
+ return wrReportTableRender($parser->getTitle()->getText()); // TODO: Replace
}
/// - 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;
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"));
+ if ($errorMsg || $action == 'showerror') {
+ $wgOut->addWikiText('<div class="errorbox">' . $errorMsg . "</div>\n");
+ if ($action == 'showerror') return;
}
// Action view
if ($action == 'view') {
- $wgOut->addHTML(wrReportTableRender());
+ $wgOut->addHTML(wrReportTableRender()); // TODO: Replace
+ }
+
+ elseif ($action == 'test') { // TODO: delete
+ $conditions = array('page_title' => 'Axamer Lizum', 'date_invalid > now()');
+ $order = 'date_report desc, date_entry desc';
+ $rows = wrReportGetReports($conditions, $order);
+ $format = WRREPORT_COMPACT_PAGE; // WRREPORT_COMPACT WRREPORT_DETAIL
+ $format = WRREPORT_DETAIL;
+ $wgOut->addHTML(wrReportTableRender2($rows, $format, True));
+ $wgOut->addHTML('OK');
+ }
+
+ // 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;
+ }
+ // $row = array_fill_keys(wrReportGetColumnNames(), NULL); // TODO: Delete
+ $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
+ $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, 'preview', $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();
+ // 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') {
+ $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 (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("<table class=\"wrreporttable\">\n");
+ $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
+ $wgOut->addHTML("</table>");
+ $wgOut->addWikiText("\n");
+ $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