Implemented user name functionality and cache purge when reporting condition
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 25 Oct 2008 21:25:05 +0000 (21:25 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 25 Oct 2008 21:25:05 +0000 (21:25 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/extensions/wrreport@284 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index 97c1ae200e25ad30d316397e908f041830990837..9bca4014c88b283201fabdf96b10d6e12f0368a0 100644 (file)
@@ -60,8 +60,7 @@ function wrReportAfterTidy(&$parser, &$text) {
 /// All parameters have to be UTF-8 encoded.
 /// \param $page_title Name of the sledding run.
 /// \return UTF-8 encoded HTML form
-function wrReportFormRender($hide_save_button = TRUE, $page_id = NULL, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
-       if ($page_id) $page_id = (int) $page_id;
+function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
        if ($page_title) $page_title = htmlspecialchars($page_title);
        // Date options
        $tagnamen = array('Heute', 'Gestern', 'Vorgestern', 'Vor 3 Tagen', 'Vor 4 Tagen');
@@ -103,7 +102,7 @@ function wrReportFormRender($hide_save_button = TRUE, $page_id = NULL, $page_tit
        $form = <<<EOT
 <form action="/wiki/Spezial:Bahnberichte" method="post">
 <table class="wrreportform" summary="Formular zum Eintragen eines Rodelbahnberichtes">
-       <tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_id" value="$page_id"/><input type="hidden" name="page_title" value="$page_title"/></td></tr>
+       <tr class="oddrow"><th>Rodelbahn</th><td>$page_title<input type="hidden" name="page_title" value="$page_title"/></td></tr>
        <tr class="evenrow"><th>Datum des Rodelns</th>
        <td>
        <select name="date_report">
@@ -175,7 +174,6 @@ function wrReportTableRender($page_title = NULL) {
                $out .= wrReportTableTitleRender($admin, $admin, TRUE, $admin, $admin, TRUE, TRUE, TRUE);
                while ($row = $dbr->fetchObject($res)) {
                        $author = $row->author_name;
-                       if ($row->author_username) $author .= ' (' . $row->author_username . ')';
                        $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);
                }
                $out .= "</table>\n";
@@ -210,7 +208,13 @@ function wrReportConditionRender($page_title) {
 ///
 /// The current page name is taken.
 function bahnberichtformularParserHook($input, $args, $parser) {
-       return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getArticleID(), $parser->getTitle()->getText()));
+       global $wgUser;
+       $author_name = NULL;
+       if ($wgUser->isLoggedIn()) {
+               $author_name = $wgUser->getRealName();
+               if (!$author_name) $author_name = $wgUser->getName();
+       }
+       return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name));
 }
 
 
@@ -264,19 +268,32 @@ class WrReport extends SpecialPage {
                }
 
                elseif ($action == 'preview' || $action == 'store') {
-                       $page_id = $wgRequest->getText('page_id');
                        $page_title = $wgRequest->getText('page_title');
                        $date_report = $wgRequest->getText('date_report');
                        $condition = $wgRequest->getText('condition');
                        $description = $wgRequest->getText('description');
                        $author_name = $wgRequest->getText('author_name');
                        if ($action == 'store') {
+                               // page_id
+                               $title = Title::newFromText($page_title);
+                               $page_id = $title->getArticleId();
+                               
+                               // user_id
+                               global $wgUser;
+                               $author_userid = $wgUser->getId();
+                               $author_username = $wgUser->getName();
+
+                               // condition
+                               $condition_int = (int) $condition;
+                               if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
+                               else $condition = NULL;
+                               
                                // TODO: check conditions/permissions
                                $dbr = wfGetDB(DB_MASTER);
                                $dbr->insert(
                                        'wrreport', 
                                        array(
-                                               'page_id' => (int) $page_id, 
+                                               'page_id' => $page_id, 
                                                'page_title' => $page_title, 
                                                'date_report' => $date_report, 
                                                // 'date_entry' => '',  // use database default
@@ -284,11 +301,18 @@ class WrReport extends SpecialPage {
                                                'condition' => $condition,
                                                'description' => $description,
                                                'author_name' => $author_name,
-                                               'author_username' => '',
-                                               'author_ip' => $_SERVER['REMOTE_ADDR']
+                                               'author_ip' => $_SERVER['REMOTE_ADDR'],
+                                               'author_userid' => $author_userid,
+                                               'author_username' => $author_username
                                        )
                                );
-                               $wgOut->addHTML('<p>Bahnbericht gespeichert! :-)</p>');
+
+                               // Show success message (TODO)
+                               // $wgOut->addHTML('Bahnbericht für [[$page_title]] gespeichert! :-)');
+                               // Purge cache
+                               Article::onArticleEdit($title);
+                               // Redirect to result
+                               $wgOut->redirect($title->getFullURL() . '#Eintr.C3.A4ge');
                        }
                        if ($action == 'preview') {
                                $wgOut->addHTML("<h3>Vorschau (noch nicht gespeichert)</h3>\n");
@@ -297,7 +321,7 @@ class WrReport extends SpecialPage {
                                $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(wrReportFormRender(FALSE, $page_id, $page_title, $date_report, $condition, $description, $author_name));
+                               $wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name));
                        } 
                        
                }