Renames in wrreport.body.php
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport.body.php
index 693ad9627d7e27c9f687f0b0082eaa596027800d..9c3e839493172046bfec5d4d8e27de35d419d7a9 100644 (file)
@@ -1,14 +1,23 @@
 <?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();
@@ -19,6 +28,7 @@ function wrReportSandboxParse($wikiText) {
 }
 
 
+/// List of markers - used by the functions replaceByMarker and wrReportAfterTidy
 $wrReportMarkerList = array();
 
 
@@ -31,12 +41,26 @@ function replaceByMarker($text, $marker = 'marker') {
 }
 
 
+/// 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
@@ -103,7 +127,7 @@ EOT;
 
 /// \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>';
@@ -118,7 +142,7 @@ function wrRenderReportTableTitle($page_id, $page_title, $date_report, $date_ent
 
 
 /// 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>';
@@ -138,7 +162,7 @@ function wrRenderReportTableRow($page_id, $page_title, $date_report, $date_entry
 /// 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();
@@ -147,11 +171,11 @@ function wrRenderReportTable($page_title = NULL) {
        $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 {
@@ -162,18 +186,37 @@ function wrRenderReportTable($page_title = NULL) {
 }
 
 
-/// 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 {
@@ -245,13 +288,4 @@ 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;
-}
-
-
 ?>