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);
58 /// \brief Returns a form to enter a report (string containing HTML).
60 /// All parameters have to be UTF-8 encoded.
61 /// \param $page_title Name of the sledding run.
62 /// \return UTF-8 encoded HTML form
63 function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
64 if ($page_title) $page_title = htmlspecialchars($page_title);
66 $daynames = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
68 $date_selected = false;
69 $time = time(); // number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
70 for ($day=0; $day!=5; ++$day) {
71 $date = strtotime("-$day days", $time);
72 $date_f = strftime("%Y-%m-%d", $date); // Formats it according to locale, that is set to CET.
73 $date_options .= '<option value="' . $date_f . '"';
74 if ((is_null($date_report) && $day == 0) || (!is_null($date_report) && $date_report == $date_f)) {
75 $date_options .= ' selected="selected"';
76 $date_selected = true;
78 $date_options .= '>' . htmlspecialchars($daynames[$day]) . ' (' . strftime('%d.%m.', $date) . ')</option>' . "\n";
80 if (!$date_selected) {
81 $date_options = '<option value="' . $date_report . '" selected="selected">' . htmlspecialchars($date_report) . "</option>\n" . $date_options;
85 $condition_options = '';
86 global $wrConditions; // $wrConditions = array(1 => 'Sehr gut', 2 => 'Gut', 3 => utf8_encode('Mittelmäßig'), 4 => 'Schlecht', 5 => 'Geht nicht');
87 $condition_options .= utf8_encode('<option value="">(keine Beurteilung)</option>') . "\n";
88 foreach ($wrConditions as $condition_num => $condition_text) {
89 $condition_options .= "<option value=\"$condition_num\"";
90 if ($condition == $condition_num) $condition_options .= ' selected="selected"';
91 $condition_options .= '>' . htmlspecialchars($condition_text) . "</option>\n";
93 $description_html = htmlspecialchars($description);
96 // I would like to do it this way, but due to a bug of internet explorer, the <button> element is not useable.
97 // $buttons = '<button name="action" type="submit" value="preview">Vorschau';
98 // if ($hide_save_button) $buttons .= ' & Speichern';
99 // $buttons .= '</button>';
100 // if (!$hide_save_button) $buttons .= '<button name="action" type="submit" value="store">Speichern</button>';
101 // Workaround: User <input type="submit"/>
102 $buttons = '<input name="preview" type="submit" value="Vorschau';
103 if ($hide_save_button) $buttons .= ' & Speichern';
105 if (!$hide_save_button) $buttons .= '<input name="store" type="submit" value="Speichern"/>';
108 <form action="/wiki/Spezial:Bahnberichte" method="post">
109 <table class="wrreportform" summary="Formular zum Eintragen eines Rodelbahnberichtes">
110 <tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_title" value="$page_title"/></td></tr>
111 <tr class="evenrow"><th>Datum des Rodelns</th>
113 <select name="date_report">
118 <tr class="oddrow"><th>Bahnzustand*</th><td><select name="condition">
121 <tr class="evenrow"><th>Meinung</th><td><textarea name="description" cols="50" rows="7">$description_html</textarea></td></tr>
122 <tr class="oddrow"><th>Autor/in</th><td><input name="author_name" maxlength="30" size="30" value="$author_name" /></td></tr>
123 <tr class="evenrow"><th>Bericht abschicken</th><td>$buttons</td></tr>
131 /// \brief Renders the form to delete a report
133 /// All in and output strings should be/are UTF-8 encoded.
134 function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible) {
136 $buttons = '<input name="deletepreview" type="submit" value="Vorschau" /> ';
137 $buttons .= utf8_encode('<input name="delete" type="submit" value="Löschen"/>');
138 $buttons .= '<input name="reportid" type="hidden" value="' . $reportid . '"/>';
139 // $buttons .= '<input name="delete_invisible" type="hidden" value="' . $delete_invisible . '"/>'; // who is allowed to do so?
140 $summary = utf8_encode('Formular zum Löschen eines Schneelageberichtes');
141 $reason = utf8_encode('Begründung');
142 $delete_reason_public_html = htmlspecialchars($delete_reason_public);
143 $delete_person_name_html = htmlspecialchars($delete_person_name);
146 <form action="/wiki/Spezial:Bahnberichte" method="post">
147 <table class="wrreportform" summary="$summary">
148 <tr class="evenrow"><th>$reason</th><td><textarea name="delete_reason_public" cols="50" rows="7">$delete_reason_public_html</textarea></td></tr>
149 <tr class="oddrow"><th>Name</th><td><input name="delete_person_name" maxlength="30" size="30" value="$delete_person_name" /></td></tr>
150 <tr class="evenrow"><th>Aktion</th><td>$buttons</td></tr>
159 /// \brief sub-function of wrReportTableRender - renders the table head
161 /// The input variables are either NULL (-> the column is not present) or a UTF-8 encoded string (that is ignored ;-) ).
162 /// \return UTF-8 encoded titles of HTML table
164 function wrReportTableTitleRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name, $delete = NULL) {
166 if ($page_id) $out .= '<th>ID</th>';
167 if ($page_title) $out .= '<th>Bahn</th>';
168 if ($date_report) $out .= '<th>Datum</th>';
169 if ($date_entry) $out .= '<th>Datum Eintrag</th>';
170 if ($date_invalid) $out .= '<th>Datum Ungültig</th>';
171 if ($condition) $out .= '<th>Zustand</th>';
172 if ($description) $out .= '<th>Beschreibung</th>';
173 if ($author_name) $out .= '<th>Autor</th>';
174 if ($delete) $out .= '<th>Aktion</th>';
175 return utf8_encode($out . "</tr>\n");
179 /// \brief sub-function of wrReportTableRender - renders a table row
181 /// * The in- and output parameters are expected to be UTF-8 encoded.
182 /// * If one parameter is NULL, the corresponding column is omitted.
184 /// \param $page_title
185 /// \param $date_report
186 /// \param $date_entry
187 /// \param $date_invalid
188 /// \param $condition
189 /// \param $description
190 /// \param $author_name
193 function wrReportTableRowRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name, $delete = NULL) {
195 if (!is_null($page_id)) $out .= '<td>' . $page_id . '</td>';
196 if (!is_null($page_title)) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
197 $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
198 $date_report = strtotime($date_report);
199 $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
200 $out .= '<td>' . $date_report . '</td>';
201 if (!is_null($date_entry)) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
202 if (!is_null($date_invalid)) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
203 global $wrConditions;
204 $condition_text = '---';
205 if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
206 $out .= '<td>' . htmlspecialchars($condition_text) . '</td>';
207 $out .= '<td class="wrreportdescription">' . wrReportSandboxParse($description) . '</td>';
208 $out .= '<td>' . htmlspecialchars($author_name) . '</td>';
209 if (!is_null($delete)) $out .= '<td>(Löschen)</td>';
215 /// \brief It returns a table (string containing HTML) showing the results.
217 /// Is called when the tag <bahnberichte/> is encounted and renders a table /
218 /// \param $page_title If the name is specified (UTF-8 encoded), only reports of this "page" (e.g. 'Birgitzer Alm') is shown. Default: NULL
219 /// \return UTF-8 encoded HTML result table
221 function wrReportTableRender($page_title = NULL) {
223 $dbr = wfGetDB(DB_SLAVE);
224 $conditions = array();
225 if ($page_title) $conditions['page_title'] = $page_title;
226 $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 desc, date_entry desc'));
227 $admin = is_null($page_title);
228 if ($res->numRows() > 0) {
229 $out .= "<table class=\"wrreporttable\">\n";
230 $out .= wrReportTableTitleRender($admin, $admin, TRUE, $admin, $admin, TRUE, TRUE, TRUE);
231 while ($row = $dbr->fetchObject($res)) {
232 $author = $row->author_name;
233 $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);
235 $out .= "</table>\n";
237 $out .= wrReportSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
239 $dbr->freeResult($res);
244 // Constants for wrReportTableRender2
245 define(WRREPORT_COMPACT_PAGE, 1); ///< includes the page name
246 define(WRREPORT_COMPACT, 2); ///< shown on a single page
247 define(WRREPORT_DETAIL, 3); ///< more columns
249 /// \brief Renders a table header ("private" sub-function of wrReportTableRender2)
251 /// \param $format row format like WRREPORT_COMPACT
252 /// \param $showActions boolean to indicate whether an actions column should be created
253 /// \return UTF-8 encoded titles of HTML table
254 function wrReportTableTitleRender2($format, $showActions) {
256 if ($format == WRREPORT_DETAIL) $out .= '<th>ID</th>';
257 if ($format != WRREPORT_COMPACT) $out .= '<th>Bahn</th>';
258 $out .= '<th>Datum</th>';
259 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Eintrag</th>';
260 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Ungültig</th>';
261 $out .= '<th>Zustand</th>';
262 $out .= '<th>Beschreibung</th>';
263 $out .= '<th>Autor</th>';
264 if ($showActions) $out .= '<th>Aktion</th>';
265 return utf8_encode($out . "</tr>\n");
269 /// \brief Renders a table row ("private" sub-function of wrReportTableRender2)
271 /// \param $row associative array of table columns like one row in the wrreport table
272 /// \param $format row format like WRREPORT_COMPACT
273 /// \param $showActions boolean to indicate whether an actions column should be created
274 /// \return UTF-8 encoded titles of HTML table
275 function wrReportTableRowRender2($row, $format, $showActions) {
280 if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
282 if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
284 $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
285 $date_report = strtotime($date_report);
286 $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
287 $out .= '<td>' . $date_report . '</td>';
289 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
291 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
293 global $wrConditions;
294 $condition_text = '---';
295 if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
297 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
298 else $out .= htmlspecialchars($condition_text);
301 $out .= '<td class="wrreportdescription">';
302 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
303 else $out .= wrReportSandboxParse($description);
307 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
308 else $out .= htmlspecialchars($author_name);
311 if ($showActions) $out .= '<td>' . utf8_encode('(Löschen)') . '</td>';
312 return $out . "</tr>\n";
316 /// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
318 /// \param $rows array of associative row arrays
319 /// \param $format row format like WRREPORT_TABLE_SHORT
320 function wrReportTableRender2($rows, $format, $showActions) {
321 $out = "<table class=\"wrreporttable\">\n" . wrReportTableTitleRender2($format, $showActions);
322 foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
323 return $out . "</table>\n";
327 /// Returns an array with column names
328 function wrReportGetColumnNames() {
329 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');
333 /// \brief Returns reports as associative array.
336 /// $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
337 /// $order = 'date_report desc, date_entry desc';
338 function wrReportGetReports($conditions, $order) {
339 $dbr = wfGetDB(DB_SLAVE);
340 $res = $dbr->select('wrreport', wrReportGetColumnNames(), $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
342 while ($row = $dbr->fetchRow($res)) $result[] = $row;
343 $dbr->freeResult($res);
349 /// \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);
351 /// If no condition is present, array(NULL, NULL) is returned
352 function wrReportConditionRender($page_title) {
353 $dbr = wfGetDB(DB_SLAVE);
354 $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, 'condition is not null', 'date_invalid > now()'));
355 // 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);
356 if ($res->numRows() <= 0) return array(NULL, NULL);
357 $row = $dbr->fetchObject($res);
358 $res = $dbr->select('wrreport', array('condition', 'date_report'), array('id' => $row->max));
359 if ($res->numRows() <= 0) return array(NULL, NULL);
360 $row = $dbr->fetchObject($res);
361 $date = $row->date_report;
362 if ($date) $date = strtotime($date);
363 return array($row->condition, $date);
367 // Parser Hook Functions
368 // ---------------------
370 /// \brief Is called when the tag <bahnberichtformular/> is encountered.
372 /// The current page name is taken.
373 function bahnberichtformularParserHook($input, $args, $parser) {
377 if ($wgUser->isLoggedIn()) {
378 $author_name = $wgUser->getRealName();
379 if (!$author_name) $author_name = $wgUser->getName();
382 global $wgWrReportMode;
383 global $wgWrReportBlackListAll;
384 global $wgWrReportBlackListStrangers;
385 if ($wgWrReportMode == 'summer') return wrReportSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n"));
386 if ($wgWrReportMode == 'deny') return wrReportSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n"));
388 // The following was changed because for testing purposes, we have 'loggedin' instead of 'summer' in the $wgWrReportMode. TODO: Change back!
389 // if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrReportSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
390 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"));
392 if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrReportSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
393 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"));
394 return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
398 /// \brief Is called when the tag <bahnberichte/> is encountered.
400 /// The current page name is taken.
401 function bahnberichteParserHook($input, $args, &$parser) {
402 return wrReportTableRender($parser->getTitle()->getText()); // TODO: Replace
406 /// \brief Is called when the tag <bahnbewertung/> is encountered.
408 /// * <bahnbewertung/>: The current page name is taken.
409 /// * <bahnbewertung>page_name</bahnbewertung>: The given page name is taken.
410 function bahnbewertungParserHook($input, $args, &$parser) {
412 if (!$titleText) $titleText = $parser->getTitle()->getText();
413 list($condition, $date) = wrReportConditionRender($titleText);
414 if ($date) $date = strftime('%d.%m.', $date);
415 global $wrConditions;
416 global $wrNewReportSection; // = utf8_encode('Eintragen');
417 global $wrShowReportsSection; // = utf8_encode('Einträge');
419 global $wgWrReportMode; // e.g. 'summer'
420 global $wgWrReportBlackListAll;
421 global $wgWrReportBlackListStrangers;
423 // Determine, whether the user is allowed to make a new report
424 $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
425 if ($userMayReport) {
426 if (in_array($titleText, $wgWrReportBlackListAll)) $userMayReport = false;
427 if (!$wgUser->isLoggedIn() && in_array($titleText, $wgWrReportBlackListStrangers)) $userMayReport = false;
430 // Get the condition and create the response wiki text
431 if (isset($wrConditions[$condition])) {
432 $wikiText = '[['. $titleText . '#' . $wrShowReportsSection . '|'. $wrConditions[$condition] . "]] <small>$date";
433 if ($userMayReport) $wikiText .= " ''[[" . $titleText . '#' . $wrNewReportSection . "|Neu]]''";
434 $wikiText .= "</small>";
436 if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
437 else $wikiText = '--';
439 return wrReportSandboxParse($wikiText);
447 /// Specal Page to show reports
448 class WrReport extends SpecialPage {
449 function WrReport() {
450 SpecialPage::SpecialPage('WrReport');
451 wfLoadExtensionMessages('WrReport');
455 /// \param $par Possibilities:
456 /// - action == 'view' (default)
457 /// - action == 'preview': Preview new report
458 /// - action == 'store': Store new report
459 /// - action == 'deletepreview': Preview the deleted record
460 /// - action == 'delete': Delete an existing report
461 /// - action == 'showerror': Shows the error and exits
462 /// \param $override_action If not NULL (default), it overrides the action in $par
463 /// \param $errorMsg UFT-8 encoded error message (in WikiText) to show on top of the page or NULL (default):
464 function execute($par, $override_action = NULL, $errorMsg = NULL) {
465 global $wgRequest, $wgOut;
470 $action = $wgRequest->getText('action');
472 if ($wgRequest->getVal('preview')) $action = 'preview';
473 elseif ($wgRequest->getVal('store')) $action = 'store';
474 elseif ($wgRequest->getVal('deletepreview')) $action = 'deletepreview';
475 elseif ($wgRequest->getVal('delete')) $action = 'delete';
476 else $action = 'view';
478 if ($override_action) $action = $override_action;
480 // Show error message
481 if ($errorMsg || $action == 'showerror') {
482 $wgOut->addWikiText('<div class="errorbox">' . $errorMsg . "</div>\n");
483 if ($action == 'showerror') return;
487 if ($action == 'view') {
488 $wgOut->addHTML(wrReportTableRender()); // TODO: Replace
491 elseif ($action == 'test') { // TODO: delete
492 $conditions = array('page_title' => 'Axamer Lizum', 'date_invalid > now()');
493 $order = 'date_report desc, date_entry desc';
494 $rows = wrReportGetReports($conditions, $order);
495 $format = WRREPORT_COMPACT_PAGE; // WRREPORT_COMPACT WRREPORT_DETAIL
496 $format = WRREPORT_DETAIL;
497 $wgOut->addHTML(wrReportTableRender2($rows, $format, True));
498 $wgOut->addHTML('OK');
501 // Action deletepreview or delete
502 elseif ($action == 'deletepreview' || $action == 'delete') {
503 $reportid = (int) $wgRequest->getText('reportid');
504 if ($reportid == 0) {
505 $this->execute($par, 'showerror', utf8_encode('Es wurde kein Bericht zum Löschen ausgewählt.'));
508 $rows = wrReportGetReports(array('id' => $reportid), '');
509 if (count($rows) != 1) {
510 $this->execute($par, 'showerror', utf8_encode('Es wurde ein ungültiger Bericht zum Löschen ausgewählt.'));
514 if (!is_null($row['delete_date'])) {
515 $this->execute($par, 'showerror', utf8_encode('Der angegebende Bericht ist bereits gelöscht.'));
518 // $row = array_fill_keys(wrReportGetColumnNames(), NULL); // TODO: Delete
519 $delete_reason_public = $wgRequest->getText('delete_reason_public');
520 $delete_person_name = $wgRequest->getText('delete_person_name');
521 $delete_invisible = $wgRequest->getText('delete_invisible') ? TRUE : FALSE;
522 if ($action == 'delete') {
524 $title = Title::newFromId($row['page_id']);
528 $delete_person_userid = $wgUser->getId();
529 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.
530 $delete_person_username = $wgUser->getName();
534 global $wgWrReportDeleteMode;
535 if ($wgWrReportDeleteMode == 'deny') $errorMsg = utf8_encode('Das Löschen von Rodelbahnberichten ist derzeit leider nicht erlaubt.');
536 elseif ($wgWrReportDeleteMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit dürfen nur angemeldete Benutzer Rodelbahnberichte löschen.');
537 elseif (!$delete_person_name && !$delete_reason_public) $errorMsg = utf8_encode('Es müssen sowohl die Begründung als auch der Name angegeben werden.');
539 $this->execute($par, 'preview', $errorMsg);
543 // "Delete" (update) entry
544 $dbr = wfGetDB(DB_MASTER);
548 'delete_date' => date('c'),
549 'delete_person_name' => $delete_person_name,
550 'delete_person_ip' => $_SERVER['REMOTE_ADDR'],
551 'delete_person_userid' => $delete_person_userid,
552 'delete_person_username' => $delete_person_username,
553 'delete_reason_public' => $delete_reason_public,
554 'delete_invisible' => $delete_invisible ? 't' : 'f'
556 array('id' => $reportid)
560 $title->invalidateCache();
561 // Show success message
562 global $wrShowReportsSection;
563 $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"));
565 if ($action == 'deletepreview') {
566 $wgOut->addWikiText(utf8_encode("== Schneelagebericht, um den es beim Löschen geht ==\n"));
567 $format = WRREPORT_COMPACT_PAGE;
568 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
569 $wgOut->addWikiText(utf8_encode("\n\n== Vorschau (noch nicht gelöscht) ==\n"));
570 $row['delete_date'] = date('c');
571 $row['delete_reason_public'] = $delete_reason_public;
572 $row['delete_person_name'] = $delete_person_name;
573 $row['delete_invisible'] = $delete_invisible;
574 $wgOut->addHTML("<table class=\"wrreporttable\">\n");
575 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
576 $wgOut->addHTML("</table>");
577 $wgOut->addWikiText("\n");
578 $wgOut->addWikiText(utf8_encode("== Löschen ==\n"));
579 $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"));
580 $wgOut->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
584 // Action preview or store
585 elseif ($action == 'preview' || $action == 'store') {
586 $page_title = $wgRequest->getText('page_title');
587 $date_report = $wgRequest->getText('date_report');
588 $condition = $wgRequest->getText('condition');
589 $description = $wgRequest->getText('description');
590 $author_name = $wgRequest->getText('author_name');
591 if ($action == 'store') {
593 $title = Title::newFromText($page_title);
594 $page_id = $title->getArticleId();
595 if ($page_id == 0) $page_id = NULL;
599 $author_userid = $wgUser->getId();
600 if ($author_userid == 0) $author_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
601 $author_username = $wgUser->getName();
604 $condition_int = (int) $condition;
605 if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
606 else $condition = NULL;
608 // check conditions/permissions
610 global $wgWrReportMode;
611 global $wgWrReportBlackListAll;
612 global $wgWrReportBlackListStrangers;
613 if ($wgWrReportMode == 'summer') $errorMsg = utf8_encode('Rodelbahnberichte sind in der schneefreien Zeit nicht erlaubt.');
614 elseif ($wgWrReportMode == 'deny') $errorMsg = utf8_encode('Rodelbahnberichte sind derzeit leider nicht erlaubt.');
615 elseif ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.');
616 elseif (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
617 elseif (in_array($page_title, $wgWrReportBlackListAll)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit keine Rodelbahnberichte abgegeben werden.');
618 elseif (!$wgUser->isLoggedIn() && in_array($page_title, $wgWrReportBlackListStrangers)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.');
619 elseif (!$condition && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung leer/nicht vergeben.');
620 elseif (!$wgUser->isLoggedIn()) {
621 if (!$description) $errorMsg = utf8_encode('Bitte bei der Beschreibung eine kurze Begründung für die Bewertung abgeben.');
622 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.');
625 $this->execute($par, 'preview', $errorMsg);
630 $dbr = wfGetDB(DB_MASTER);
634 'page_id' => $page_id,
635 'page_title' => $page_title,
636 'date_report' => $date_report,
637 // 'date_entry' => '', // use database default
638 // 'date_invalid' => '', // use database default
639 'condition' => $condition,
640 'description' => $description,
641 'author_name' => $author_name,
642 'author_ip' => $_SERVER['REMOTE_ADDR'],
643 'author_userid' => $author_userid,
644 'author_username' => $author_username
649 $title->invalidateCache();
650 // Show success message
651 global $wrShowReportsSection;
652 $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n"));
653 // We could redirect to result with the following line but we don't want to.
654 // $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
656 if ($action == 'preview') {
657 $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
658 $wgOut->addHTML("<table class=\"wrreporttable\">\n");
659 $wgOut->addHTML(wrReportTableTitleRender(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE));
660 $wgOut->addHTML(wrReportTableRowRender(NULL, $page_title, $date_report, NULL, NULL, $condition, $description, $author_name));
661 $wgOut->addHTML("</table>");
662 $wgOut->addWikiText("\n");
663 $wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
664 $wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
669 else die('Wrong action');