Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wiki] make formatting more consistent #1346

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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