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;
* @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
return $this->getPath() . $filename;
}
+ #[\Override]
public function getLink(): string
{
return LinkHandler::getInstance()->getControllerLink(
FileDownloadAction::class,
- ['id' => $this->fileID]
+ [
+ 'id' => $this->fileID,
+ 'forceFrontend' => true,
+ ]
);
}
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;
* @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
{
{
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;
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;
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,