From 974df48ee795144c8cb00ed47f1558f84b6c3086 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 20 Oct 2026 17:37:00 +0200 Subject: [PATCH] Hide profile content, avatar and cover photo of banned users and exclude them from the sitemap ref https://www.woltlab.com/community/thread/317190-disable-user-pages-for-banned-users/ --- com.woltlab.wcf/templates/user.tpl | 6 ++++- .../templates/userProfileHeader.tpl | 4 +-- .../files/lib/data/user/UserProfile.class.php | 21 +++++++++++++++ .../install/files/lib/page/UserPage.class.php | 8 +++++- .../object/UserSitemapObject.class.php | 9 +++++++ .../profile/UserProfileHeaderView.class.php | 27 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 8 files changed, 73 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/templates/user.tpl b/com.woltlab.wcf/templates/user.tpl index 099fbce7918..ea784d5bf85 100644 --- a/com.woltlab.wcf/templates/user.tpl +++ b/com.woltlab.wcf/templates/user.tpl @@ -58,7 +58,11 @@ {/foreach} {else} - {lang}wcf.user.profile.protected{/lang} + {if $user->isHiddenBecauseBanned()} + {lang}wcf.user.profile.banned{/lang} + {else} + {lang}wcf.user.profile.protected{/lang} + {/if} {/if} {include file='footer'} diff --git a/com.woltlab.wcf/templates/userProfileHeader.tpl b/com.woltlab.wcf/templates/userProfileHeader.tpl index 6a53e393e18..c43a5270077 100644 --- a/com.woltlab.wcf/templates/userProfileHeader.tpl +++ b/com.woltlab.wcf/templates/userProfileHeader.tpl @@ -4,7 +4,7 @@ >
- +
@@ -42,7 +42,7 @@
- {unsafe:$view->user->getAvatar()->getImageTag(128)} + {unsafe:$view->getAvatar()->getImageTag(128)} {if $view->user->isOnline()}{/if}
diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index 657f03f9f6b..32c8076ade3 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -733,9 +733,26 @@ public function isAccessible(string $name, ?int $userID = null): bool */ public function isProtected() { + if ($this->isHiddenBecauseBanned()) { + return true; + } + return !WCF::getSession()->hasPermission('admin.general.canViewPrivateUserOptions') && !$this->isAccessible('canViewProfile') && $this->userID !== WCF::getUser()->userID; } + /** + * Returns true if the profile content of this user is hidden from the active + * user because this user is banned. + * + * @since 6.3 + */ + public function isHiddenBecauseBanned(): bool + { + return $this->banned !== 0 + && $this->userID !== WCF::getUser()->userID + && !WCF::getSession()->hasPermission('admin.general.canViewPrivateUserOptions'); + } + /** * Returns the age of this user. * @@ -1115,6 +1132,10 @@ public function getUserCardOptions(): array */ private function getVisibleUserOption(string $name): ?UserOption { + if ($this->isHiddenBecauseBanned()) { + return null; + } + $option = UserOptionCacheBuilder::getInstance()->getData([], 'options')[$name] ?? null; if ($option === null) { return null; diff --git a/wcfsetup/install/files/lib/page/UserPage.class.php b/wcfsetup/install/files/lib/page/UserPage.class.php index 5cb75b5115a..96dca977b38 100644 --- a/wcfsetup/install/files/lib/page/UserPage.class.php +++ b/wcfsetup/install/files/lib/page/UserPage.class.php @@ -162,7 +162,9 @@ public function readData() $this->user->username . ' - ' . WCF::getLanguage()->get('wcf.user.members') . ' - ' . WCF::getLanguage()->get(\PAGE_TITLE), true ); - MetaTagHandler::getInstance()->addTag('og:image', 'og:image', $this->user->getAvatar()->getURL(), true); + if (!$this->user->isHiddenBecauseBanned()) { + MetaTagHandler::getInstance()->addTag('og:image', 'og:image', $this->user->getAvatar()->getURL(), true); + } } #[\Override] @@ -186,6 +188,10 @@ public function assignVariables() 'specialTrophyCount' => (\MODULE_TROPHY !== 0 ? \count($this->user->getSpecialTrophies()) : 0), 'userProfileHeaderView' => new UserProfileHeaderView($this->user), ]); + + if ($this->user->banned !== 0) { + WCF::getTPL()->assign('allowSpidersToIndexThisPage', false); + } } #[\Override] diff --git a/wcfsetup/install/files/lib/system/sitemap/object/UserSitemapObject.class.php b/wcfsetup/install/files/lib/system/sitemap/object/UserSitemapObject.class.php index dbda0dec4e1..590581a26ac 100755 --- a/wcfsetup/install/files/lib/system/sitemap/object/UserSitemapObject.class.php +++ b/wcfsetup/install/files/lib/system/sitemap/object/UserSitemapObject.class.php @@ -24,6 +24,15 @@ public function getObjectClass() return User::class; } + #[\Override] + public function getObjectList() + { + $userList = new UserList(); + $userList->getConditionBuilder()->add('user_table.banned = ?', [0]); + + return $userList; + } + #[\Override] public function getLastModifiedColumn(): string { diff --git a/wcfsetup/install/files/lib/system/view/user/profile/UserProfileHeaderView.class.php b/wcfsetup/install/files/lib/system/view/user/profile/UserProfileHeaderView.class.php index 38cb4f956db..63ed1d971fe 100644 --- a/wcfsetup/install/files/lib/system/view/user/profile/UserProfileHeaderView.class.php +++ b/wcfsetup/install/files/lib/system/view/user/profile/UserProfileHeaderView.class.php @@ -2,6 +2,9 @@ namespace wcf\system\view\user\profile; +use wcf\data\user\avatar\DefaultAvatar; +use wcf\data\user\avatar\IUserAvatar; +use wcf\data\user\cover\photo\IUserCoverPhoto; use wcf\data\user\group\UserGroup; use wcf\data\user\UserProfile; use wcf\event\user\profile\UserProfileHeaderSearchContentLinkCollecting; @@ -93,6 +96,30 @@ public function getManagementContextMenu(): StandaloneInteractionContextMenuComp return $this->managementContextMenu; } + /** + * @since 6.3 + */ + public function getAvatar(): IUserAvatar + { + if ($this->user->isHiddenBecauseBanned()) { + return new DefaultAvatar($this->user->username); + } + + return $this->user->getAvatar(); + } + + /** + * @since 6.3 + */ + public function getCoverPhoto(): IUserCoverPhoto + { + if ($this->user->isHiddenBecauseBanned()) { + return $this->user->getDefaultCoverPhoto(); + } + + return $this->user->getCoverPhoto(); + } + public function canEditUser(): bool { return $this->user->canEdit() || (WCF::getUser()->userID === $this->user->userID && $this->user->canEditOwnProfile()); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index a0beaad24b4..cfcd34d615e 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -5388,6 +5388,7 @@ Benachrichtigungen auf {PAGE_TITLE|phra {$author} hat auf einen Kommentar von {$commentAuthor} an der Pinnwand von {$user} geantwortet.]]> + username}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 8f1a9a8fe51..42785bfa977 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -5383,6 +5383,7 @@ your notifications on {PAGE_TITLE|phras {$author} replied to a comment by {$commentAuthor} on {$user}’s wall.]]> + username}]]>