Implemented error reporting mechanism.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 26 Oct 2008 21:35:12 +0000 (21:35 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 26 Oct 2008 21:35:12 +0000 (21:35 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/extensions/wrreport@286 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index 07a2f19c2e0674b79c8609d506dddc175b2df880..d554e6542f1b89118a64a2bd3c36ee5792f6e199 100644 (file)
@@ -249,24 +249,33 @@ class WrReport extends SpecialPage {
        }
 
 
-       /// 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');
@@ -277,10 +286,12 @@ class WrReport extends SpecialPage {
                                // 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
@@ -288,7 +299,18 @@ class WrReport extends SpecialPage {
                                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', 
@@ -310,17 +332,18 @@ class WrReport extends SpecialPage {
                                // 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));
                        }