X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/mediawiki_extensions/wrreport.git/blobdiff_plain/b78d1e728f8c912842b92c336393b67a3a5ecdc5..c03bf4dd0287f705cfb5c27542e6b102ccf1d5a4:/wrreport.body.php diff --git a/wrreport.body.php b/wrreport.body.php index 9c3e839..9bca401 100644 --- a/wrreport.body.php +++ b/wrreport.body.php @@ -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 = << - + "; if (!is_null($page_id)) $out .= ''; @@ -150,8 +150,8 @@ function wrReportTableRowRender($page_id, $page_title, $date_report, $date_entry if (!is_null($date_entry)) $out .= ''; if (!is_null($date_invalid)) $out .= ''; $out .= ''; - $out .= ''; - $out .= ''; + $out .= ''; + $out .= ''; $out .= "\n"; return $out; } @@ -174,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 .= "
Rodelbahn$page_title
Rodelbahn$page_title
Datum des Rodelns
' . $page_id . '' . date('Y-m-d, H:i', strtotime($date_entry)) . '' . date('Y-m-d, H:i', strtotime($date_invalid)) . '' . $condition . '' . $description . '' . $author_name . '' . htmlspecialchars($description) . '' . htmlspecialchars($author_name) . '
\n"; @@ -186,6 +185,22 @@ function wrReportTableRender($page_title = NULL) { } +/// \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 +function wrReportConditionRender($page_title) { + $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); + $row = $dbr->fetchObject($res); + $res = $dbr->select('wrreport', array('condition', 'date_report'), array('id' => $row->max)); + if ($res->numRows() <= 0) return array(NULL, NULL); + $row = $dbr->fetchObject($res); + return array($row->condition, $row->date_report); +} + + // Parser Hook Functions // --------------------- @@ -193,7 +208,13 @@ function wrReportTableRender($page_title = NULL) { /// /// 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)); } @@ -211,10 +232,12 @@ function bahnberichteParserHook($input, $args, &$parser) { /// * page_name: The given page name is taken. function bahnbewertungParserHook($input, $args, &$parser) { if (!$input) $input = $parser->getTitle()->getText(); - return wrReportConditionRender($input); + list($condition, $date) = wrReportConditionRender($input); + return "$condition ($date)"; } + // Special page // ------------ @@ -245,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 @@ -265,20 +301,27 @@ 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('

Bahnbericht gespeichert! :-)

'); + + // 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("

Vorschau (noch nicht gespeichert)

\n"); $wgOut->addHTML("\n"); - $wgOut->addHTML(wrRenderReportTableTitle(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE)); - $wgOut->addHTML(wrRenderReportTableRow(NULL, $page_title, $date_report, NULL, NULL, $condition, $description, $author_name)); + $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("
\n\n\n"); $wgOut->addHTML(utf8_encode("

Speichern oder Ändern

\n")); - $wgOut->addHTML(wrRenderReportForm(FALSE, $page_id, $page_title, $date_report, $condition, $description, $author_name)); + $wgOut->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $condition, $description, $author_name)); } }