<?php
+// Init
+// ----
+
function wrReportParserInit() {
global $wgParser;
- $wgParser->setHook('bahnberichtformular', 'wrReportFormRender');
- $wgParser->setHook('bahnberichte', 'wrReportTableRender');
+ $wgParser->setHook('bahnberichtformular', 'bahnberichtformularParserHook');
+ $wgParser->setHook('bahnberichte', 'bahnberichteParserHook');
+ $wgParser->setHook('bahnbewertung', 'bahnbewertungParserHook');
return true;
}
+// Tool functions
+// --------------
+
+/// \brief This function is used to translate WikiText to HTML. Normally it should be avoided to do this
+/// but I found situations where I did not find an other possibility.
function wrReportSandboxParse($wikiText) {
global $wgTitle, $wgUser;
$myParser = new Parser();
}
+/// List of markers - used by the functions replaceByMarker and wrReportAfterTidy
$wrReportMarkerList = array();
}
+/// Replaces the markers by its contents
+function wrReportAfterTidy(&$parser, &$text) {
+ // find markers in $text
+ // replace markers with actual output
+ global $wrReportMarkerList;
+ foreach ($wrReportMarkerList as $marker => $html) $text = str_replace($marker, $html, $text);
+ return true;
+}
+
+
+
+// Render Functions
+// ----------------
+
/// \brief Returns a form to enter a report (string containing HTML).
///
/// All parameters have to be UTF-8 encoded.
/// \param $page_title Name of the sledding run.
/// \return UTF-8 encoded HTML form
-function wrRenderReportForm($hide_save_button = TRUE, $page_id = NULL, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
+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;
if ($page_title) $page_title = htmlspecialchars($page_title);
// Date options
/// \brief sub-function of wrRenderReportTable
/// \return UTF-8 encoded titles of HTML table
-function wrRenderReportTableTitle($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
+function wrReportTableTitleRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
$out = '<tr>';
if ($page_id) $out .= '<th>ID</th>';
if ($page_title) $out .= '<th>Bahn</th>';
/// sub-function of wrRenderReportTable
-function wrRenderReportTableRow($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
+function wrReportTableRowRender($page_id, $page_title, $date_report, $date_entry, $date_invalid, $condition, $description, $author_name) {
$out = "<tr>";
if (!is_null($page_id)) $out .= '<td>' . $page_id . '</td>';
if (!is_null($page_title)) $out .= '<td>' . wrReportSandboxParse('[[' . $page_title . ']]') . '</td>';
/// Is called when the tag <bahnberichte/> is encounted and renders a table /
/// \param $page_title If the name is specified (UTF-8 encoded), only reports of this "page" (e.g. 'Birgitzer Alm') is shown. Default: NULL
/// \return UTF-8 encoded HTML result table
-function wrRenderReportTable($page_title = NULL) {
+function wrReportTableRender($page_title = NULL) {
$out = '';
$dbr = wfGetDB(DB_SLAVE);
$conditions = array();
$admin = is_null($page_title);
if ($res->numRows() > 0) {
$out .= "<table class=\"wrreporttable\">\n";
- $out .= wrRenderReportTableTitle($admin, $admin, TRUE, $admin, $admin, TRUE, TRUE, TRUE);
+ $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 .= wrRenderReportTableRow($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 .= 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";
} else {
}
-/// Is called when the tag <<bahnberichtformular /> is encounted.
-function wrReportFormRender($input, $args, $parser) {
- return replaceByMarker(wrRenderReportForm(TRUE, $parser->getTitle()->getArticleID(), $parser->getTitle()->getText()));
+// Parser Hook Functions
+// ---------------------
+
+/// \brief Is called when the tag <bahnberichtformular/> is encountered.
+///
+/// The current page name is taken.
+function bahnberichtformularParserHook($input, $args, $parser) {
+ return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getArticleID(), $parser->getTitle()->getText()));
}
+/// \brief Is called when the tag <bahnberichte/> is encountered.
+///
+/// The current page name is taken.
+function bahnberichteParserHook($input, $args, &$parser) {
+ return wrReportTableRender($parser->getTitle()->getText());
+}
+
-function wrReportTableRender($input, $args, &$parser) {
- return wrRenderReportTable($parser->getTitle());
+/// \brief Is called when the tag <bahnbewertung/> is encountered.
+///
+/// * <bahnbewertung/>: The current page name is taken.
+/// * <bahnbewertung>page_name</bahnbewertung>: The given page name is taken.
+function bahnbewertungParserHook($input, $args, &$parser) {
+ if (!$input) $input = $parser->getTitle()->getText();
+ return wrReportConditionRender($input);
}
+// Special page
+// ------------
/// Specal Page to show reports
class WrReport extends SpecialPage {
}
-function wrReportAfterTidy(&$parser, &$text) {
- // find markers in $text
- // replace markers with actual output
- global $wrReportMarkerList;
- foreach ($wrReportMarkerList as $marker => $html) $text = str_replace($marker, $html, $text);
- return true;
-}
-
-
?>