7 function wrReportParserInit() {
9 $wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
10 $wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
11 $wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
19 /// \brief This function is used to translate WikiText to HTML. Normally it should be avoided to do this
20 /// but I found situations where I did not find an other possibility.
21 function wrReportSandboxParse($wikiText) {
22 global $wgTitle, $wgUser;
23 $myParser = new Parser();
24 $myParserOptions = new ParserOptions();
25 $myParserOptions->initialiseFromUser($wgUser);
26 $result = $myParser->parse($wikiText, $wgTitle, $myParserOptions);
27 return $result->getText();
31 /// List of markers - used by the functions replaceByMarker and wrReportAfterTidy
32 $wrReportMarkerList = array();
35 /// Returns a marker for a text and back-replaces the text in wrReportAfterTidy
36 function replaceByMarker($text, $marker = 'marker') {
37 $marker = $marker . mt_rand(1e5, 1e7);
38 global $wrReportMarkerList;
39 $wrReportMarkerList[$marker] = $text;
44 /// Replaces the markers by its contents
45 function wrReportAfterTidy(&$parser, &$text) {
46 // find markers in $text
47 // replace markers with actual output
48 global $wrReportMarkerList;
49 foreach ($wrReportMarkerList as $marker => $html) $text = str_replace($marker, $html, $text);
54 /// Forces a regeneration of region overview pages
55 function wrRecacheRegions() {
56 // TODO: Better implementation - it's a "quick fix" now.
57 $title = Title::newFromText('Tirol');
58 $title->invalidateCache();
60 $title = Title::newFromText('Vorarlberg');
61 $title->invalidateCache();
63 $title = Title::newFromText('Steiermark');
64 $title->invalidateCache();
72 /// \brief Returns a form to enter a report (string containing HTML).
74 /// All parameters have to be UTF-8 encoded.
75 /// \param $page_title Name of the sledding run.
76 /// \return UTF-8 encoded HTML form
77 function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
78 if ($page_title) $page_title = htmlspecialchars($page_title);
80 $daynames = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
82 $date_selected = false;
83 $time = time(); // number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
84 for ($day=0; $day!=5; ++$day) {
85 $date = strtotime("-$day days", $time);
86 $date_f = strftime("%Y-%m-%d", $date); // Formats it according to locale, that is set to CET.
87 $date_options .= '<option value="' . $date_f . '"';
88 if ((is_null($date_report) && $day == 0) || (!is_null($date_report) && $date_report == $date_f)) {
89 $date_options .= ' selected="selected"';
90 $date_selected = true;
92 $date_options .= '>' . htmlspecialchars($daynames[$day]) . ' (' . strftime('%d.%m.', $date) . ')</option>' . "\n";
94 if (!$date_selected) {
95 $date_options = '<option value="' . $date_report . '" selected="selected">' . htmlspecialchars($date_report) . "</option>\n" . $date_options;
99 $condition_options = '';
100 global $wrConditions; // $wrConditions = array(1 => 'Sehr gut', 2 => 'Gut', 3 => utf8_encode('Mittelmäßig'), 4 => 'Schlecht', 5 => 'Geht nicht');
101 $condition_options .= utf8_encode('<option value="">(keine Beurteilung)</option>') . "\n";
102 foreach ($wrConditions as $condition_num => $condition_text) {
103 $condition_options .= "<option value=\"$condition_num\"";
104 if ($condition == $condition_num) $condition_options .= ' selected="selected"';
105 $condition_options .= '>' . htmlspecialchars($condition_text) . "</option>\n";
107 $description_html = htmlspecialchars($description);
110 // I would like to do it this way, but due to a bug of internet explorer, the <button> element is not useable.
111 // $buttons = '<button name="action" type="submit" value="preview">Vorschau';
112 // if ($hide_save_button) $buttons .= ' & Speichern';
113 // $buttons .= '</button>';
114 // if (!$hide_save_button) $buttons .= '<button name="action" type="submit" value="store">Speichern</button>';
115 // Workaround: User <input type="submit"/>
116 $buttons = '<input name="preview" type="submit" value="Vorschau';
117 if ($hide_save_button) $buttons .= ' & Speichern';
119 if (!$hide_save_button) $buttons .= '<input name="store" type="submit" value="Speichern"/>';
121 // TODO: Get rid of absolute URL
123 <form action="/wiki/Spezial:Bahnberichte" method="post">
124 <table class="wrreportform" summary="Formular zum Eintragen eines Rodelbahnberichtes">
125 <tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_title" value="$page_title"/></td></tr>
126 <tr class="evenrow"><th>Datum des Rodelns</th>
128 <select name="date_report">
133 <tr class="oddrow"><th>Bahnzustand*</th><td><select name="condition">
136 <tr class="evenrow"><th>Meinung</th><td><textarea name="description" cols="50" rows="7">$description_html</textarea></td></tr>
137 <tr class="oddrow"><th>Autor/in</th><td><input name="author_name" maxlength="30" size="30" value="$author_name" /></td></tr>
138 <tr class="evenrow"><th>Bericht abschicken</th><td>$buttons</td></tr>
146 /// \brief Renders the form to delete a report
148 /// All in and output strings should be/are UTF-8 encoded.
149 function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible) {
151 $buttons = '<input name="deletepreview" type="submit" value="Vorschau" /> ';
152 $buttons .= utf8_encode('<input name="delete" type="submit" value="Löschen"/>');
153 $buttons .= '<input name="reportid" type="hidden" value="' . $reportid . '"/>';
154 // $buttons .= '<input name="delete_invisible" type="hidden" value="' . $delete_invisible . '"/>'; // who is allowed to do so?
155 $summary = utf8_encode('Formular zum Löschen eines Schneelageberichtes');
156 $reason = utf8_encode('Begründung');
157 $delete_reason_public_html = htmlspecialchars($delete_reason_public);
158 $delete_person_name_html = htmlspecialchars($delete_person_name);
160 // TODO: Get rid of absolute URL
162 <form action="/wiki/Spezial:Bahnberichte" method="post">
163 <table class="wrreportform" summary="$summary">
164 <tr class="evenrow"><th>$reason</th><td><textarea name="delete_reason_public" cols="50" rows="7">$delete_reason_public_html</textarea></td></tr>
165 <tr class="oddrow"><th>Name</th><td><input name="delete_person_name" maxlength="30" size="30" value="$delete_person_name" /></td></tr>
166 <tr class="evenrow"><th>Aktion</th><td>$buttons</td></tr>
175 // Constants for wrReportTableRender2
176 define(WRREPORT_COMPACT_PAGE, 1); ///< includes the page name
177 define(WRREPORT_COMPACT, 2); ///< shown on a single page
178 define(WRREPORT_DETAIL, 3); ///< more columns
180 /// \brief Renders a table header ("private" sub-function of wrReportTableRender2)
182 /// \param $format row format like WRREPORT_COMPACT
183 /// \param $showActions boolean to indicate whether an actions column should be created
184 /// \return UTF-8 encoded titles of HTML table
185 function wrReportTableTitleRender2($format, $showActions) {
187 if ($format == WRREPORT_DETAIL) $out .= '<th>ID</th>';
188 if ($format != WRREPORT_COMPACT) $out .= '<th>Bahn</th>';
189 $out .= '<th>Datum</th>';
190 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Eintrag</th>';
191 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Ungültig</th>';
192 $out .= '<th>Zustand</th>';
193 $out .= '<th>Beschreibung</th>';
194 $out .= '<th>Autor</th>';
195 if ($showActions) $out .= '<th>Aktion</th>';
196 return utf8_encode($out . "</tr>\n");
200 /// \brief Renders a table row ("private" sub-function of wrReportTableRender2)
202 /// \param $row associative array of table columns like one row in the wrreport table
203 /// \param $format row format like WRREPORT_COMPACT
204 /// \param $showActions boolean to indicate whether an actions column should be created
205 /// \return UTF-8 encoded titles of HTML table
206 function wrReportTableRowRender2($row, $format, $showActions) {
211 if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
213 if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
215 $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
216 $date_report = strtotime($date_report);
217 $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
218 $out .= '<td>' . $date_report . '</td>';
220 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
222 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
224 global $wrConditions;
225 $condition_text = '---';
226 if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
228 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
229 else $out .= htmlspecialchars($condition_text);
232 $out .= '<td class="wrreportdescription">';
233 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
234 else $out .= wrReportSandboxParse($description);
238 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
239 else $out .= htmlspecialchars($author_name);
242 // wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
245 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
248 return $out . "</tr>\n";
252 /// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
254 /// \param $rows array of associative row arrays
255 /// \param $format row format like WRREPORT_TABLE_SHORT
256 function wrReportTableRender2($rows, $format, $showActions) {
257 $out = "<table class=\"wrreporttable\">\n" . wrReportTableTitleRender2($format, $showActions);
258 foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
259 return $out . "</table>\n";
263 /// Returns an array with column names
264 function wrReportGetColumnNames() {
265 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');
269 /// \brief Returns reports as associative array.
272 /// $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
273 /// $order = 'date_report desc, date_entry desc';
274 function wrReportGetReports($conditions, $order) {
275 $dbr = wfGetDB(DB_SLAVE);
276 $res = $dbr->select('wrreport', wrReportGetColumnNames(), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
278 while ($row = $dbr->fetchRow($res)) $result[] = $row;
279 $dbr->freeResult($res);
284 /// \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);
286 /// If no condition is present, array(NULL, NULL) is returned
287 function wrReportConditionRender($page_title) {
288 $dbr = wfGetDB(DB_SLAVE);
289 $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, 'condition is not null', 'date_invalid > now()'));
290 // 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);
291 if ($res->numRows() <= 0) {
292 $dbr->freeResult($res);
293 return array(NULL, NULL);
295 $row = $dbr->fetchObject($res);
296 $dbr->freeResult($res);
297 $res = $dbr->select('wrreport', array('condition', 'date_report'), array('id' => $row->max));
298 if ($res->numRows() <= 0) {
299 $dbr->freeResult($res);
300 return array(NULL, NULL);
302 $row = $dbr->fetchObject($res);
303 $date = $row->date_report;
304 if ($date) $date = strtotime($date);
305 $dbr->freeResult($res);
306 return array($row->condition, $date);
310 /// \brief Returns true if the user is allowed to delete reports (in general)
311 function wrReportUserMayDelete() {
313 global $wgWrReportDeleteMode;
314 return $wgWrReportDeleteMode == 'allow' || ($wgWrReportDeleteMode == 'loggedin' && $wgUser->isLoggedIn());
319 // Parser Hook Functions
320 // ---------------------
322 /// \brief Is called when the tag <bahnberichtformular/> is encountered.
324 /// The current page name is taken.
325 function bahnberichtformularParserHook($input, $args, $parser) {
329 if ($wgUser->isLoggedIn()) {
330 $author_name = $wgUser->getRealName();
331 if (!$author_name) $author_name = $wgUser->getName();
334 global $wgWrReportMode;
335 global $wgWrReportBlackListAll;
336 global $wgWrReportBlackListStrangers;
337 if ($wgWrReportMode == 'summer') return wrReportSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n"));
338 if ($wgWrReportMode == 'deny') return wrReportSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n"));
340 if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrReportSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
342 if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrReportSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
343 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"));
345 // Calling "$title = $parser->getTitle(); $title->invalidateCache();" doesn't help here to force regeneration
346 // However, this would not be the best solution because the page has to be re-rendered only at midnight
348 return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
352 /// \brief Is called when the tag <bahnberichte/> is encountered.
354 /// The current page name is taken.
355 function bahnberichteParserHook($input, $args, &$parser) {
356 $page_title = $parser->getTitle()->getText();
357 $conditions = array('page_title' => $page_title, 'date_invalid > now()');
358 $order = 'date_report desc, date_entry desc';
359 $rows = wrReportGetReports($conditions, $order);
360 if (count($rows) == 0) return wrReportSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
361 return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete());
365 /// \brief Is called when the tag <bahnbewertung/> is encountered.
367 /// * <bahnbewertung/>: The current page name is taken.
368 /// * <bahnbewertung>page_name</bahnbewertung>: The given page name is taken.
369 function bahnbewertungParserHook($input, $args, &$parser) {
371 if (!$titleText) $titleText = $parser->getTitle()->getText();
372 list($condition, $date) = wrReportConditionRender($titleText);
373 if ($date) $date = strftime('%d.%m.', $date);
374 global $wrConditions;
375 global $wrNewReportSection; // = utf8_encode('Eintragen');
376 global $wrShowReportsSection; // = utf8_encode('Einträge');
378 global $wgWrReportMode; // e.g. 'summer'
379 global $wgWrReportBlackListAll;
380 global $wgWrReportBlackListStrangers;
382 // Determine, whether the user is allowed to make a new report
383 $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
384 if ($userMayReport) {
385 if (in_array($titleText, $wgWrReportBlackListAll)) $userMayReport = false;
386 if (!$wgUser->isLoggedIn() && in_array($titleText, $wgWrReportBlackListStrangers)) $userMayReport = false;
389 // Get the condition and create the response wiki text
390 if (isset($wrConditions[$condition])) {
391 $wikiText = '[['. $titleText . '#' . $wrShowReportsSection . '|'. $wrConditions[$condition] . "]] <small>$date";
392 if ($userMayReport) $wikiText .= " ''[[" . $titleText . '#' . $wrNewReportSection . "|Neu]]''";
393 $wikiText .= "</small>";
395 if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
396 else $wikiText = '--';
398 return wrReportSandboxParse($wikiText);
406 /// Specal Page to show reports
407 class WrReport extends SpecialPage {
408 function WrReport() {
409 SpecialPage::SpecialPage('WrReport');
410 wfLoadExtensionMessages('WrReport');
414 /// \param $par Possibilities:
415 /// - action == 'view' (default)
416 /// - action == 'preview': Preview new report
417 /// - action == 'store': Store new report
418 /// - action == 'deletepreview': Preview the deleted record
419 /// - action == 'delete': Delete an existing report
420 /// - action == 'showerror': Shows the error and exits
421 /// \param $override_action If not NULL (default), it overrides the action in $par
422 /// \param $errorMsg UFT-8 encoded error message (in WikiText) to show on top of the page or NULL (default):
423 function execute($par, $override_action = NULL, $errorMsg = NULL) {
424 global $wgRequest, $wgOut;
429 $action = $wgRequest->getText('action');
431 if ($wgRequest->getVal('preview')) $action = 'preview';
432 elseif ($wgRequest->getVal('store')) $action = 'store';
433 elseif ($wgRequest->getVal('deletepreview')) $action = 'deletepreview';
434 elseif ($wgRequest->getVal('delete')) $action = 'delete';
435 else $action = 'view';
437 if ($override_action) $action = $override_action;
439 // Show error message
440 if ($errorMsg || $action == 'showerror') {
441 $wgOut->addWikiText('<div class="errorbox">' . $errorMsg . "</div>\n");
442 if ($action == 'showerror') return;
446 if ($action == 'view') {
447 $conditions = array('date_invalid > now()');
448 $order = 'date_entry desc, date_report desc';
449 $rows = wrReportGetReports($conditions, $order);
450 if (count($rows) == 0) $wgOut->addWikiText("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
451 $wgOut->addHTML(wrReportTableRender2($rows, WRREPORT_DETAIL, wrReportUserMayDelete()));
454 // Action deletepreview or delete
455 elseif ($action == 'deletepreview' || $action == 'delete') {
456 $reportid = (int) $wgRequest->getText('reportid');
457 if ($reportid == 0) {
458 $this->execute($par, 'showerror', utf8_encode('Es wurde kein Bericht zum Löschen ausgewählt.'));
461 $rows = wrReportGetReports(array('id' => $reportid), '');
462 if (count($rows) != 1) {
463 $this->execute($par, 'showerror', utf8_encode('Es wurde ein ungültiger Bericht zum Löschen ausgewählt.'));
467 if (!is_null($row['delete_date'])) {
468 $this->execute($par, 'showerror', utf8_encode('Der angegebende Bericht ist bereits gelöscht.'));
471 $delete_reason_public = $wgRequest->getText('delete_reason_public');
472 $delete_person_name = $wgRequest->getText('delete_person_name');
473 $delete_invisible = $wgRequest->getText('delete_invisible') ? TRUE : FALSE;
474 if ($action == 'delete') {
476 $title = Title::newFromId($row['page_id']);
480 $delete_person_userid = $wgUser->getId();
481 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.
482 $delete_person_username = $wgUser->getName();
484 // Check permissions - see also function wrReportUserMayDelete, that does also check permissions but does not return an error message.
486 global $wgWrReportDeleteMode;
487 if ($wgWrReportDeleteMode == 'deny') $errorMsg = utf8_encode('Das Löschen von Rodelbahnberichten ist derzeit leider nicht erlaubt.');
488 elseif ($wgWrReportDeleteMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit dürfen nur angemeldete Benutzer Rodelbahnberichte löschen.');
489 elseif (!$delete_person_name || !$delete_reason_public) $errorMsg = utf8_encode('Es müssen sowohl die Begründung als auch der Name angegeben werden.');
491 $this->execute($par, 'deletepreview', $errorMsg);
495 // "Delete" (update) entry
496 $dbr = wfGetDB(DB_MASTER);
500 'delete_date' => date('c'),
501 'delete_person_name' => $delete_person_name,
502 'delete_person_ip' => $_SERVER['REMOTE_ADDR'],
503 'delete_person_userid' => $delete_person_userid,
504 'delete_person_username' => $delete_person_username,
505 'delete_reason_public' => $delete_reason_public,
506 'delete_invisible' => $delete_invisible ? 't' : 'f'
508 array('id' => $reportid)
512 $title->invalidateCache();
515 // Show success message
516 global $wrShowReportsSection;
517 $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"));
519 if ($action == 'deletepreview') {
520 $preview_msg = "Bitte nur dann einen Bericht löschen, wenn Gründe vorliegen wie\n" .
521 "* Beschimpfungen, Verleumdungen (wir wollen ''Rodelbahnen'' bewerten, nicht Personen)\n" .
522 "* Werbung oder Spam (wenn jemand allerdings ''werbend'' zu gute Noten vergibt, lieber eigenen Bericht eintragen als löschen).\n\n";
523 $wgOut->addWikiText(utf8_encode($preview_msg));
524 $wgOut->addWikiText(utf8_encode("== Schneelagebericht, um den es beim Löschen geht ==\n"));
525 $format = WRREPORT_COMPACT_PAGE;
526 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
527 $wgOut->addWikiText(utf8_encode("\n\n== Vorschau (derzeit noch nicht gelöscht) ==\n"));
528 $row['delete_date'] = date('c');
529 $row['delete_reason_public'] = $delete_reason_public;
530 $row['delete_person_name'] = $delete_person_name;
531 $row['delete_invisible'] = $delete_invisible;
532 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
533 $wgOut->addWikiText(utf8_encode("== Löschen ==\n"));
534 $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"));
535 $wgOut->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
539 // Action preview or store
540 elseif ($action == 'preview' || $action == 'store') {
541 $page_title = $wgRequest->getText('page_title');
542 $date_report = $wgRequest->getText('date_report');
543 $condition = $wgRequest->getText('condition');
544 $description = $wgRequest->getText('description');
545 $author_name = $wgRequest->getText('author_name');
546 if ($action == 'store') {
548 $title = Title::newFromText($page_title);
549 $page_id = $title->getArticleId();
550 if ($page_id == 0) $page_id = NULL;
554 $author_userid = $wgUser->getId();
555 if ($author_userid == 0) $author_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
556 $author_username = $wgUser->getName();
559 $condition_int = (int) $condition;
560 if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
561 else $condition = NULL;
563 // check conditions/permissions
565 global $wgWrReportMode;
566 global $wgWrReportBlackListAll;
567 global $wgWrReportBlackListStrangers;
568 if ($wgWrReportMode == 'summer') $errorMsg = utf8_encode('Rodelbahnberichte sind in der schneefreien Zeit nicht erlaubt.');
569 elseif ($wgWrReportMode == 'deny') $errorMsg = utf8_encode('Rodelbahnberichte sind derzeit leider nicht erlaubt.');
570 elseif ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.');
571 elseif (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
572 elseif (in_array($page_title, $wgWrReportBlackListAll)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit keine Rodelbahnberichte abgegeben werden.');
573 elseif (!$wgUser->isLoggedIn() && in_array($page_title, $wgWrReportBlackListStrangers)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.');
574 elseif (!$condition && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung leer/nicht vergeben.');
575 elseif (!$wgUser->isLoggedIn()) {
576 if (!$description) $errorMsg = utf8_encode('Bitte bei der Beschreibung eine kurze Begründung für die Bewertung abgeben.');
577 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.');
580 // Chech whether identical reports are present
582 $dbr = wfGetDB(DB_SLAVE);
583 $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, 'condition' => $condition, 'description' => $description, 'author_name' => $author_name);
584 $res = $dbr->select('wrreport', 'id', $sqlConditions);
585 if ($res->numRows() == 1) $errorMsg = utf8_encode('Der Rodelbahnbericht wurde bereits früher gespeichert.');
586 $dbr->freeResult($res);
591 $this->execute($par, 'preview', $errorMsg);
596 $dbr = wfGetDB(DB_MASTER);
600 'page_id' => $page_id,
601 'page_title' => $page_title,
602 'date_report' => $date_report,
603 // 'date_entry' => '', // use database default
604 // 'date_invalid' => '', // use database default
605 'condition' => $condition,
606 'description' => $description,
607 'author_name' => $author_name,
608 'author_ip' => $_SERVER['REMOTE_ADDR'],
609 'author_userid' => $author_userid,
610 'author_username' => $author_username
611 // 'delete_*' => // use database defaults (NULL)
616 $title->invalidateCache();
619 // Show success message
620 global $wrShowReportsSection;
621 $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n"));
622 // We could redirect to result with the following line but we don't want to.
623 // $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
625 if ($action == 'preview') {
626 $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
627 $format = WRREPORT_COMPACT_PAGE;
628 $row = array_fill_keys(wrReportGetColumnNames(), NULL);
629 $row['page_title'] = $page_title;
630 $row['date_report'] = $date_report;
631 $row['condition'] = $condition;
632 $row['description'] = $description;
633 $row['author_name'] = $author_name;
634 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
635 $wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
636 $wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
641 else die('Wrong action');