Skip to content

Commit ee7f84d

Browse files
committed
Apply changes to UserProfileCommentManager and LikeableArticleProvider
1 parent ba311df commit ee7f84d

8 files changed

Lines changed: 58 additions & 162 deletions

File tree

com.woltlab.wcf/templates/userProfileLikeItem.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</h3>
1818

1919
{if $like->getDescription()}
20-
<div class="recentActivityListItem__description{if !$like->isRawHtml()} htmlContent{/if}">
20+
<div class="recentActivityListItem__description">
2121
{unsafe:$like->getDescription()}
2222
</div>
2323
{/if}

wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
use wcf\data\like\ILikeObjectTypeProvider;
66
use wcf\data\like\object\ILikeObject;
77
use wcf\data\object\type\AbstractObjectTypeProvider;
8+
use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
89
use wcf\system\like\IViewableLikeProvider;
910
use wcf\system\WCF;
1011

1112
/**
12-
* Like Object type provider for cms articles.
13+
* Like object type provider for cms articles.
1314
*
14-
* @author Marcel Werk
15-
* @copyright 2001-2019 WoltLab GmbH
16-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17-
* @since 3.0
15+
* @author Marcel Werk
16+
* @copyright 2001-2026 WoltLab GmbH
17+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1818
*
1919
* @extends AbstractObjectTypeProvider<LikeableArticle>
2020
* @implements ILikeObjectTypeProvider<LikeableArticle>
@@ -38,54 +38,42 @@ class LikeableArticleProvider extends AbstractObjectTypeProvider implements
3838
*/
3939
public $decoratorClassName = LikeableArticle::class;
4040

41-
/**
42-
* @inheritDoc
43-
*/
41+
#[\Override]
4442
public function checkPermissions(ILikeObject $object)
4543
{
46-
/** @var LikeableArticle $object */
44+
\assert($object instanceof LikeableArticle);
45+
4746
return $object->articleID && $object->canRead();
4847
}
4948

50-
/**
51-
* @inheritDoc
52-
*/
49+
#[\Override]
5350
public function prepare(array $likes)
5451
{
55-
$articleIDs = [];
52+
$objectIDs = [];
5653
foreach ($likes as $like) {
57-
$articleIDs[] = $like->objectID;
54+
$objectIDs[] = $like->objectID;
5855
}
5956

60-
// fetch articles
61-
$articleList = new ViewableArticleList();
62-
$articleList->setObjectIDs($articleIDs);
63-
$articleList->readObjects();
64-
$articles = $articleList->getObjects();
57+
ViewableArticleRuntimeCache::getInstance()->cacheObjectIDs($objectIDs);
6558

66-
// set message
6759
foreach ($likes as $like) {
68-
if (isset($articles[$like->objectID])) {
69-
$article = $articles[$like->objectID];
60+
$article = ViewableArticleRuntimeCache::getInstance()->getObject($like->objectID);
61+
if ($article === null || !$article->canRead()) {
62+
continue;
63+
}
7064

71-
// check permissions
72-
if (!$article->canRead()) {
73-
continue;
74-
}
75-
$like->setIsAccessible();
65+
$like->setIsAccessible();
7666

77-
// short output
78-
$text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.likeableArticle', [
67+
$like->setTitle(WCF::getLanguage()->getDynamicVariable(
68+
'wcf.article.recentActivity.likedArticle',
69+
[
7970
'article' => $article,
80-
'reaction' => $like,
81-
// @deprecated 5.3 Use `$reaction` instead
82-
'like' => $like,
83-
]);
84-
$like->setTitle($text);
85-
86-
// output
87-
$like->setDescription($article->getTeaser());
88-
}
71+
'reactionType' => $like->getReactionType(),
72+
'author' => $like->getUserProfile(),
73+
]
74+
));
75+
$like->setLink($article->getLink());
76+
$like->setDescription(\strip_tags($article->getFormattedTeaser()));
8977
}
9078
}
9179
}

wcfsetup/install/files/lib/data/like/ILikeObjectTypeProvider.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ interface ILikeObjectTypeProvider extends IObjectTypeProvider
2121
/**
2222
* Returns true if the active user can access the given likeable object.
2323
*
24-
* @param ILikeObject $object
2524
* @return bool
2625
*/
2726
public function checkPermissions(ILikeObject $object);

wcfsetup/install/files/lib/data/like/ViewableLike.class.php

Lines changed: 15 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
/**
1313
* Provides methods for viewable likes.
1414
*
15-
* @author Marcel Werk
16-
* @copyright 2001-2019 WoltLab GmbH
17-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @author Marcel Werk
16+
* @copyright 2001-2026 WoltLab GmbH
17+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1818
*
19-
* @method Like getDecoratedObject()
2019
* @mixin Like
2120
* @extends DatabaseObjectDecorator<Like>
2221
*/
@@ -27,29 +26,9 @@ class ViewableLike extends DatabaseObjectDecorator
2726
*/
2827
public static $baseClass = Like::class;
2928

