+
+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 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 wrRenderReportTableTitle($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
+function wrReportTableTitleRender2($format, $showActions) {
$out = '';
- if ($page_id) $out .= 'ID | ';
- if ($page_title) $out .= 'Bahn | ';
- if ($date_report) $out .= 'Datum | ';
- if ($date_entry) $out .= 'Datum Eintrag | ';
- if ($date_invalid) $out .= 'Datum Ungültig | ';
- if ($condition) $out .= 'Zustand | ';
- if ($description) $out .= 'Beschreibung | ';
- if ($author_name) $out .= 'Autor | ';
+ if ($format == WRREPORT_DETAIL) $out .= 'ID | ';
+ if ($format != WRREPORT_COMPACT) $out .= 'Bahn | ';
+ $out .= 'Datum | ';
+ if ($format == WRREPORT_DETAIL) $out .= 'Datum Eintrag | ';
+ if ($format == WRREPORT_DETAIL) $out .= 'Datum Ungültig | ';
+ $out .= 'Zustand | ';
+ $out .= 'Beschreibung | ';
+ $out .= 'Autor | ';
+ if ($showActions) $out .= 'Aktion | ';
return utf8_encode($out . "
\n");
}
-/// sub-function of wrRenderReportTable
-function wrRenderReportTableRow($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
- $out = "";
- if (!is_null($page_id)) $out .= '' . $page_id . ' | ';
- if (!is_null($page_title)) $out .= '' . wrReportSandboxParse('[[' . $page_title . ']]') . ' | ';
+/// \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 = '
';
+ // $id
+ if ($format == WRREPORT_DETAIL) $out .= '' . $id . ' | ';
+ // $page_title
+ if ($format != WRREPORT_COMPACT) $out .= '' . wrCommonSandboxParse('[[' . $page_title . ']]') . ' | ';
+ // $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 .= '' . $date_report . ' | ';
- if (!is_null($date_entry)) $out .= '' . date('Y-m-d, H:i', strtotime($date_entry)) . ' | ';
- if (!is_null($date_invalid)) $out .= '' . date('Y-m-d, H:i', strtotime($date_invalid)) . ' | ';
- $out .= '' . $condition . ' | ';
- $out .= '' . $description . ' | ';
- $out .= '' . $author_name . ' | ';
- $out .= "
\n";
- return $out;
+ // $date_entry
+ if ($format == WRREPORT_DETAIL) $out .= '' . date('Y-m-d, H:i', strtotime($date_entry)) . ' | ';
+ // $date_invalid
+ if ($format == WRREPORT_DETAIL) $out .= '' . date('Y-m-d, H:i', strtotime($date_invalid)) . ' | ';
+ // $condition
+ global $wrConditions;
+ $condition_text = '---';
+ if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
+ $out .= '';
+ if ($delete_date) $out .= utf8_encode('Gelöscht');
+ else $out .= htmlspecialchars($condition_text);
+ $out .= ' | ';
+ // $description
+ $out .= '';
+ if ($delete_date) $out .= utf8_encode('Gelöscht');
+ else $out .= wrCommonSandboxParse($description);
+ $out .= ' | ';
+ // $author_name
+ $out .= '';
+ if ($delete_date) $out .= utf8_encode('Gelöscht');
+ else $out .= htmlspecialchars($author_name);
+ $out .= ' | ';
+ // actions
+ // wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
+ if ($showActions) {
+ $out .= '';
+ if (!isset($row['delete_date'])) {
+ $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
+ $title = Title::newFromText($specialPageName, NS_SPECIAL);
+ $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
+ $out .= "' . utf8_encode('Löschen...') . '';
+ }
+ $out .= ' | ';
+ }
+ return $out . "\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 = "\n" . wrReportTableTitleRender2($format, $showActions);
+ foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
+ return $out . "
\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 It returns a table (string containing HTML) showing the results.
+/// \brief Returns reports as associative array.
///
-/// Is called when the tag 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 wrRenderReportTable($page_title = NULL) {
- $out = '';
+/// 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 .= "\n";
- $out .= wrRenderReportTableTitle($admin, $admin, TRUE, $admin, $admin, TRUE, TRUE, TRUE);
- while ($row = $dbr->fetchObject($res)) {
- $author = $row->author_name;
- if ($row->author_username) $author .= ' (' . $row->author_username . ')';
- $out .= wrRenderReportTableRow($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 .= "
\n";
- } else {
- $out .= "Es wurden keine Bahnberichte in der Datenbank gefunden.
\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 $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
+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('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 $out;
+ 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());
}
-/// Is called when the tag < is encounted.
-function wrReportFormRender($input, $args, $parser) {
- return replaceByMarker(wrRenderReportForm(TRUE, $parser->getTitle()->getArticleID(), $parser->getTitle()->getText()));
+
+// Parser Hook Functions
+// ---------------------
+
+/// \brief Is called when the tag is encountered.
+///
+/// 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();
+ }
+
+ 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');
}
+/// \brief Is called when the tag is encountered.
+///
+/// The current page name is taken.
+function bahnberichteParserHook($input, $args, &$parser) {
+ $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());
+}
+
+
+/// \brief Is called when the tag is encountered.
+///
+/// * : The current page name is taken.
+/// * page_name: The given page name is taken.
+function bahnbewertungParserHook($input, $args, &$parser) {
+ $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;
+ }
-function wrReportTableRender($input, $args, &$parser) {
- return wrRenderReportTable($parser->getTitle());
+ // Get the condition and create the response wiki text
+ if (isset($wrConditions[$condition])) {
+ $wikiText = '[['. $titleText . '#' . $wrShowReportsSection . '|'. $wrConditions[$condition] . "]] $date";
+ if ($userMayReport) $wikiText .= " ''[[" . $titleText . '#' . $wrNewReportSection . "|Neu]]''";
+ $wikiText .= "";
+ } else {
+ if ($userMayReport) $wikiText = "''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''";
+ else $wikiText = '--';
+ }
+ return wrCommonSandboxParse($wikiText);
}
+// Special page
+// ------------
+
/// Specal Page to show reports
class WrReport extends SpecialPage {
function WrReport() {
@@ -183,59 +397,232 @@ class WrReport extends SpecialPage {
}
- /// Possibilities for $par:
+ /// \param $par Possibilities:
/// - action == 'view' (default)
/// - action == 'preview': Preview new report
/// - action == 'store': Store new report
- /// - action == 'success': Show a success message
- function execute($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;
$this->setHeaders();
- # Get request data from, e.g.
+ // 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 || $action == 'showerror') {
+ $wgOut->addWikiText('' . $errorMsg . "
\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('Der Bahnbericht für [[') . $row['page_title'] . '#' . $wrShowReportsSection . '|' . $row['page_title'] . utf8_encode("]] wurde erfolgreich gelöscht.
\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
elseif ($action == 'preview' || $action == 'store') {
- $page_id = $wgRequest->getText('page_id');
$page_title = $wgRequest->getText('page_title');
$date_report = $wgRequest->getText('date_report');
$condition = $wgRequest->getText('condition');
$description = $wgRequest->getText('description');
$author_name = $wgRequest->getText('author_name');
if ($action == 'store') {
- // TODO: check conditions/permissions
+ // page_id
+ $title = Title::newFromText($page_title);
+ $page_id = $title->getArticleId();
+ if ($page_id == 0) $page_id = NULL;
+
+ // user_id
+ global $wgUser;
+ $author_userid = $wgUser->getId();
+ if ($author_userid == 0) $author_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
+ $author_username = $wgUser->getName();
+
+ // condition
+ $condition_int = (int) $condition;
+ if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
+ else $condition = NULL;
+
+ // check conditions/permissions
+ $errorMsg = NULL;
+ 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 (!$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;
+ }
+
+ // Save entry
$dbr = wfGetDB(DB_MASTER);
$dbr->insert(
'wrreport',
array(
- 'page_id' => (int) $page_id,
+ '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_username' => '',
- 'author_ip' => $_SERVER['REMOTE_ADDR']
+ 'author_ip' => $_SERVER['REMOTE_ADDR'],
+ 'author_userid' => $author_userid,
+ 'author_username' => $author_username
+ // 'delete_*' => // use database defaults (NULL)
)
);
- $wgOut->addHTML('Bahnbericht gespeichert! :-)
');
+
+ // Purge cache
+ $title->invalidateCache();
+ wrRecacheRegions();
+
+ // Show success message
+ global $wrShowReportsSection;
+ $wgOut->addWikiText(utf8_encode('Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.
\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->addHTML("Vorschau (noch nicht gespeichert)
\n");
- $wgOut->addHTML("\n");
- $wgOut->addHTML(wrRenderReportTableTitle(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE));
- $wgOut->addHTML(wrRenderReportTableRow(NULL, $page_title, $date_report, NULL, NULL, $condition, $description, $author_name));
- $wgOut->addHTML("
\n\n\n");
- $wgOut->addHTML(utf8_encode("Speichern oder Ändern
\n"));
- $wgOut->addHTML(wrRenderReportForm(FALSE, $page_id, $page_title, $date_report, $condition, $description, $author_name));
+ $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\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));
}
}
@@ -245,13 +632,4 @@ class WrReport extends SpecialPage {
}
-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;
-}
-
-
?>