Skip to content

Commit

Permalink
[wiki] make formatting more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 13, 2024
1 parent 54eb01d commit d4d09dc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 64 deletions.
63 changes: 0 additions & 63 deletions ext/wiki/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
48 changes: 47 additions & 1 deletion ext/wiki/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,60 @@ 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;

$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)) {
Expand Down

0 comments on commit d4d09dc

Please sign in to comment.