30-
/**
31-
* event text
32-
* @var string
33-
*/
34-
protected $description = '';
35-
36-
/**
37-
* accessible by current user
38-
* @var bool
39-
*/
40-
protected $isAccessible = false;
41-
42-
/**
43-
* event title
44-
* @var string
45-
*/
46-
protected $title = '';
47-
48-
/**
49-
* user profile
50-
* @var UserProfile
51-
*/
52-
protected $userProfile;
29+
protected string $description = '';
30+
protected bool $isAccessible = false;
31+
protected string $title = '';
5332

5433
/**
5534
* description of the object type displayed in the list of likes
@@ -59,101 +38,48 @@ class ViewableLike extends DatabaseObjectDecorator
5938
*/
6039
protected $objectTypeDescription;
6140

62-
/**
63-
* true if event description contains raw html
64-
* @var bool
65-
*/
66-
protected $isRawHtml = false;
67-
6841
/**
6942
* @since 6.3
7043
*/
7144
protected string $link = '';
7245

7346
/**
7447
* Marks this like as accessible for current user.
75-
*
76-
* @return void
7748
*/
78-
public function setIsAccessible()
49+
public function setIsAccessible(): void
7950
{
8051
$this->isAccessible = true;
8152
}
8253

8354
/**
8455
* Returns true if like is accessible by current user.
85-
*
86-
* @return bool
8756
*/
88-
public function isAccessible()
57+
public function isAccessible(): bool
8958
{
9059
return $this->isAccessible;
9160
}
9261

93-
/**
94-
* Sets user profile.
95-
*
96-
* @return void
97-
* @deprecated 3.0
98-
*/
99-
public function setUserProfile(UserProfile $userProfile)
100-
{
101-
$this->userProfile = $userProfile;
102-
}
103-
104-
/**
105-
* Returns user profile.
106-
*
107-
* @return UserProfile
108-
*/
109-
public function getUserProfile()
62+
public function getUserProfile(): ?UserProfile
11063
{
111-
if ($this->userProfile === null) {
112-
$this->userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
113-
}
114-
115-
return $this->userProfile;
64+
return UserProfileRuntimeCache::getInstance()->getObject($this->userID);
11665
}
11766

118-
/**
119-
* Sets like description.
120-
*
121-
* @param string $description
122-
* @return void
123-
*/
124-
public function setDescription($description, bool $isRawHtml = false)
67+
public function setDescription(string $description): void
12568
{
12669
$this->description = $description;
127-
$this->isRawHtml = $isRawHtml;
12870
}
12971

130-
/**
131-
* Returns like description.
132-
*
133-
* @return string
134-
*/
135-
public function getDescription()
72+
public function getDescription(): string
13673
{
13774
return $this->description;
13875
}
13976

140-
/**
141-
* Sets like title.
142-
*
143-
* @param string $title
144-
* @return void
145-
*/
146-
public function setTitle($title)
77+
public function setTitle(string $title): void
14778
{
14879
$this->title = $title;
14980
}
15081

151-
/**
152-
* Returns like title.
153-
*
154-
* @return string
155-
*/
156-
public function getTitle()
82+
public function getTitle(): string
15783
{
15884
return $this->title;
15985
}
@@ -162,6 +88,7 @@ public function getTitle()
16288
* Returns the object type name.
16389
*
16490
* @return string
91+
* @deprecated 6.3 No longer in use.
16592
*/
16693
public function getObjectTypeName()
16794
{
@@ -200,14 +127,6 @@ public function getObjectTypeDescription()
200127
return WCF::getLanguage()->getDynamicVariable('wcf.like.objectType.' . $this->getObjectTypeName());
201128
}
202129

203-
/**
204-
* @since 6.3
205-
*/
206-
public function isRawHtml(): bool
207-
{
208-
return $this->isRawHtml;
209-
}
210-
211130
/**
212131
* @since 6.3
213132
*/

wcfsetup/install/files/lib/data/like/ViewableLikeList.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public function readObjects()
7272
// parse like
7373
foreach ($likeGroups as $likeData) {
7474
if ($likeData['provider'] instanceof IViewableLikeProvider) {
75-
/** @noinspection PhpUndefinedMethodInspection */
7675
$likeData['provider']->prepare($likeData['objects']);
7776
}
7877
}

wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,18 @@ public function prepare(array $likes)
254254
if (isset($users[$comment->objectID]) && !$users[$comment->objectID]->isProtected()) {
255255
$like->setIsAccessible();
256256

257-
// short output
258-
$text = WCF::getLanguage()->getDynamicVariable(
257+
$like->setTitle(WCF::getLanguage()->getDynamicVariable(
259258
'wcf.like.title.com.woltlab.wcf.user.profileComment',
260259
[
261260
'commentAuthor' => $comment->userID ? $users[$comment->userID] : null,
262261
'comment' => $comment,
263262
'user' => $users[$comment->objectID],
264263
'reaction' => $like,
265-
// @deprecated 5.3 Use `$reaction` instead
266-
'like' => $like,
264+
'author' => $like->getUserProfile(),
267265
]
268-
);
269-
$like->setTitle($text);
270-
271-
// output
272-
$like->setDescription($comment->getExcerpt());
266+
));
267+
$like->setLink($comment->getLink());
268+
$like->setDescription(\strip_tags($comment->getExcerpt()));
273269
}
274270
}
275271
} else {
@@ -281,23 +277,18 @@ public function prepare(array $likes)
281277
if (isset($users[$comment->objectID]) && !$users[$comment->objectID]->isProtected()) {
282278
$like->setIsAccessible();
283279

284-
// short output
285-
$text = WCF::getLanguage()->getDynamicVariable(
280+
$like->setTitle(WCF::getLanguage()->getDynamicVariable(
286281
'wcf.like.title.com.woltlab.wcf.user.profileComment.response',
287282
[
288283
'responseAuthor' => $response->userID ? $users[$response->userID] : null,
289284
'commentAuthor' => $comment->userID ? $users[$comment->userID] : null,
290285
'user' => $users[$comment->objectID],
291286
'reaction' => $like,
292-
// @deprecated 5.3 Use `$reaction` instead
293-
'like' => $like,
294-
'response' => $response,
287+
'author' => $like->getUserProfile(),
295288
]
296-
);
297-
$like->setTitle($text);
298-
299-
// output
300-
$like->setDescription($response->getExcerpt());
289+
));
290+
$like->setLink($response->getLink());
291+
$like->setDescription(\strip_tags($response->getExcerpt()));
301292
}
302293
}
303294
}

wcfsetup/install/lang/de.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,10 +4223,9 @@ Erlaubte Dateiendungen: gif, jpg, jpeg, png, webp]]></item>
42234223
<item name="wcf.like.likes.noMoreEntries"><![CDATA[Keine weiteren Reaktionen]]></item>
42244224
<item name="wcf.like.dislikes.more"><![CDATA[Weitere Dislikes]]></item>
42254225
<item name="wcf.like.dislikes.noMoreEntries"><![CDATA[Keine weiteren Dislikes]]></item>
4226-
<item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">von {$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$comment->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
4227-
<item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[Hat mit {@$reaction->render()} auf die Antwort {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">von {$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$response->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
4226+
<item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[<strong>{$author}</strong> hat mit {unsafe:$reaction->render()} auf den Kommentar {if $commentAuthor}von <strong>{$commentAuthor->username}</strong>{else}eines Gasts{/if} an der Pinnwand von <strong>{$user->username}</strong> reagiert.]]></item>
4227+
<item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[<strong>{$author}</strong> hat mit {unsafe:$reaction->render()} auf die Antwort {if $responseAuthor}von <strong>{$responseAuthor->username}</strong>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <strong{$commentAuthor->username}</strong>{else}eines Gasts{/if} an der Pinnwand von <strong>{$user->username}</strong> reagiert.]]></item>
42284228
<item name="wcf.like.objectType.com.woltlab.wcf.likeableArticle"><![CDATA[Artikel]]></item>
4229-
<item name="wcf.like.title.com.woltlab.wcf.likeableArticle"><![CDATA[Hat mit {@$reaction->render()} auf den Artikel <a href="{$article->getLink()}">{$article->getTitle()}</a> reagiert.]]></item>
42304229
<item name="wcf.like.title.com.woltlab.wcf.articleComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$comment->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
42314230
<item name="wcf.like.title.com.woltlab.wcf.articleComment.response"><![CDATA[Hat mit {@$reaction->render()} auf die Antwort {if $responseAuthor}von <a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$response->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
42324231
<item name="wcf.like.title.com.woltlab.wcf.pageComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zu der Seite <a href="{$comment->getLink()}">{$page->getTitle()}</a> reagiert.]]></item>
@@ -5733,5 +5732,6 @@ Erlaubte Dateiendungen: {', '|implode:$allowedFileExtensions}]]></item>
57335732
<item name="wcf.user.profileHits.hitsPerDay"/>
57345733
<item name="wcf.user.avatar.type.none"/>
57355734
<item name="wcf.user.avatar.type.custom"/>
5735+
<item name="wcf.like.title.com.woltlab.wcf.likeableArticle"/>
57365736
</delete>
57375737
</language>

0 commit comments

Comments
 (0)