7 function wrReportParserInit() {
9 wfLoadExtensionMessages('WrReport');
10 $wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
11 $wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
12 $wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
20 /// Forces a regeneration of region overview pages
21 function wrRecacheRegions() {
22 // TODO: Better implementation - it's a "quick fix" now.
23 $title = Title::newFromText('Tirol');
24 $title->invalidateCache();
26 $title = Title::newFromText('Vorarlberg');
27 $title->invalidateCache();
29 $title = Title::newFromText('Steiermark');
30 $title->invalidateCache();
38 /// \brief Returns a form to enter a report (string containing HTML).
40 /// All parameters have to be UTF-8 encoded.
41 /// \param $page_title Name of the sledding run.
42 /// \return UTF-8 encoded HTML form
43 function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
44 if ($page_title) $page_title = htmlspecialchars($page_title);
46 $daynames = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
48 $date_selected = false;
49 $time = time(); // number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
50 for ($day=0; $day!=5; ++$day) {
51 $date = strtotime("-$day days", $time);
52 $date_f = strftime("%Y-%m-%d", $date); // Formats it according to locale, that is set to CET.
53 $date_options .= '<option value="' . $date_f . '"';
54 if ((is_null($date_report) && $day == 0) || (!is_null($date_report) && $date_report == $date_f)) {
55 $date_options .= ' selected="selected"';
56 $date_selected = true;
58 $date_options .= '>' . htmlspecialchars($daynames[$day]) . ' (' . strftime('%d.%m.', $date) . ')</option>' . "\n";
60 if (!$date_selected) {
61 $date_options = '<option value="' . $date_report . '" selected="selected">' . htmlspecialchars($date_report) . "</option>\n" . $date_options;
65 $condition_options = '';
66 global $wrConditions; // $wrConditions = array(1 => 'Sehr gut', 2 => 'Gut', 3 => utf8_encode('Mittelmäßig'), 4 => 'Schlecht', 5 => 'Geht nicht');
67 $condition_options .= utf8_encode('<option value="">(keine Beurteilung)</option>') . "\n";
68 foreach ($wrConditions as $condition_num => $condition_text) {
69 $condition_options .= "<option value=\"$condition_num\"";
70 if ($condition == $condition_num) $condition_options .= ' selected="selected"';
71 $condition_options .= '>' . htmlspecialchars($condition_text) . "</option>\n";
73 $description_html = htmlspecialchars($description);
76 // I would like to do it this way, but due to a bug of internet explorer, the <button> element is not useable.
77 // $buttons = '<button name="action" type="submit" value="preview">Vorschau';
78 // if ($hide_save_button) $buttons .= ' & Speichern';
79 // $buttons .= '</button>';
80 // if (!$hide_save_button) $buttons .= '<button name="action" type="submit" value="store">Speichern</button>';
81 // Workaround: User <input type="submit"/>
82 $buttons = '<input name="preview" type="submit" value="Vorschau';
83 if ($hide_save_button) $buttons .= ' & Speichern';
85 if (!$hide_save_button) $buttons .= '<input name="store" type="submit" value="Speichern"/>';
87 $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
88 $title = Title::newFromText($specialPageName, NS_SPECIAL);
89 $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
92 <form action="$specialPageUrl" method="post">
93 <table class="wrreportform" summary="Formular zum Eintragen eines Rodelbahnberichtes">
94 <tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_title" value="$page_title"/></td></tr>
95 <tr class="evenrow"><th>Datum des Rodelns</th>
97 <select name="date_report">
102 <tr class="oddrow"><th>Bahnzustand*</th><td><select name="condition">
105 <tr class="evenrow"><th>Meinung</th><td><textarea name="description" cols="50" rows="7">$description_html</textarea></td></tr>
106 <tr class="oddrow"><th>Autor/in</th><td><input name="author_name" maxlength="30" size="30" value="$author_name" /></td></tr>
107 <tr class="evenrow"><th>Bericht abschicken</th><td>$buttons</td></tr>
115 /// \brief Renders the form to delete a report
117 /// All in and output strings should be/are UTF-8 encoded.
118 function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible) {
120 $buttons = '<input name="deletepreview" type="submit" value="Vorschau" /> ';
121 $buttons .= utf8_encode('<input name="delete" type="submit" value="Löschen"/>');
122 $buttons .= '<input name="reportid" type="hidden" value="' . $reportid . '"/>';
123 // $buttons .= '<input name="delete_invisible" type="hidden" value="' . $delete_invisible . '"/>'; // who is allowed to do so?
124 $summary = utf8_encode('Formular zum Löschen eines Schneelageberichtes');
125 $reason = utf8_encode('Begründung');
126 $delete_reason_public_html = htmlspecialchars($delete_reason_public);
127 $delete_person_name_html = htmlspecialchars($delete_person_name);
129 $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
130 $title = Title::newFromText($specialPageName, NS_SPECIAL);
131 $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
134 <form action="$specialPageUrl" method="post">
135 <table class="wrreportform" summary="$summary">
136 <tr class="evenrow"><th>$reason</th><td><textarea name="delete_reason_public" cols="50" rows="7">$delete_reason_public_html</textarea></td></tr>
137 <tr class="oddrow"><th>Name</th><td><input name="delete_person_name" maxlength="30" size="30" value="$delete_person_name" /></td></tr>
138 <tr class="evenrow"><th>Aktion</th><td>$buttons</td></tr>
147 // Constants for wrReportTableRender2
148 define(WRREPORT_COMPACT_PAGE, 1); ///< includes the page name
149 define(WRREPORT_COMPACT, 2); ///< shown on a single page
150 define(WRREPORT_DETAIL, 3); ///< more columns
152 /// \brief Renders a table header ("private" sub-function of wrReportTableRender2)
154 /// \param $format row format like WRREPORT_COMPACT
155 /// \param $showActions boolean to indicate whether an actions column should be created
156 /// \return UTF-8 encoded titles of HTML table
157 function wrReportTableTitleRender2($format, $showActions) {
159 if ($format == WRREPORT_DETAIL) $out .= '<th>ID</th>';
160 if ($format != WRREPORT_COMPACT) $out .= '<th>Bahn</th>';
161 $out .= '<th>Datum</th>';
162 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Eintrag</th>';
163 if ($format == WRREPORT_DETAIL) $out .= '<th>Datum Ungültig</th>';
164 $out .= '<th>Zustand</th>';
165 $out .= '<th>Beschreibung</th>';
166 $out .= '<th>Autor</th>';
167 if ($showActions) $out .= '<th>Aktion</th>';
168 return utf8_encode($out . "</tr>\n");
172 /// \brief Renders a table row ("private" sub-function of wrReportTableRender2)
174 /// \param $row associative array of table columns like one row in the wrreport table
175 /// \param $format row format like WRREPORT_COMPACT
176 /// \param $showActions boolean to indicate whether an actions column should be created
177 /// \return UTF-8 encoded titles of HTML table
178 function wrReportTableRowRender2($row, $format, $showActions) {
183 if ($format == WRREPORT_DETAIL) $out .= '<td>' . $id . '</td>';
185 if ($format != WRREPORT_COMPACT) $out .= '<td>' . wrCommonSandboxParse('[[' . $page_title . ']]') . '</td>';
187 $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
188 $date_report = strtotime($date_report);
189 $date_report = $dayOfWeek[strftime('%u', $date_report)-1] . strftime(', %d.%m.', $date_report);
190 $out .= '<td>' . $date_report . '</td>';
192 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_entry)) . '</td>';
194 if ($format == WRREPORT_DETAIL) $out .= '<td>' . date('Y-m-d, H:i', strtotime($date_invalid)) . '</td>';
196 global $wrConditions;
197 $condition_text = '---';
198 if (isset($wrConditions[$condition])) $condition_text = $wrConditions[$condition];
200 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
201 else $out .= htmlspecialchars($condition_text);
204 $out .= '<td class="wrreportdescription">';
205 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
206 else $out .= wrCommonSandboxParse($description);
210 if ($delete_date) $out .= utf8_encode('<em>Gelöscht</em>');
211 else $out .= htmlspecialchars($author_name);
214 // wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
217 if (!isset($row['delete_date'])) {
218 $specialPageName = wfMsg('wrreport'); // 'Bahnberichte'
219 $title = Title::newFromText($specialPageName, NS_SPECIAL);
220 $specialPageUrl = $title->getLocalURL(); // e.g. '/wiki/Spezial:Bahnberichte'
221 $out .= "<a href=\"$specialPageUrl?action=deletepreview&reportid=" . $row['id'] . '">' . utf8_encode('Löschen...') . '</a>';
225 return $out . "</tr>\n";
229 /// \brief Renders the report table. Call wrReportGetReports for the $rows parameter.
231 /// \param $rows array of associative row arrays
232 /// \param $format row format like WRREPORT_TABLE_SHORT
233 function wrReportTableRender2($rows, $format, $showActions) {
234 $out = "<table class=\"wrreporttable\">\n" . wrReportTableTitleRender2($format, $showActions);
235 foreach ($rows as $key => $row) $out .= wrReportTableRowRender2($row, $format, $showActions);
236 return $out . "</table>\n";
240 /// Returns an array with column names
241 function wrReportGetColumnNames() {
242 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');
246 /// \brief Returns reports as associative array.
249 /// $conditions = array('page_title' => 'Birgitzer Alm', 'date_invalid > now()');
250 /// $order = 'date_report desc, date_entry desc';
251 function wrReportGetReports($conditions, $order) {
252 $dbr = wfGetDB(DB_SLAVE);
253 $columns = wrReportGetColumnNames();
255 if ($wgDBtype == "mysql") // "condition" is a reserved word in mysql
256 for ($i = 0; $i != count($columns); ++$i) $columns[$i] = sprintf('`%s`', $columns[$i]);
257 $res = $dbr->select('wrreport', $columns, $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc'));
259 while ($row = $dbr->fetchRow($res)) $result[] = $row;
260 $dbr->freeResult($res);
265 /// \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);
267 /// If no condition is present, array(NULL, NULL) is returned
268 function wrReportConditionRender($page_title) {
269 $dbr = wfGetDB(DB_SLAVE);
272 if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
273 $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, "$cond is not null", 'date_invalid > now()'));
274 // 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);
275 if ($res->numRows() <= 0) {
276 $dbr->freeResult($res);
277 return array(NULL, NULL);
279 $row = $dbr->fetchObject($res);
280 $dbr->freeResult($res);
281 $res = $dbr->select('wrreport', array($cond, 'date_report'), array('id' => $row->max));
282 if ($res->numRows() <= 0) {
283 $dbr->freeResult($res);
284 return array(NULL, NULL);
286 $row = $dbr->fetchObject($res);
287 $date = $row->date_report;
288 if ($date) $date = strtotime($date);
289 $dbr->freeResult($res);
290 return array($row->condition, $date);
294 /// \brief Returns true if the user is allowed to delete reports (in general)
295 function wrReportUserMayDelete() {
297 global $wgWrReportDeleteMode;
298 return $wgWrReportDeleteMode == 'allow' || ($wgWrReportDeleteMode == 'loggedin' && $wgUser->isLoggedIn());
303 // Parser Hook Functions
304 // ---------------------
306 /// \brief Is called when the tag <bahnberichtformular/> is encountered.
308 /// The current page name is taken.
309 function bahnberichtformularParserHook($input, $args, $parser) {
313 if ($wgUser->isLoggedIn()) {
314 $author_name = $wgUser->getRealName();
315 if (!$author_name) $author_name = $wgUser->getName();
318 global $wgWrReportMode;
319 global $wgWrReportBlackListAll;
320 global $wgWrReportBlackListStrangers;
321 if ($wgWrReportMode == 'summer') return wrCommonSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n"));
322 if ($wgWrReportMode == 'deny') return wrCommonSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n"));
324 if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrCommonSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n"));
326 if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrCommonSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
327 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"));
329 // Calling "$title = $parser->getTitle(); $title->invalidateCache();" doesn't help here to force regeneration
330 // However, this would not be the best solution because the page has to be re-rendered only at midnight
332 // In the following line, $author_name was replaced by NULL to prevent a bug, where the wrong author_name
333 // is shown (see ticket #35). TODO: Find reason.
334 // return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name), 'wrform');
335 return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL), 'wrform');
339 /// \brief Is called when the tag <bahnberichte/> is encountered.
341 /// The current page name is taken.
342 function bahnberichteParserHook($input, $args, &$parser) {
343 $page_title = $parser->getTitle()->getText();
344 $conditions = array('page_title' => $page_title, 'date_invalid > now()');
345 $order = 'date_report desc, date_entry desc';
346 $rows = wrReportGetReports($conditions, $order);
347 if (count($rows) == 0) return wrCommonSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
348 return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete());
352 /// \brief Is called when the tag <bahnbewertung/> is encountered.
354 /// * <bahnbewertung/>: The current page name is taken.
355 /// * <bahnbewertung>page_name</bahnbewertung>: The given page name is taken.
356 function bahnbewertungParserHook($input, $args, &$parser) {
358 if (!$titleText) $titleText = $parser->getTitle()->getText();
359 list($condition, $date) = wrReportConditionRender($titleText);
360 if ($date) $date = strftime('%d.%m.', $date);
361 global $wrConditions;
362 global $wrNewReportSection; // = utf8_encode('Eintragen');
363 global $wrShowReportsSection; // = utf8_encode('Einträge');
365 global $wgWrReportMode; // e.g. 'summer'
366 global $wgWrReportBlackListAll;
367 global $wgWrReportBlackListStrangers;
369 // Determine, whether the user is allowed to make a new report
370 $userMayReport = ($wgWrReportMode == 'allow' || ($wgWrReportMode == 'loggedin' && $wgUser->isLoggedIn()));
371 if ($userMayReport) {
372 if (in_array($titleText, $wgWrReportBlackListAll)) $userMayReport = false;
373 if (!$wgUser->isLoggedIn() && in_array($titleText, $wgWrReportBlackListStrangers)) $userMayReport = false;
376 // Get the condition and create the response wiki text
377 if (isset($wrConditions[$condition])) {
378 $wikiText = '[['. $titleText . '#' . $wrShowReportsSection . '|'. $wrConditions[$condition] . "]] <small>$date";
379 if ($userMayReport) $wikiText .= " ''[[" . $titleText . '#' . $wrNewReportSection . "|Neu]]''";
380 $wikiText .= "</small>";
382 if ($userMayReport) $wikiText = "<small>''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''</small>";
383 else $wikiText = '--';
385 return wrCommonSandboxParse($wikiText);
393 /// Specal Page to show reports
394 class WrReport extends SpecialPage {
395 function WrReport() {
396 SpecialPage::SpecialPage('WrReport');
397 wfLoadExtensionMessages('WrReport');
401 /// \param $par Possibilities:
402 /// - action == 'view' (default)
403 /// - action == 'preview': Preview new report
404 /// - action == 'store': Store new report
405 /// - action == 'deletepreview': Preview the deleted record
406 /// - action == 'delete': Delete an existing report
407 /// - action == 'showerror': Shows the error and exits
408 /// \param $override_action If not NULL (default), it overrides the action in $par
409 /// \param $errorMsg UFT-8 encoded error message (in WikiText) to show on top of the page or NULL (default):
410 function execute($par, $override_action = NULL, $errorMsg = NULL) {
411 global $wgRequest, $wgOut;
416 $action = $wgRequest->getText('action');
418 if ($wgRequest->getVal('preview')) $action = 'preview';
419 elseif ($wgRequest->getVal('store')) $action = 'store';
420 elseif ($wgRequest->getVal('deletepreview')) $action = 'deletepreview';
421 elseif ($wgRequest->getVal('delete')) $action = 'delete';
422 else $action = 'view';
424 if ($override_action) $action = $override_action;
426 // Show error message
427 if ($errorMsg || $action == 'showerror') {
428 $wgOut->addWikiText('<div class="errorbox">' . $errorMsg . "</div>\n");
429 if ($action == 'showerror') return;
433 if ($action == 'view') {
434 $conditions = array('date_invalid > now()');
435 $order = 'date_entry desc, date_report desc';
436 $rows = wrReportGetReports($conditions, $order);
437 if (count($rows) == 0) $wgOut->addWikiText("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
438 $wgOut->addHTML(wrReportTableRender2($rows, WRREPORT_DETAIL, wrReportUserMayDelete()));
441 // Action deletepreview or delete
442 elseif ($action == 'deletepreview' || $action == 'delete') {
443 $reportid = (int) $wgRequest->getText('reportid');
444 if ($reportid == 0) {
445 $this->execute($par, 'showerror', utf8_encode('Es wurde kein Bericht zum Löschen ausgewählt.'));
448 $rows = wrReportGetReports(array('id' => $reportid), '');
449 if (count($rows) != 1) {
450 $this->execute($par, 'showerror', utf8_encode('Es wurde ein ungültiger Bericht zum Löschen ausgewählt.'));
454 if (!is_null($row['delete_date'])) {
455 $this->execute($par, 'showerror', utf8_encode('Der angegebende Bericht ist bereits gelöscht.'));
458 $delete_reason_public = $wgRequest->getText('delete_reason_public');
459 $delete_person_name = $wgRequest->getText('delete_person_name');
460 $delete_invisible = $wgRequest->getText('delete_invisible') ? TRUE : FALSE;
461 if ($action == 'delete') {
463 $title = Title::newFromId($row['page_id']);
467 $delete_person_userid = $wgUser->getId();
468 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.
469 $delete_person_username = $wgUser->getName();
471 // Check permissions - see also function wrReportUserMayDelete, that does also check permissions but does not return an error message.
473 global $wgWrReportDeleteMode;
474 if ($wgWrReportDeleteMode == 'deny') $errorMsg = utf8_encode('Das Löschen von Rodelbahnberichten ist derzeit leider nicht erlaubt.');
475 elseif ($wgWrReportDeleteMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit dürfen nur angemeldete Benutzer Rodelbahnberichte löschen.');
476 elseif (!$delete_person_name || !$delete_reason_public) $errorMsg = utf8_encode('Es müssen sowohl die Begründung als auch der Name angegeben werden.');
478 $this->execute($par, 'deletepreview', $errorMsg);
482 // "Delete" (update) entry
483 $dbr = wfGetDB(DB_MASTER);
487 'delete_date' => date('c'),
488 'delete_person_name' => $delete_person_name,
489 'delete_person_ip' => $_SERVER['REMOTE_ADDR'],
490 'delete_person_userid' => $delete_person_userid,
491 'delete_person_username' => $delete_person_username,
492 'delete_reason_public' => $delete_reason_public,
493 'delete_invisible' => $delete_invisible ? 't' : 'f'
495 array('id' => $reportid)
499 $title->invalidateCache();
502 // Show success message
503 global $wrShowReportsSection;
504 $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"));
506 if ($action == 'deletepreview') {
507 $preview_msg = "Bitte nur dann einen Bericht löschen, wenn Gründe vorliegen wie\n" .
508 "* Beschimpfungen, Verleumdungen (wir wollen ''Rodelbahnen'' bewerten, nicht Personen)\n" .
509 "* Werbung oder Spam (wenn jemand allerdings ''werbend'' zu gute Noten vergibt, lieber eigenen Bericht eintragen als löschen).\n\n";
510 $wgOut->addWikiText(utf8_encode($preview_msg));
511 $wgOut->addWikiText(utf8_encode("== Schneelagebericht, um den es beim Löschen geht ==\n"));
512 $format = WRREPORT_COMPACT_PAGE;
513 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
514 $wgOut->addWikiText(utf8_encode("\n\n== Vorschau (derzeit noch nicht gelöscht) ==\n"));
515 $row['delete_date'] = date('c');
516 $row['delete_reason_public'] = $delete_reason_public;
517 $row['delete_person_name'] = $delete_person_name;
518 $row['delete_invisible'] = $delete_invisible;
519 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
520 $wgOut->addWikiText(utf8_encode("== Löschen ==\n"));
521 $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"));
522 $wgOut->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
526 // Action preview or store
527 elseif ($action == 'preview' || $action == 'store') {
528 $page_title = $wgRequest->getText('page_title');
529 $date_report = $wgRequest->getText('date_report');
530 $condition = $wgRequest->getText('condition');
531 $description = $wgRequest->getText('description');
532 $author_name = $wgRequest->getText('author_name');
533 if ($action == 'store') {
535 $title = Title::newFromText($page_title);
536 $page_id = $title->getArticleId();
537 if ($page_id == 0) $page_id = NULL;
541 $author_userid = $wgUser->getId();
542 if ($author_userid == 0) $author_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
543 $author_username = $wgUser->getName();
546 $condition_int = (int) $condition;
547 if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
548 else $condition = NULL;
550 // check conditions/permissions
552 global $wgWrReportMode;
553 global $wgWrReportBlackListAll;
554 global $wgWrReportBlackListStrangers;
555 if ($wgWrReportMode == 'summer') $errorMsg = utf8_encode('Rodelbahnberichte sind in der schneefreien Zeit nicht erlaubt.');
556 elseif ($wgWrReportMode == 'deny') $errorMsg = utf8_encode('Rodelbahnberichte sind derzeit leider nicht erlaubt.');
557 elseif ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) $errorMsg = utf8_encode('Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.');
558 elseif (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
559 elseif (in_array($page_title, $wgWrReportBlackListAll)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit keine Rodelbahnberichte abgegeben werden.');
560 elseif (!$wgUser->isLoggedIn() && in_array($page_title, $wgWrReportBlackListStrangers)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.');
561 elseif (!$condition && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung leer/nicht vergeben.');
562 elseif (!$wgUser->isLoggedIn()) {
563 if (!$description) $errorMsg = utf8_encode('Bitte bei der Beschreibung eine kurze Begründung für die Bewertung abgeben.');
564 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.');
567 // Chech whether identical reports are present
569 $dbr = wfGetDB(DB_SLAVE);
572 if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
573 $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, $cond => $condition, 'description' => $description, 'author_name' => $author_name);
574 $res = $dbr->select('wrreport', 'id', $sqlConditions);
575 if ($res->numRows() == 1) $errorMsg = utf8_encode('Der Rodelbahnbericht wurde bereits früher gespeichert.');
576 $dbr->freeResult($res);
581 $this->execute($par, 'preview', $errorMsg);
586 $dbr = wfGetDB(DB_MASTER);
590 'page_id' => $page_id,
591 'page_title' => $page_title,
592 'date_report' => $date_report,
593 'date_entry' => date('c'),
594 'date_invalid' => date('c', strtotime('+9 days')),
596 'description' => $description,
597 'author_name' => $author_name,
598 'author_ip' => $_SERVER['REMOTE_ADDR'],
599 'author_userid' => $author_userid,
600 'author_username' => $author_username
601 // 'delete_*' => // use database defaults (NULL)
606 $title->invalidateCache();
609 // Show success message
610 global $wrShowReportsSection;
611 $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n"));
612 // We could redirect to result with the following line but we don't want to.
613 // $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
615 if ($action == 'preview') {
616 $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
617 $format = WRREPORT_COMPACT_PAGE;
618 $row = array_fill_keys(wrReportGetColumnNames(), NULL);
619 $row['page_title'] = $page_title;
620 $row['date_report'] = $date_report;
621 $row['condition'] = $condition;
622 $row['description'] = $description;
623 $row['author_name'] = $author_name;
624 $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));
625 $wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
626 $wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
631 else die('Wrong action');