From b57803924d1a0d572904b4d59669a278608e81c4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 19 May 2020 17:28:28 +0200 Subject: [PATCH] Use ILinkableObject::getLink() whenever possible in PHP code See #3295 --- .../lib/data/attachment/Attachment.class.php | 3 +++ .../attachment/AttachmentAction.class.php | 7 +++--- .../queue/ModerationQueueAction.class.php | 2 +- .../files/lib/data/package/Package.class.php | 22 ++++++++++++++++++- .../files/lib/page/ArticlePage.class.php | 3 +-- .../install/files/lib/page/UserPage.class.php | 2 +- .../system/bbcode/AttachmentBBCode.class.php | 6 ++--- .../PackageACPSearchResultProvider.class.php | 6 +---- ...owFollowingUserNotificationEvent.class.php | 2 +- ...CommentLikeUserNotificationEvent.class.php | 3 +-- ...esponseLikeUserNotificationEvent.class.php | 7 +----- ...sponseOwnerUserNotificationEvent.class.php | 8 ++----- ...fileCommentUserNotificationEvent.class.php | 8 ++----- ...egistrationUserNotificationEvent.class.php | 2 +- 14 files changed, 41 insertions(+), 40 deletions(-) diff --git a/wcfsetup/install/files/lib/data/attachment/Attachment.class.php b/wcfsetup/install/files/lib/data/attachment/Attachment.class.php index a624f3d27a..0cf22fb7ad 100644 --- a/wcfsetup/install/files/lib/data/attachment/Attachment.class.php +++ b/wcfsetup/install/files/lib/data/attachment/Attachment.class.php @@ -209,6 +209,9 @@ class Attachment extends DatabaseObject implements ILinkableObject, IRouteContro if ($size == 'tiny') { $parameters['tiny'] = 1; } + else if ($size == 'thumbnail') { + $parameters['thumbnail'] = 1; + } return LinkHandler::getInstance()->getLink('Attachment', $parameters); } diff --git a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php index ab45a063f3..6ac70ce907 100644 --- a/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php +++ b/wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php @@ -9,7 +9,6 @@ use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\event\EventHandler; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; -use wcf\system\request\LinkHandler; use wcf\system\upload\DefaultUploadFileSaveStrategy; use wcf\system\upload\DefaultUploadFileValidationStrategy; use wcf\system\upload\UploadFile; @@ -172,9 +171,9 @@ class AttachmentAction extends AbstractDatabaseObjectAction implements ISortable 'formattedFilesize' => FileUtil::formatFilesize($attachment->filesize), 'isImage' => $attachment->isImage, 'attachmentID' => $attachment->attachmentID, - 'tinyURL' => $attachment->tinyThumbnailType ? LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment], 'tiny=1') : '', - 'thumbnailURL' => $attachment->thumbnailType ? LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment], 'thumbnail=1') : '', - 'url' => LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment]), + 'tinyURL' => $attachment->tinyThumbnailType ? $attachment->getThumbnailLink('tiny') : '', + 'thumbnailURL' => $attachment->thumbnailType ? $attachment->getThumbnailLink('thumbnail') : '', + 'url' => $attachment->getLink(), 'height' => $attachment->height, 'width' => $attachment->width, 'iconName' => $attachment->getIconName() diff --git a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php index fa640ab77e..26baf987b1 100644 --- a/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php +++ b/wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php @@ -263,7 +263,7 @@ class ModerationQueueAction extends AbstractDatabaseObjectAction { $username = $this->user->userID ? $this->user->username : WCF::getLanguage()->get('wcf.moderation.assignedUser.nobody'); $link = ''; if ($this->user->userID) { - $link = LinkHandler::getInstance()->getLink('User', ['object' => $this->user]); + $link = $this->user->getLink(); } $newStatus = ''; diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 9c5d9e0c42..ebfc10b50d 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -1,7 +1,11 @@ getControllerLink(PackagePage::class, [ + 'object' => $this, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle() { + return $this->getName(); + } + /** * Returns true if this package is required by other packages. * diff --git a/wcfsetup/install/files/lib/page/ArticlePage.class.php b/wcfsetup/install/files/lib/page/ArticlePage.class.php index 4cf8bec2d9..d8dfc6a384 100644 --- a/wcfsetup/install/files/lib/page/ArticlePage.class.php +++ b/wcfsetup/install/files/lib/page/ArticlePage.class.php @@ -7,7 +7,6 @@ use wcf\data\like\object\LikeObject; use wcf\system\comment\manager\ICommentManager; use wcf\system\comment\CommentHandler; use wcf\system\reaction\ReactionHandler; -use wcf\system\request\LinkHandler; use wcf\system\MetaTagHandler; use wcf\system\WCF; use wcf\util\StringUtil; @@ -105,7 +104,7 @@ class ArticlePage extends AbstractArticlePage { // add meta/og tags MetaTagHandler::getInstance()->addTag('og:title', 'og:title', $this->articleContent->getTitle() . ' - ' . WCF::getLanguage()->get(PAGE_TITLE), true); - MetaTagHandler::getInstance()->addTag('og:url', 'og:url', LinkHandler::getInstance()->getLink('Article', ['object' => $this->articleContent]), true); + MetaTagHandler::getInstance()->addTag('og:url', 'og:url', $this->articleContent->getLink(), true); MetaTagHandler::getInstance()->addTag('og:type', 'og:type', 'article', true); MetaTagHandler::getInstance()->addTag('og:description', 'og:description', ($this->articleContent->teaser ?: StringUtil::decodeHTML(StringUtil::stripHTML($this->articleContent->getFormattedTeaser()))), true); diff --git a/wcfsetup/install/files/lib/page/UserPage.class.php b/wcfsetup/install/files/lib/page/UserPage.class.php index 072232effe..a2074f57b7 100644 --- a/wcfsetup/install/files/lib/page/UserPage.class.php +++ b/wcfsetup/install/files/lib/page/UserPage.class.php @@ -94,7 +94,7 @@ class UserPage extends AbstractPage { if (isset($_REQUEST['editOnInit'])) $this->editOnInit = true; - $this->canonicalURL = LinkHandler::getInstance()->getLink('User', ['object' => $this->user]); + $this->canonicalURL = $this->user->getLink(); } /** diff --git a/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php index a60667e634..ebaa30128c 100644 --- a/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php @@ -107,7 +107,7 @@ class AttachmentBBCode extends AbstractBBCode { $class = 'messageFloatObject'.ucfirst($alignment); } - $source = StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment])); + $source = StringUtil::encodeHTML($attachment->getLink()); $title = StringUtil::encodeHTML($attachment->filename); if ($parser instanceof HtmlBBCodeParser && $parser->getIsGoogleAmp()) { @@ -165,9 +165,7 @@ class AttachmentBBCode extends AbstractBBCode { } else { // file - return StringUtil::getAnchorTag(LinkHandler::getInstance()->getLink('Attachment', [ - 'object' => $attachment - ]), $attachment->filename); + return StringUtil::getAnchorTag($attachment->getLink(), $attachment->filename); } } diff --git a/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php b/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php index f0359c6426..f39fd1125b 100644 --- a/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php @@ -2,7 +2,6 @@ namespace wcf\system\search\acp; use wcf\data\package\Package; use wcf\system\database\util\PreparedStatementConditionBuilder; -use wcf\system\request\LinkHandler; use wcf\system\WCF; /** @@ -59,10 +58,7 @@ class PackageACPSearchResultProvider implements IACPSearchResultProvider { /** @var Package $package */ while ($package = $statement->fetchObject(Package::class)) { - $results[] = new ACPSearchResult($package->getName(), LinkHandler::getInstance()->getLink('Package', [ - 'id' => $package->packageID, - 'title' => $package->getName() - ])); + $results[] = new ACPSearchResult($package->getName(), $package->getLink()); } return $results; diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserFollowFollowingUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserFollowFollowingUserNotificationEvent.class.php index 9e18b93990..5fa814159d 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserFollowFollowingUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserFollowFollowingUserNotificationEvent.class.php @@ -70,7 +70,7 @@ class UserFollowFollowingUserNotificationEvent extends AbstractUserNotificationE * @inheritDoc */ public function getLink() { - return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]); + return $this->author->getLink(); } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentLikeUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentLikeUserNotificationEvent.class.php index 202a765556..e761464c13 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentLikeUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentLikeUserNotificationEvent.class.php @@ -3,7 +3,6 @@ namespace wcf\system\user\notification\event; use wcf\data\user\UserProfile; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\comment\CommentHandler; -use wcf\system\request\LinkHandler; use wcf\system\user\notification\object\LikeUserNotificationObject; use wcf\system\WCF; @@ -96,7 +95,7 @@ class UserProfileCommentLikeUserNotificationEvent extends AbstractSharedUserNoti $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']); } - return LinkHandler::getInstance()->getLink('User', ['object' => $owner], '#wall/comment' . $this->getCommentID()); + return $owner->getLink() . '#wall/comment' . $this->getCommentID(); } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseLikeUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseLikeUserNotificationEvent.class.php index f737828b4d..a927a1b726 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseLikeUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseLikeUserNotificationEvent.class.php @@ -3,7 +3,6 @@ namespace wcf\system\user\notification\event; use wcf\data\user\UserProfile; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\comment\CommentHandler; -use wcf\system\request\LinkHandler; use wcf\system\user\notification\object\LikeUserNotificationObject; use wcf\system\WCF; @@ -103,11 +102,7 @@ class UserProfileCommentResponseLikeUserNotificationEvent extends AbstractShared $owner = UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID']); } - return LinkHandler::getInstance()->getLink( - 'User', - ['object' => $owner], - '#wall/comment' . $this->additionalData['commentID'] . '/response' . $this->getResponseID() - ); + return $owner->getLink() . '#wall/comment' . $this->additionalData['commentID'] . '/response' . $this->getResponseID(); } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php index 6c77e2ff9a..7b1ab0c06c 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php @@ -5,7 +5,6 @@ use wcf\system\cache\runtime\CommentRuntimeCache; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\comment\CommentHandler; use wcf\system\email\Email; -use wcf\system\request\LinkHandler; use wcf\system\user\notification\object\CommentResponseUserNotificationObject; /** @@ -123,11 +122,8 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare * @inheritDoc */ public function getLink() { - return LinkHandler::getInstance()->getLink( - 'User', - ['object' => UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])], - '#wall/comment' . $this->getUserNotificationObject()->commentID - ); + return UserProfileRuntimeCache::getInstance()->getObject($this->additionalData['objectID'])->getLink() . + '#wall/comment' . $this->getUserNotificationObject()->commentID; } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php index 4da2d378ec..f994687d13 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php @@ -3,7 +3,6 @@ namespace wcf\system\user\notification\event; use wcf\data\user\UserProfile; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\comment\CommentHandler; -use wcf\system\request\LinkHandler; use wcf\system\user\notification\object\CommentUserNotificationObject; /** @@ -93,11 +92,8 @@ class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotifica * @inheritDoc */ public function getLink() { - return LinkHandler::getInstance()->getLink( - 'User', - ['object' => UserProfileRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)], - '#wall/comment' . $this->getUserNotificationObject()->commentID - ); + return UserProfileRuntimeCache::getInstance()->getObject($this->getUserNotificationObject()->objectID)->getLink() . + '#wall/comment' . $this->getUserNotificationObject()->commentID; } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php index 1e69acb9c7..105573c00d 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php @@ -69,7 +69,7 @@ class UserRegistrationUserNotificationEvent extends AbstractUserNotificationEven * @inheritDoc */ public function getLink() { - return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]); + return $this->author->getLink(); } /** -- 2.20.1