From d4d09dc22e4aa2ee0094dd6092908a3227401d5b Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 13 Dec 2024 21:42:43 +0000 Subject: [PATCH] [wiki] make formatting more consistent --- ext/wiki/main.php | 63 ---------------------------------------------- ext/wiki/theme.php | 48 ++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 45fe4843b..ecd6b18d9 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -389,67 +389,4 @@ public static function get_page(string $title, ?int $revision = null): WikiPage return new WikiPage($row); } - - public static function format_tag_wiki_page(WikiPage $page): string - { - global $database, $config; - - $row = $database->get_row(" - SELECT * - FROM tags - WHERE tag = :title - ", ["title" => $page->title]); - - if (!empty($row)) { - $template = $config->get_string(WikiConfig::TAG_PAGE_TEMPLATE); - - //ALIASES - $aliases = $database->get_col(" - SELECT oldtag - FROM aliases - WHERE newtag = :title - ORDER BY oldtag ASC - ", ["title" => $row["tag"]]); - - if (!empty($aliases)) { - $template = str_replace("{aliases}", implode(", ", $aliases), $template); - } else { - $template = str_replace("{aliases}", $config->get_string(WikiConfig::EMPTY_TAGINFO), $template); - } - - //Things before this line will be passed through html_escape. - $template = format_text($template); - //Things after this line will NOT be escaped!!! Be careful what you add. - - if (Extension::is_enabled(AutoTaggerInfo::KEY)) { - $auto_tags = $database->get_one(" - SELECT additional_tags - FROM auto_tag - WHERE tag = :title - ", ["title" => $row["tag"]]); - - if (!empty($auto_tags)) { - $auto_tags = Tag::explode($auto_tags); - $f_auto_tags = []; - - foreach ($auto_tags as $a_tag) { - $a_row = $database->get_row(" - SELECT * - FROM tags - WHERE tag = :title - ", ["title" => $a_tag]); - - $f_auto_tags[] = TagListTheme::return_tag($a_row)[1]; - } - - $template = str_replace("{autotags}", implode(", ", $f_auto_tags), $template); - } else { - $template = str_replace("{autotags}", format_text($config->get_string(WikiConfig::EMPTY_TAGINFO)), $template); - } - } - } - - //Insert page body AT LAST to avoid replacing its contents with the actions above. - return str_replace("{body}", format_text($page->body), $template ?? "{body}"); - } } diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index 792a6311b..c5720d14c 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -89,6 +89,52 @@ protected function create_edit_html(WikiPage $page): HTMLElement ); } + protected function format_wiki_page(WikiPage $page): HTMLElement + { + global $database, $config; + + $text = "{body}"; + + // if this is a tag page, add tag info + $tag = $database->get_one("SELECT tag FROM tags WHERE tag = :tag", ["tag" => $page->title]); + if (!is_null($tag)) { + $text = $config->get_string(WikiConfig::TAG_PAGE_TEMPLATE); + + if (Extension::is_enabled(AliasEditorInfo::KEY)) { + $aliases = $database->get_col(" + SELECT oldtag + FROM aliases + WHERE newtag = :title + ORDER BY oldtag ASC + ", ["title" => $tag]); + + if (!empty($aliases)) { + $text = str_replace("{aliases}", implode(", ", $aliases), $text); + } else { + $text = str_replace("{aliases}", $config->get_string(WikiConfig::EMPTY_TAGINFO), $text); + } + } + + if (Extension::is_enabled(AutoTaggerInfo::KEY)) { + $auto_tags = $database->get_one(" + SELECT additional_tags + FROM auto_tag + WHERE tag = :title + ", ["title" => $tag]); + + if (!empty($auto_tags)) { + $text = str_replace("{autotags}", $auto_tags, $text); + } else { + $text = str_replace("{autotags}", $config->get_string(WikiConfig::EMPTY_TAGINFO), $text); + } + } + } + + $text = str_replace("{body}", $page->body, $text); + + return rawHTML(format_text($text)); + } + protected function create_display_html(WikiPage $page): HTMLElement { global $user; @@ -96,7 +142,7 @@ protected function create_display_html(WikiPage $page): HTMLElement $u_title = url_escape($page->title); $owner = $page->get_owner(); - $formatted_body = rawHTML(Wiki::format_tag_wiki_page($page)); + $formatted_body = self::format_wiki_page($page); $edit = TR(); if (Wiki::can_edit($user, $page)) {