}
+/// Forces a regeneration of region overview pages
+function wrRecacheRegions() {
+ // TODO: Better implementation - it's a "quick fix" now.
+ $title = Title::newFromText('Tirol');
+ $title->invalidateCache();
+
+ $title = Title::newFromText('Vorarlberg');
+ $title->invalidateCache();
+
+ $title = Title::newFromText('Steiermark');
+ $title->invalidateCache();
+}
+
+
// Render Functions
// ----------------
// actions
// wiki/Spezial:Bahnberichte?action=deletepreview&reportid=42
if ($showActions) {
- if (!isset($row['delete_date'])) $out .= '<td><a href="/wiki/Spezial:Bahnberichte?action=deletepreview&reportid=' . $row['id'] . '">' . utf8_encode('Löschen...') . '</a></td>'; // TODO: Get rid of absolute URL
+ $out .= '<td>';
+ 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
+ $out .= '</td>';
}
return $out . "</tr>\n";
}
}
-
/// \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
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, 'condition is not null', 'date_invalid > now()'));
// 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);
- if ($res->numRows() <= 0) return array(NULL, NULL);
+ if ($res->numRows() <= 0) {
+ $dbr->freeResult($res);
+ return array(NULL, NULL);
+ }
$row = $dbr->fetchObject($res);
+ $dbr->freeResult($res);
$res = $dbr->select('wrreport', array('condition', 'date_report'), array('id' => $row->max));
- if ($res->numRows() <= 0) return array(NULL, NULL);
+ 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 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());
+}
+
+
+
// Parser Hook Functions
// ---------------------
if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrReportSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n"));
if (!$wgUser->isLoggedIn() && in_array($parser->getTitle()->getText(), $wgWrReportBlackListStrangers)) return wrReportSandboxParse(utf8_encode("''Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.''\n\n"));
+
+ // 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
+
return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
}
$order = 'date_report desc, date_entry desc';
$rows = wrReportGetReports($conditions, $order);
if (count($rows) == 0) return wrReportSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n");
- return wrReportTableRender2($rows, WRREPORT_COMPACT, true);
+ return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete());
}
$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, True));
+ $wgOut->addHTML(wrReportTableRender2($rows, WRREPORT_DETAIL, wrReportUserMayDelete()));
}
// Action deletepreview or delete
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
+ // 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.');
// Purge cache
$title->invalidateCache();
+ wrRecacheRegions();
+
// Show success message
global $wrShowReportsSection;
$wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $row['page_title'] . '#' . $wrShowReportsSection . '|' . $row['page_title'] . utf8_encode("]] wurde erfolgreich gelöscht.</div>\n"));
if (!$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);
+ $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, 'condition' => $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;
// Purge cache
$title->invalidateCache();
+ wrRecacheRegions();
+
// Show success message
global $wrShowReportsSection;
$wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . '#' . $wrShowReportsSection . '|' . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n"));