Skip to content

Commit

Permalink
[all] remove redundant html_escape in set_title/set_heading, remove r…
Browse files Browse the repository at this point in the history
…edundant formatting
  • Loading branch information
shish committed Dec 13, 2024
1 parent adac4f4 commit 372f5ae
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ext/comment/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function display_all_user_comments(array $comments, int $page_number, int
$h_index = "<a href='".make_link()."'>Index</a>";
$h_next = ($page_number >= $total_pages) ? "Next" : "<a href='$next'>Next</a>";

$page->set_title(html_escape($user->name)."'s comments");
$page->set_title("{$user->name}'s comments");
$page->add_block(new Block("Navigation", rawHTML($h_prev.' | '.$h_index.' | '.$h_next), "left", 0));
$this->display_paginator($page, "comment/beta-search/{$user->name}", null, $page_number, $total_pages);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/ext_manager/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public function display_doc(Page $page, ExtensionInfo $info): void
P(A(["href" => make_link("ext_manager")], "Back to the list"))
);

$page->set_title("Documentation for " . html_escape($info->name));
$page->set_heading(html_escape($info->name));
$page->set_title("Documentation for {$info->name}");
$page->set_heading($info->name);
$page->add_block(new NavBlock());
$page->add_block(new Block("Documentation", $html));
}
Expand Down
6 changes: 3 additions & 3 deletions ext/forum/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function display_new_thread_composer(Page $page, ?string $threadText = nu
);

$blockTitle = "Write a new thread";
$page->set_title(html_escape($blockTitle));
$page->set_title($blockTitle);
$page->add_block(new Block($blockTitle, $html, "main", 120));
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public function display_thread(array $posts, bool $showAdminOptions, string $thr
DIV(["class" => "postDate"], SMALL(rawHTML(autodate($post['date'])))),
DIV(["class" => "postNumber"], " #".$post_number),
BR(),
DIV(["class" => "postMessage"], rawHTML(send_event(new TextFormattingEvent($post["message"]))->formatted))
DIV(["class" => "postMessage"], rawHTML(format_text($post["message"])))
)
),
TR(
Expand Down Expand Up @@ -189,7 +189,7 @@ public function display_thread(array $posts, bool $showAdminOptions, string $thr

$this->display_paginator($page, "forum/view/".$threadID, null, $pageNumber, $totalPages);

$page->set_title(html_escape($threadTitle));
$page->set_title($threadTitle);
$page->add_block(new Block($threadTitle, $html, "main", 20));
}

Expand Down
5 changes: 1 addition & 4 deletions ext/index/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ protected function display_shortwiki(Page $page): void
$short_wiki_description = '';
if ($wikiPage->id != -1) {
// only show first line of wiki
$short_wiki_description = explode("\n", $wikiPage->body, 2)[0];

$tfe = send_event(new TextFormattingEvent($short_wiki_description));
$short_wiki_description = $tfe->formatted;
$short_wiki_description = format_text(explode("\n", $wikiPage->body, 2)[0]);
}
$wikiLink = make_link("wiki/$st");
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/pm/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function display_composer(Page $page, User $from, User $to, string $subje
public function display_message(Page $page, User $from, User $to, PM $pm): void
{
$page->set_title("Private Message");
$page->set_heading(html_escape($pm->subject));
$page->set_heading($pm->subject);
$page->add_block(new NavBlock());
$page->add_block(new Block("Message from {$from->name}", rawHTML(format_text($pm->message)), "main", 10));
}
Expand Down
3 changes: 1 addition & 2 deletions ext/pools/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ private function display_top(?Pool $pool, string $heading, bool $check_all = fal
$this->sidebar_options($page, $pool, $check_all);
}
}
$tfe = send_event(new TextFormattingEvent($pool->description));
$page->add_block(new Block(html_escape($pool->title), rawHTML($tfe->formatted), "main", 10));
$page->add_block(new Block($pool->title, rawHTML(format_text($pool->description)), "main", 10));
}
}

Expand Down
4 changes: 2 additions & 2 deletions ext/user/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function display_signup_page(Page $page): void
$tac = $config->get_string("login_tac", "");

if ($config->get_bool("login_tac_bbcode")) {
$tac = send_event(new TextFormattingEvent($tac))->formatted;
$tac = format_text($tac);
}

$email_required = (
Expand Down Expand Up @@ -246,7 +246,7 @@ public function display_user_page(User $duser, array $stats): void
global $page;
$stats[] = 'User ID: '.$duser->id;

$page->set_title(html_escape($duser->name)."'s Page");
$page->set_title("{$duser->name}'s Page");
$page->add_block(new NavBlock());
$page->add_block(new Block("Stats", rawHTML(join("<br>", $stats)), "main", 10));
}
Expand Down
2 changes: 1 addition & 1 deletion ext/view/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function display_page(Image $image, array $editor_parts): void
{
global $page;
$page->set_title("Post {$image->id}: ".$image->get_tag_list());
$page->set_heading(html_escape($image->get_tag_list()));
$page->set_heading($image->get_tag_list());
$page->add_block(new Block("Post {$image->id}", $this->build_navigation($image), "left", 0, "Navigationleft"));
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 20, "ImageInfo"));
//$page->add_block(new Block(null, $this->build_pin($image), "main", 11));
Expand Down
24 changes: 8 additions & 16 deletions ext/wiki/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,21 @@ public function display_page(Page $page, WikiPage $wiki_page, ?WikiPage $nav_pag
$nav_page->body = "";
}

