/// 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');
$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">
$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";
///
/// 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));
}
}
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
'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");
$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));
}
}