Skip to content

Commit

Permalink
[tag_list] Make return_tag static, see #1328
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 13, 2024
1 parent 8ed16ef commit 440866f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
22 changes: 7 additions & 15 deletions ext/tag_list/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public function display_split_related_block(Page $page, array $tag_infos): void
$tag_categories_count = [];

foreach ($tag_infos as $row) {
$split = self::return_tag($row, $tag_category_dict);
$category = $split[0];
$tag_html = $split[1];
[$category, $tag_html] = static::return_tag($row);
if (!isset($tag_categories_html[$category])) {
$tag_categories_html[$category] = $this->get_tag_list_preamble();
}
Expand All @@ -120,9 +118,9 @@ public function display_split_related_block(Page $page, array $tag_infos): void

foreach (array_keys($tag_categories_html) as $category) {
if ($tag_categories_count[$category] < 2) {
$category_display_name = html_escape($tag_category_dict[$category]['display_singular']);
$category_display_name = $tag_category_dict[$category]['display_singular'];
} else {
$category_display_name = html_escape($tag_category_dict[$category]['display_multiple']);
$category_display_name = $tag_category_dict[$category]['display_multiple'];
}
$page->add_block(new Block($category_display_name, rawHTML($tag_categories_html[$category]), "left", 9));
}
Expand All @@ -141,17 +139,10 @@ private function get_tag_list_html(array $tag_infos, string $sort): string
asort($tag_infos);
}

if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tag_category_dict = TagCategories::getKeyedDict();
} else {
$tag_category_dict = [];
}
$main_html = $this->get_tag_list_preamble();

foreach ($tag_infos as $row) {
$split = $this->return_tag($row, $tag_category_dict);
//$category = $split[0];
$tag_html = $split[1];
$tag_html = static::return_tag($row)[1];
$main_html .= "<tr>$tag_html</tr>";
}

Expand Down Expand Up @@ -210,13 +201,14 @@ public function display_refine_block(Page $page, array $tag_infos, array $search

/**
* @param array{tag: string, count: int} $row
* @param array<string, array{color: string}> $tag_category_dict
* @return array{0: string, 1: string}
*/
public function return_tag(array $row, array $tag_category_dict): array
public static function return_tag(array $row): array
{
global $config;

$tag_category_dict = TagCategories::getKeyedDict();

$display_html = '';
$tag = $row['tag'];
$h_tag = html_escape($tag);
Expand Down
24 changes: 8 additions & 16 deletions ext/wiki/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,26 +395,21 @@ 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]);
SELECT *
FROM tags
WHERE tag = :title
", ["title" => $page->title]);

if (!empty($row)) {
$template = $config->get_string(WikiConfig::TAG_PAGE_TEMPLATE);

//CATEGORIES
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tag_category_dict = TagCategories::getKeyedDict();
}

//ALIASES
$aliases = $database->get_col("
SELECT oldtag
FROM aliases
WHERE newtag = :title
ORDER BY oldtag ASC
", ["title" => $row["tag"]]);
", ["title" => $row["tag"]]);

if (!empty($aliases)) {
$template = str_replace("{aliases}", implode(", ", $aliases), $template);
Expand All @@ -431,23 +426,20 @@ public static function format_tag_wiki_page(WikiPage $page): string
SELECT additional_tags
FROM auto_tag
WHERE tag = :title
", ["title" => $row["tag"]]);
", ["title" => $row["tag"]]);

if (!empty($auto_tags)) {
$auto_tags = Tag::explode($auto_tags);
$f_auto_tags = [];

$tag_list_t = new TagListTheme();

foreach ($auto_tags as $a_tag) {
$a_row = $database->get_row("
SELECT *
FROM tags
WHERE tag = :title
", ["title" => $a_tag]);
", ["title" => $a_tag]);

$tag_html = $tag_list_t->return_tag($a_row, $tag_category_dict ?? []);
$f_auto_tags[] = $tag_html[1];
$f_auto_tags[] = TagListTheme::return_tag($a_row)[1];
}

$template = str_replace("{autotags}", implode(", ", $f_auto_tags), $template);
Expand Down

0 comments on commit 440866f

Please sign in to comment.