Use ILinkableObject::getLink() whenever possible in PHP code
authorMatthias Schmidt <gravatronics@live.com>
Tue, 19 May 2020 15:28:28 +0000 (17:28 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 19 May 2020 15:28:28 +0000 (17:28 +0200)
See  #3295

14 files changed:
wcfsetup/install/files/lib/data/attachment/Attachment.class.php
wcfsetup/install/files/lib/data/attachment/AttachmentAction.class.php
wcfsetup/install/files/lib/data/moderation/queue/ModerationQueueAction.class.php
wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/page/ArticlePage.class.php
wcfsetup/install/files/lib/page/UserPage.class.php
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php
wcfsetup/install/files/lib/system/search/acp/PackageACPSearchResultProvider.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserFollowFollowingUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentLikeUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseLikeUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php

index a624f3d27a246601b0e3eb75c8c81eb902554738..0cf22fb7ad602eaabb9a03b1802840567be47bac 100644 (file)
@@ -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);
        }
index ab45a063f3789268ed22cb88dae2698b916896c6..6ac70ce907e2cde2031a81de329c516b5790c338 100644 (file)
@@ -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()
index fa640ab77ef4fa60072daf01f4b0856756cd189d..26baf987b13d010ecc2a7ba64b1c8b38bd7f1611 100644 (file)
@@ -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 = '';
index 9c5d9e0c42753617d782624e00c530466fbf9213..ebfc10b50d2ffd89956bf1d09ee48b57135bda75 100644 (file)
@@ -1,7 +1,11 @@
 <?php
 namespace wcf\data\package;
+use wcf\acp\page\PackagePage;
 use wcf\data\DatabaseObject;
+use wcf\data\ILinkableObject;
 use wcf\system\package\PackageInstallationDispatcher;
+use wcf\system\request\IRouteController;
+use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
 use wcf\util\FileUtil;
 
@@ -27,7 +31,7 @@ use wcf\util\FileUtil;
  * @property-read      string          $author                 author of the package
  * @property-read      string          $authorURL              external url to the website of the package author
  */
-class Package extends DatabaseObject {
+class Package extends DatabaseObject implements ILinkableObject, IRouteController {
        /**
         * recursive list of packages that were given as required packages during installation
         * @var         Package[]
@@ -71,6 +75,22 @@ class Package extends DatabaseObject {
         */
        protected static $requirements = null;
        
+       /**
+        * @inheritDoc
+        */
+       public function getLink() {
+               return LinkHandler::getInstance()->getControllerLink(PackagePage::class, [
+                       'object' => $this,
+               ]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getTitle() {
+               return $this->getName();
+       }
+       
        /**
         * Returns true if this package is required by other packages.
         * 
index 4cf8bec2d91beca2cae8a76e1090f467821c275f..d8dfc6a384a79173e677909466eebb32cca8f635 100644 (file)
@@ -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);
                
index 072232effe430070d70743348a59a5af03ac4974..a2074f57b7dea0c46d6e083ead0f970042947fa5 100644 (file)
@@ -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();
        }
        
        /**
index a60667e634aa45d76c122e6ece703699e8401b31..ebaa30128c611fd29c7158c94335c9bb8821fe70 100644 (file)
@@ -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);
                        }
                }
                
index f0359c64268da2430c4279dc152dcef267b293a0..f39fd1125babe3193029b6e27afa3bf80bc3de62 100644 (file)
@@ -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;
index 9e18b93990135c6f74d318bd11298d02c8b23c78..5fa814159db02c13a44c9942c872fec1e26cf878 100644 (file)
@@ -70,7 +70,7 @@ class UserFollowFollowingUserNotificationEvent extends AbstractUserNotificationE
         * @inheritDoc
         */
        public function getLink() {
-               return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]);
+               return $this->author->getLink();
        }
        
        /**
index 202a765556fded23debae5a0d533115df1019566..e761464c13d23791fab3549c84bf6c787a2cff6e 100644 (file)
@@ -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();
        }
        
        /**
index f737828b4d63eddbccc894cbea848b3e267cae53..a927a1b7264691feee4907bda7ca4a934cff1a3c 100644 (file)
@@ -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();
        }
        
        /**
index 6c77e2ff9aedfc81ed1c1e74a9794c3b2b1a3789..7b1ab0c06c58b815e152298799cc0ed0c1f7aafb 100644 (file)
@@ -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;
        }
        
        /**
index 4da2d378ecf69c57e964f71e37fa1006ef1a8c89..f994687d1331afe6cf18799144fefb16939c20d3 100644 (file)
@@ -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;
        }
        
        /**
index 1e69acb9c7c0727f0619f98d93f6edbd03f8c724..105573c00dab7a028e5ae16de80340d3c28433af 100644 (file)
@@ -69,7 +69,7 @@ class UserRegistrationUserNotificationEvent extends AbstractUserNotificationEven
         * @inheritDoc
         */
        public function getLink() {
-               return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]);
+               return $this->author->getLink();
        }
        
        /**