From 131f10202f189198dd2d36859d04a2e77a811e76 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 11 Oct 2026 13:32:18 +0200 Subject: [PATCH] Add per-user article list page and link it from the user profile header ref https://www.woltlab.com/community/thread/313959-alle-artikel-eines-benutzers-anzeigen/ --- com.woltlab.wcf/page.xml | 10 ++++ com.woltlab.wcf/templates/userArticleList.tpl | 10 ++++ .../lib/page/UserArticleListPage.class.php | 60 +++++++++++++++++++ .../user/UserArticleListView.class.php | 50 ++++++++++++++++ .../UserArticleListPageHandler.class.php | 29 +++++++++ .../profile/UserProfileHeaderView.class.php | 13 +++- wcfsetup/install/lang/de.xml | 4 ++ wcfsetup/install/lang/en.xml | 4 ++ 8 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 com.woltlab.wcf/templates/userArticleList.tpl create mode 100644 wcfsetup/install/files/lib/page/UserArticleListPage.class.php create mode 100644 wcfsetup/install/files/lib/system/listView/user/UserArticleListView.class.php create mode 100644 wcfsetup/install/files/lib/system/page/handler/UserArticleListPageHandler.class.php diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index afd70f9edd1..c3acbad30a7 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -605,6 +605,16 @@ 1 1 + + system + wcf\page\UserArticleListPage + Artikel eines bestimmten Benutzers + Articles of Certain User + wcf\system\page\handler\UserArticleListPageHandler + com.woltlab.wcf.ArticleList + module_article + 1 + system wcf\page\ArticlePage diff --git a/com.woltlab.wcf/templates/userArticleList.tpl b/com.woltlab.wcf/templates/userArticleList.tpl new file mode 100644 index 00000000000..cecd3a533cf --- /dev/null +++ b/com.woltlab.wcf/templates/userArticleList.tpl @@ -0,0 +1,10 @@ +{capture assign='contentTitle'}{lang}wcf.article.userArticles{/lang}{/capture} +{capture assign='pageTitle'}{lang}wcf.article.userArticles{/lang}{/capture} + +{include file='header'} + +
+ {unsafe:$listView->render()} +
+ +{include file='footer'} diff --git a/wcfsetup/install/files/lib/page/UserArticleListPage.class.php b/wcfsetup/install/files/lib/page/UserArticleListPage.class.php new file mode 100644 index 00000000000..3bdfb08217a --- /dev/null +++ b/wcfsetup/install/files/lib/page/UserArticleListPage.class.php @@ -0,0 +1,60 @@ + + * @since 6.3 + * + * @extends AbstractListViewPage + */ +class UserArticleListPage extends AbstractListViewPage +{ + /** + * @inheritDoc + */ + public $neededModules = ['MODULE_ARTICLE']; + + public User $user; + + #[\Override] + public function readParameters(): void + { + parent::readParameters(); + + $this->user = Helper::fetchObjectFromQueryParameter(User::class); + } + + #[\Override] + public function assignVariables(): void + { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'user' => $this->user, + ]); + } + + #[\Override] + protected function createListView(): UserArticleListView + { + return new UserArticleListView($this->user->userID); + } + + #[\Override] + protected function getBaseUrlParameters(): array + { + return [ + 'object' => $this->user, + ]; + } +} diff --git a/wcfsetup/install/files/lib/system/listView/user/UserArticleListView.class.php b/wcfsetup/install/files/lib/system/listView/user/UserArticleListView.class.php new file mode 100644 index 00000000000..0f181b9abb9 --- /dev/null +++ b/wcfsetup/install/files/lib/system/listView/user/UserArticleListView.class.php @@ -0,0 +1,50 @@ + + * @since 6.3 + */ +class UserArticleListView extends ArticleListView +{ + public function __construct(public readonly int $userID) + { + parent::__construct(); + } + + #[\Override] + protected function createObjectList(): AccessibleArticleList + { + $list = parent::createObjectList(); + $list->getConditionBuilder()->add('article.userID = ?', [$this->userID]); + + return $list; + } + + #[\Override] + public function addAvailableFilters(array $filters): void + { + // Remove useless username filter. + $filters = \array_filter( + $filters, + static fn($filter) => $filter->getId() !== 'username' + ); + + parent::addAvailableFilters($filters); + } + + #[\Override] + public function getParameters(): array + { + return [ + 'userID' => $this->userID, + ]; + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/UserArticleListPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/UserArticleListPageHandler.class.php new file mode 100644 index 00000000000..064a6c1e575 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/UserArticleListPageHandler.class.php @@ -0,0 +1,29 @@ + + * @since 6.3 + */ +final class UserArticleListPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler +{ + use TUserLookupPageHandler; + use TUserOnlineLocationPageHandler; + + #[\Override] + public function getLink(int $objectID): string + { + return LinkHandler::getInstance()->getControllerLink(UserArticleListPage::class, [ + 'object' => UserRuntimeCache::getInstance()->getObject($objectID), + ]); + } +} 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 edd04a1fbce..dc1dd1ffc0e 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 @@ -7,6 +7,7 @@ use wcf\event\user\profile\UserProfileHeaderSearchContentLinkCollecting; use wcf\event\user\profile\UserProfileStatItemCollecting; use wcf\page\MembersListPage; +use wcf\page\UserArticleListPage; use wcf\system\event\EventHandler; use wcf\system\interaction\InteractionContextMenuComponentConfiguration; use wcf\system\interaction\StandaloneInteractionContextMenuComponent; @@ -129,9 +130,19 @@ private function initStatItems(): void private function initSearchContentLinks(): void { + if (\MODULE_ARTICLE !== 0 && $this->user->articles !== 0) { + $this->searchContentLinks[] = new UserProfileHeaderViewSearchContentLink( + WCF::getLanguage()->get('wcf.article.articles'), + LinkHandler::getInstance()->getControllerLink( + UserArticleListPage::class, + ['object' => $this->user] + ) + ); + } + $event = new UserProfileHeaderSearchContentLinkCollecting($this->user); EventHandler::getInstance()->fire($event); - $this->searchContentLinks = $event->getLinks(); + $this->searchContentLinks = [...$this->searchContentLinks, ...$event->getLinks()]; } private function initInteractionContextMenu(): void diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f5384505b45..76561c2604a 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3320,6 +3320,7 @@ freigeschaltet. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if + username}]]> @@ -4393,6 +4394,7 @@ Erlaubte Dateiendungen: gif, jpg, jpeg, png, webp]]> getLink()}">{$article->getTitle()}]]> getLink()}">{$category->getTitle()}]]> userID}">{$user->username}]]> + Artikel von {$user->username}]]> Aktualisierungen für installierte Pakete verfügbar.]]> @@ -4411,10 +4413,12 @@ Erlaubte Dateiendungen: gif, jpg, jpeg, png, webp]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 66b17651452..35f06cddc81 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3245,6 +3245,7 @@ Your account on {@PAGE_TITLE|phrase} [URL:{link isEmail=true}{/link}] has been a + username}]]> @@ -4339,6 +4340,7 @@ Allowed extensions: gif, jpg, jpeg, png, webp]]> getLink()}">{$article->getTitle()}]]> getLink()}">{$category->getTitle()}]]> userID}">{$user->username}]]> + Articles by {$user->username}]]> updates available for installed packages.]]> @@ -4357,10 +4359,12 @@ Allowed extensions: gif, jpg, jpeg, png, webp]]> + +