From 1a3532b52c1e07898c03307608a3151477bb6fda Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 18 Aug 2023 17:10:41 +0200 Subject: [PATCH] Fix the handling of mentions with and without leading `@` --- com.woltlab.wcf/bbcode.xml | 2 ++ com.woltlab.wcf/templates/groupBBCodeTag.tpl | 2 +- com.woltlab.wcf/templates/userBBCodeTag.tpl | 2 +- wcfsetup/install/files/acp/templates/userBBCodeTag.tpl | 2 +- .../files/lib/system/bbcode/GroupBBCode.class.php | 9 +++++++-- .../install/files/lib/system/bbcode/UserBBCode.class.php | 9 +++++++-- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/com.woltlab.wcf/bbcode.xml b/com.woltlab.wcf/bbcode.xml index 074a6322e05..5f84ea27a5f 100644 --- a/com.woltlab.wcf/bbcode.xml +++ b/com.woltlab.wcf/bbcode.xml @@ -208,6 +208,7 @@ wcf\system\bbcode\UserBBCode + 1 @@ -232,6 +233,7 @@ + 1 wcf\system\bbcode\GroupBBCode diff --git a/com.woltlab.wcf/templates/groupBBCodeTag.tpl b/com.woltlab.wcf/templates/groupBBCodeTag.tpl index 74ae8bfc523..177ae1c6128 100644 --- a/com.woltlab.wcf/templates/groupBBCodeTag.tpl +++ b/com.woltlab.wcf/templates/groupBBCodeTag.tpl @@ -1,5 +1,5 @@ {if $group} {$group->getName()} {else} - @{$groupName} + {$groupName} {/if} diff --git a/com.woltlab.wcf/templates/userBBCodeTag.tpl b/com.woltlab.wcf/templates/userBBCodeTag.tpl index dbe32b29d2a..369371df25c 100644 --- a/com.woltlab.wcf/templates/userBBCodeTag.tpl +++ b/com.woltlab.wcf/templates/userBBCodeTag.tpl @@ -1,6 +1,6 @@ {if $userProfile === null} {* user no longer exists, use plain output rather than using a broken link *} - @{$username}{* no newline after the tag + {$username}{* no newline after the tag *}{else} {@$userProfile->getFormattedUsername()}{* no newline after the tag *}{/if} diff --git a/wcfsetup/install/files/acp/templates/userBBCodeTag.tpl b/wcfsetup/install/files/acp/templates/userBBCodeTag.tpl index dbe32b29d2a..369371df25c 100644 --- a/wcfsetup/install/files/acp/templates/userBBCodeTag.tpl +++ b/wcfsetup/install/files/acp/templates/userBBCodeTag.tpl @@ -1,6 +1,6 @@ {if $userProfile === null} {* user no longer exists, use plain output rather than using a broken link *} - @{$username}{* no newline after the tag + {$username}{* no newline after the tag *}{else} {@$userProfile->getFormattedUsername()}{* no newline after the tag *}{/if} diff --git a/wcfsetup/install/files/lib/system/bbcode/GroupBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/GroupBBCode.class.php index 42160201b0c..a58e949029a 100644 --- a/wcfsetup/install/files/lib/system/bbcode/GroupBBCode.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/GroupBBCode.class.php @@ -20,10 +20,15 @@ final class GroupBBCode extends AbstractBBCode */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser): string { - $groupID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0; + $content = $openingTag['attributes'][0]; + if (!\str_starts_with($content, '@')) { + $content = "@{$content}"; + } + + $groupID = (!empty($openingTag['attributes'][1])) ? \intval($openingTag['attributes'][1]) : 0; $group = UserGroup::getGroupByID($groupID); if ($group === null || !$group->canBeMentioned()) { - return "[group]{$content}[/group]"; + return $content; } return WCF::getTPL()->fetch('groupBBCodeTag', 'wcf', [ diff --git a/wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php index d96c4b5d2e9..33d3c1c82ea 100644 --- a/wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php @@ -21,9 +21,14 @@ final class UserBBCode extends AbstractBBCode */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser): string { - $userID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0; + $content = $openingTag['attributes'][0]; + if (!\str_starts_with($content, '@')) { + $content = "@{$content}"; + } + + $userID = (!empty($openingTag['attributes'][1])) ? \intval($openingTag['attributes'][1]) : 0; if (!$userID) { - return "[user]{$content}[/user]"; + return $content; } /** @var UserProfile $userProfile */