$tfe = send_event(new TextFormattingEvent($nav_page->body));
$body_html = format_text($nav_page->body);

// only the admin can edit the sidebar
if ($user->can(Permissions::WIKI_ADMIN)) {
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar/edit")."'>Edit</a>)";
}

// see if title is a category'd tag
$title_html = html_escape($wiki_page->title);
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tagcategories = new TagCategories();
$tag_category_dict = $tagcategories->getKeyedDict();
$title_html = $tagcategories->getTagHtml($title_html, $tag_category_dict);
$body_html .= "<p>(<a href='".make_link("wiki/wiki:sidebar/edit")."'>Edit</a>)";
}

if (!$wiki_page->exists) {
$page->set_code(404);
}

$page->set_title(html_escape($wiki_page->title));
$page->set_title($wiki_page->title);
$page->add_block(new NavBlock());
$page->add_block(new Block("Wiki Index", rawHTML($tfe->formatted), "left", 20));
$page->add_block(new Block($title_html, $this->create_display_html($wiki_page)));
$page->add_block(new Block("Wiki Index", rawHTML($body_html), "left", 20));
$page->add_block(new Block($wiki_page->title, $this->create_display_html($wiki_page)));
}

/**
Expand All @@ -62,14 +54,14 @@ public function display_page_history(Page $page, string $title, array $history):
$html .= "<tr><td><a href='".make_link("wiki/$title", "revision=$rev")."'>{$rev}</a></td><td>{$row['date']}</td></tr>";
}
$html .= "</table>";
$page->set_title(html_escape($title));
$page->set_title($title);
$page->add_block(new NavBlock());
$page->add_block(new Block(html_escape($title), rawHTML($html)));
$page->add_block(new Block($title, rawHTML($html)));
}

public function display_page_editor(Page $page, WikiPage $wiki_page): void
{
$page->set_title(html_escape($wiki_page->title));
$page->set_title($wiki_page->title);
$page->add_block(new NavBlock());
$page->add_block(new Block("Editor", $this->create_edit_html($wiki_page)));
}
Expand Down
4 changes: 1 addition & 3 deletions themes/danbooru/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ public function display_user_block(Page $page, User $user, array $parts): void
public function display_signup_page(Page $page): void
{
global $config;
$tac = $config->get_string("login_tac", "");

$tac = send_event(new TextFormattingEvent($tac))->formatted;

$reca = "<tr><td colspan='2'>".captcha_get_html()."</td></tr>";

$tac = format_text($config->get_string("login_tac", ""));
if (empty($tac)) {
$html = "";
} else {
Expand Down
2 changes: 1 addition & 1 deletion themes/danbooru/view.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DanbooruViewPostTheme extends ViewPostTheme
public function display_page(Image $image, array $editor_parts): void
{
global $page;
$page->set_heading(html_escape($image->get_tag_list()));
$page->set_heading($image->get_tag_list());
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10));
Expand Down
4 changes: 1 addition & 3 deletions themes/danbooru2/user.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public function display_user_block(Page $page, User $user, array $parts): void
public function display_signup_page(Page $page): void
{
global $config, $user;
$tac = $config->get_string("login_tac", "");

$tac = send_event(new TextFormattingEvent($tac))->formatted;

$reca = "<tr><td colspan='2'>".captcha_get_html()."</td></tr>";

Expand All @@ -79,6 +76,7 @@ public function display_signup_page(Page $page): void
);
$email_text = $email_required ? "Email" : "Email (Optional)";

$tac = format_text($config->get_string("login_tac", ""));
if (empty($tac)) {
$html = "";
} else {
Expand Down
2 changes: 1 addition & 1 deletion themes/danbooru2/view.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Danbooru2ViewPostTheme extends ViewPostTheme
public function display_page(Image $image, array $editor_parts): void
{
global $page;
$page->set_heading(html_escape($image->get_tag_list()));
$page->set_heading($image->get_tag_list());
$page->add_block(new Block("Search", $this->build_navigation($image), "left", 0));
$page->add_block(new Block("Information", $this->build_information($image), "left", 15));
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 15));
Expand Down
2 changes: 1 addition & 1 deletion themes/futaba/view.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FutabaViewPostTheme extends ViewPostTheme
public function display_page(Image $image, array $editor_parts): void
{
global $page;
$page->set_heading(html_escape($image->get_tag_list()));
$page->set_heading($image->get_tag_list());
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 10));
}
}
2 changes: 1 addition & 1 deletion themes/lite/view.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function display_page(Image $image, array $editor_parts): void
{
global $page;
$page->set_title("Post {$image->id}: ".$image->get_tag_list());
$page->set_heading(html_escape($image->get_tag_list()));
$page->set_heading($image->get_tag_list());
$page->add_block(new Block("Navigation", $this->build_navigation($image), "left", 0));
$page->add_block(new Block("Statistics", $this->build_stats($image), "left", 15));
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 11));
Expand Down

0 comments on commit 372f5ae

Please sign in to comment.