}
- /// 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) {
+ /// \param $override_action If not NULL (defualt), 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 ($override_action) $action = $override_action;
+ // Show error message
+ if ($errorMsg) {
+ $wgOut->addWikiText(utf8_encode('<div class="errorbox">') . $errorMsg . utf8_encode("</div>\n\n"));
+ }
+
+ // Action view
if ($action == 'view') {
$wgOut->addHTML(wrRenderReportTable());
}
+ // Action preview or store
elseif ($action == 'preview' || $action == 'store') {
$page_title = $wgRequest->getText('page_title');
$date_report = $wgRequest->getText('date_report');
// 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
if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
else $condition = NULL;
- // TODO: check conditions/permissions
+ // check conditions/permissions
+ $errorMsg = NULL;
+ if (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
+ elseif (!$wgUser->isLoggedIn()) {
+ if (!(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.');
+ }
+ if ($errorMsg) {
+ $this->execute($par, 'preview', $errorMsg);
+ return;
+ }
+
+ // Save entry
$dbr = wfGetDB(DB_MASTER);
$dbr->insert(
'wrreport',
// Purge cache
$title->invalidateCache();
// Show success message
- $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . utf8_encode('#Einträge|') . $page_title . utf8_encode(']] wurde erfolgreich gespeichert.</div>'));
+ $wgOut->addWikiText(utf8_encode('<div class="successbox">Der Bahnbericht für [[') . $page_title . utf8_encode('#Einträge|') . $page_title . utf8_encode("]] wurde erfolgreich gespeichert.</div>\n\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("<h3>Vorschau (noch nicht gespeichert)</h3>\n");
+ $wgOut->addWikiText(utf8_encode("== Vorschau (noch nicht gespeichert) ==\n"));
$wgOut->addHTML("<table class=\"wrreporttable\">\n");
$wgOut->addHTML(wrReportTableTitleRender(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE));
$wgOut->addHTML(wrReportTableRowRender(NULL, $page_title, $date_report, NULL, NULL, $condition, $description, $author_name));
- $wgOut->addHTML("</table>\n\n\n");
- $wgOut->addHTML(utf8_encode("<h3>Speichern oder Ändern</h3>\n"));
+ $wgOut->addHTML("</table>");
+ $wgOut->addWikiText("\n");
+ $wgOut->addWikiText(utf8_encode("== Speichern oder Ändern ==\n"));
$wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
}