Skip to content

Commit

Permalink
Fix the handling of mentions with and without leading @
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Aug 18, 2023
1 parent 2a7c4b3 commit 1a3532b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions com.woltlab.wcf/bbcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
</bbcode>
<bbcode name="user">
<classname>wcf\system\bbcode\UserBBCode</classname>
<sourcecode>1</sourcecode>
<attributes>
<attribute name="0">
<validationpattern><![CDATA[^\d+$]]></validationpattern>
Expand All @@ -232,6 +233,7 @@
</attributes>
</bbcode>
<bbcode name="group">
<sourcecode>1</sourcecode>
<classname>wcf\system\bbcode\GroupBBCode</classname>
<attributes>
<attribute name="0">
Expand Down
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/groupBBCodeTag.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{if $group}
<span class="groupMention">{$group->getName()}</span>
{else}
@{$groupName}
{$groupName}
{/if}
2 changes: 1 addition & 1 deletion com.woltlab.wcf/templates/userBBCodeTag.tpl
Original file line number Diff line number Diff line change
@@ -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}
<a href="{link controller='User' object=$userProfile->getDecoratedObject()}{/link}" class="userMention userLink" data-object-id="{@$userProfile->userID}">{@$userProfile->getFormattedUsername()}</a>{* no newline after the tag
*}{/if}
2 changes: 1 addition & 1 deletion wcfsetup/install/files/acp/templates/userBBCodeTag.tpl
Original file line number Diff line number Diff line change
@@ -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}
<a href="{link controller='User' object=$userProfile->getDecoratedObject()}{/link}" class="userMention userLink" data-object-id="{@$userProfile->userID}">{@$userProfile->getFormattedUsername()}</a>{* no newline after the tag
*}{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
9 changes: 7 additions & 2 deletions wcfsetup/install/files/lib/system/bbcode/UserBBCode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 1a3532b

Please sign in to comment.