X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/mediawiki_extensions/wrreport.git/blobdiff_plain/d0385aec2fbca17d5b7258ef1bad273efdf8030d..b156d161e1caa0a613b5a22a5b351275cca31205:/wrreport.body.php diff --git a/wrreport.body.php b/wrreport.body.php index 7df26b8..526e44d 100644 --- a/wrreport.body.php +++ b/wrreport.body.php @@ -17,41 +17,6 @@ function wrReportParserInit() { // 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(); - $myParserOptions = new ParserOptions(); - $myParserOptions->initialiseFromUser($wgUser); - $result = $myParser->parse($wikiText, $wgTitle, $myParserOptions); - return $result->getText(); -} - - -/// List of markers - used by the functions replaceByMarker and wrReportAfterTidy -$wrReportMarkerList = array(); - - -/// Returns a marker for a text and back-replaces the text in wrReportAfterTidy -function replaceByMarker($text, $marker = 'marker') { - $marker = $marker . mt_rand(1e5, 1e7); - global $wrReportMarkerList; - $wrReportMarkerList[$marker] = $text; - return $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; -} - - /// Forces a regeneration of region overview pages function wrRecacheRegions() { // TODO: Better implementation - it's a "quick fix" now. @@ -217,7 +182,7 @@ function wrReportTableRowRender2($row, $format, $showActions) { // $id if ($format == WRREPORT_DETAIL) $out .= '' . $id . ''; // $page_title - if ($format != WRREPORT_COMPACT) $out .= '' . wrReportSandboxParse('[[' . $page_title . ']]') . ''; + if ($format != WRREPORT_COMPACT) $out .= '' . wrCommonSandboxParse('[[' . $page_title . ']]') . ''; // $date_report $dayOfWeek = array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'); $date_report = strtotime($date_report); @@ -238,7 +203,7 @@ function wrReportTableRowRender2($row, $format, $showActions) { // $description $out .= ''; if ($delete_date) $out .= utf8_encode('Gelöscht'); - else $out .= wrReportSandboxParse($description); + else $out .= wrCommonSandboxParse($description); $out .= ''; // $author_name $out .= ''; @@ -289,7 +254,7 @@ function wrReportGetReports($conditions, $order) { global $wgDBtype; if ($wgDBtype == "mysql") // "condition" is a reserved word in mysql for ($i = 0; $i != count($columns); ++$i) $columns[$i] = sprintf('`%s`', $columns[$i]); - $res = $dbr->select('wrreport', $columns, $conditions, $fname = 'Database::select', $options = array('ORDER BY' => 'date_report desc, date_entry desc')); + $res = $dbr->select('wrreport', $columns, $conditions, 'wrReportGetReports', array('ORDER BY' => 'date_report desc, date_entry desc')); $result = array(); while ($row = $dbr->fetchRow($res)) $result[] = $row; $dbr->freeResult($res); @@ -297,23 +262,22 @@ function wrReportGetReports($conditions, $order) { } -/// \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); +/// \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); $cond = 'condition'; global $wgDBtype; + // select wrreport.id as report_id, `condition`, date_report from wrreport where page_title='Axamer Lizum' and `condition` is not null and date_invalid > now() and delete_date is null order by date_report desc, date_entry desc limit 1; if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql - $res = $dbr->select('wrreport', array('max(wrreport.id) as max'), array('page_title' => $page_title, "$cond 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) { - $dbr->freeResult($res); - return array(NULL, NULL); - } - $row = $dbr->fetchObject($res); - $dbr->freeResult($res); - $res = $dbr->select('wrreport', array($cond, 'date_report'), array('id' => $row->max)); + $res = $dbr->select( + 'wrreport', + array('wrreport.id as report_id', $cond, 'date_report'), + array('page_title' => $page_title, "$cond is not null", 'date_invalid > now()', 'delete_date is null'), + 'wrReportConditionRender', + array('ORDER BY' => 'date_report desc, date_entry desc', 'LIMIT' => '1') + ); if ($res->numRows() <= 0) { $dbr->freeResult($res); return array(NULL, NULL); @@ -353,21 +317,21 @@ function bahnberichtformularParserHook($input, $args, $parser) { global $wgWrReportMode; global $wgWrReportBlackListAll; global $wgWrReportBlackListStrangers; - if ($wgWrReportMode == 'summer') return wrReportSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n")); - if ($wgWrReportMode == 'deny') return wrReportSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n")); + if ($wgWrReportMode == 'summer') return wrCommonSandboxParse(utf8_encode("''An dieser Stelle kann während des Winters die Schneelage von Rodelbahnen eingetragen werden.''\n\n")); + if ($wgWrReportMode == 'deny') return wrCommonSandboxParse(utf8_encode("''Rodelbahnberichte sind derzeit leider nicht erlaubt.''\n\n")); - if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrReportSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n")); + if ($wgWrReportMode == 'loggedin' && !$wgUser->isLoggedIn()) return wrCommonSandboxParse(utf8_encode("''Derzeit sind Rodelbahnberichte nur für angemeldete Benutzer erlaubt.''\n\n")); - if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrReportSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n")); - if (!$wgUser->isLoggedIn() && in_array($parser->getTitle()->getText(), $wgWrReportBlackListStrangers)) return wrReportSandboxParse(utf8_encode("''Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.''\n\n")); + if (in_array($parser->getTitle()->getText(), $wgWrReportBlackListAll)) return wrCommonSandboxParse(utf8_encode("''Bei dieser Rodelbahn dürfen derzeit leider keine Rodelbahnberichte abgegeben werden.''\n")); + if (!$wgUser->isLoggedIn() && in_array($parser->getTitle()->getText(), $wgWrReportBlackListStrangers)) return wrCommonSandboxParse(utf8_encode("''Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.''\n\n")); // Calling "$title = $parser->getTitle(); $title->invalidateCache();" doesn't help here to force regeneration // However, this would not be the best solution because the page has to be re-rendered only at midnight // In the following line, $author_name was replaced by NULL to prevent a bug, where the wrong author_name // is shown (see ticket #35). TODO: Find reason. - // return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name)); - return replaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL)); + // return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, $author_name), 'wrform'); + return wrCommonReplaceByMarker(wrReportFormRender(TRUE, $parser->getTitle()->getText(), NULL, NULL, NULL, NULL), 'wrform'); } @@ -379,7 +343,7 @@ function bahnberichteParserHook($input, $args, &$parser) { $conditions = array('page_title' => $page_title, 'date_invalid > now()'); $order = 'date_report desc, date_entry desc'; $rows = wrReportGetReports($conditions, $order); - if (count($rows) == 0) return wrReportSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n"); + if (count($rows) == 0) return wrCommonSandboxParse("''Es wurden keine Bahnberichte in der Datenbank gefunden.''\n\n"); return wrReportTableRender2($rows, WRREPORT_COMPACT, wrReportUserMayDelete()); } @@ -417,7 +381,7 @@ function bahnbewertungParserHook($input, $args, &$parser) { if ($userMayReport) $wikiText = "''[[" . $titleText . '#' . $wrNewReportSection . "|Bitte eintragen]]''"; else $wikiText = '--'; } - return wrReportSandboxParse($wikiText); + return wrCommonSandboxParse($wikiText); }