Deprecate and redirect the attachment page
authorAlexander Ebert <ebert@woltlab.com>
Wed, 31 Jul 2024 14:59:44 +0000 (16:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 31 Jul 2024 14:59:44 +0000 (16:59 +0200)
wcfsetup/install/files/lib/data/file/File.class.php
wcfsetup/install/files/lib/page/AttachmentPage.class.php
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php

index 4edc1fc757fb8f33e3dff8c8dab8b1b1c3029a65..87bbf0cc56a90c1535227171935e4cf33a7162ec 100644 (file)
@@ -5,6 +5,7 @@ namespace wcf\data\file;
 use wcf\action\FileDownloadAction;
 use wcf\data\DatabaseObject;
 use wcf\data\file\thumbnail\FileThumbnail;
+use wcf\data\ILinkableObject;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\file\processor\FileProcessor;
 use wcf\system\file\processor\IFileProcessor;
@@ -29,7 +30,7 @@ use wcf\util\StringUtil;
  * @property-read int|null $height
  * @property-read string|null $fileHashWebp
  */
-class File extends DatabaseObject
+class File extends DatabaseObject implements ILinkableObject
 {
     /**
      * List of common file extensions that are always safe to be served directly
@@ -126,11 +127,15 @@ class File extends DatabaseObject
         return $this->getPath() . $filename;
     }
 
+    #[\Override]
     public function getLink(): string
     {
         return LinkHandler::getInstance()->getControllerLink(
             FileDownloadAction::class,
-            ['id' => $this->fileID]
+            [
+                'id' => $this->fileID,
+                'forceFrontend' => true,
+            ]
         );
     }
 
index 27c2639f07e50575058b12c91a50614d38b00b1a..44a28f1e524ef391151c744b012f7496115ca74b 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\page;
 
 use Laminas\Diactoros\Response\EmptyResponse;
+use Laminas\Diactoros\Response\RedirectResponse;
 use wcf\data\attachment\Attachment;
 use wcf\data\attachment\AttachmentEditor;
 use wcf\system\exception\IllegalLinkException;
@@ -17,6 +18,7 @@ use wcf\util\FileReader;
  * @author  Joshua Ruesweg, Marcel Werk
  * @copyright   2001-2019 WoltLab GmbH
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @deprecated 6.1 Attachments are now served through the unified upload system
  */
 class AttachmentPage extends AbstractPage
 {
@@ -138,6 +140,20 @@ class AttachmentPage extends AbstractPage
     {
         parent::readData();
 
+        // The redirect is placed here instead of inside the `readParameters()`
+        // method in order to take advantage of the previous access validation.
+        if ($this->attachment->getFile() !== null) {
+            if ($this->tiny) {
+                $url = $this->attachment->getThumbnailLink('tiny');
+            } elseif ($this->thumbnail) {
+                $url = $this->attachment->getThumbnailLink();
+            } else {
+                $url = $this->attachment->getLink();
+            }
+
+            return new RedirectResponse($url);
+        }
+
         // get file data
         if ($this->tiny) {
             $mimeType = $this->attachment->tinyThumbnailType;
index 624177592d125feab22be899a009865c83d70da4..39b4d2850b9351c889c6a9a3537607c2f42e5969 100644 (file)
@@ -4,7 +4,6 @@ namespace wcf\system\bbcode;
 
 use wcf\data\attachment\Attachment;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
-use wcf\system\request\LinkHandler;
 use wcf\system\style\FontAwesomeIcon;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
@@ -162,7 +161,7 @@ final class AttachmentBBCode extends AbstractBBCode
         if (!$hasParentLink && $attachment->hasThumbnail() && $attachment->canDownload()) {
             $result = \sprintf(
                 '<a href="%s" title="%s" class="embeddedAttachmentLink jsImageViewer %s" style="width: %s">%s%s</a>',
-                StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment])),
+                StringUtil::encodeHTML($attachment->getLink()),
                 StringUtil::encodeHTML($attachment->filename),
                 $class,
                 $width,