$attachment = $this->getAttachment($attachmentID);
if ($attachment === null) {
- return new ContentNotVisibleView();
+ return ContentNotVisibleView::forNotAvailable();
}
$outputType = $parser->getOutputType();
} elseif (\substr($attachment->fileType, 0, 6) === 'audio/' && $outputType == 'text/html') {
return $this->showAudioPlayer($attachment);
} elseif (!$attachment->canDownload()) {
- return new ContentNotVisibleView(
- WCF::getLanguage()->getDynamicVariable('wcf.message.content.no.permission.title')
- );
+ return ContentNotVisibleView::forNoPermission();
}
return StringUtil::getAnchorTag($attachment->getLink(), $attachment->filename);
$article = $this->getArticle($articleID);
if ($article === null) {
- return new ContentNotVisibleView();
+ return ContentNotVisibleView::forNotAvailable();
}
if (!$article->canRead()) {
- return new ContentNotVisibleView(
- WCF::getLanguage()->getDynamicVariable('wcf.message.content.no.permission.title')
- );
+ return ContentNotVisibleView::forNoPermission();
} elseif ($parser->getOutputType() == 'text/html') {
return WCF::getTPL()->fetch('shared_bbcode_wsa', 'wcf', [
'article' => $article,
/** @var ViewableMedia $media */
$media = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.media', $mediaID);
if ($media === null) {
- return new ContentNotVisibleView();
+ return ContentNotVisibleView::forNotAvailable();
}
if ($media->isAccessible()) {
return StringUtil::encodeHTML($media->getLink());
} else {
- return new ContentNotVisibleView(
- WCF::getLanguage()->getDynamicVariable('wcf.message.content.no.permission.title')
- );
+ return ContentNotVisibleView::forNoPermission();
}
}
}
return StringUtil::getAnchorTag($page->getLink(), $title ?: $page->getTitle());
}
- return new ContentNotVisibleView();
+ return ContentNotVisibleView::forNotAvailable();
}
}
*/
final class ContentNotVisibleView
{
- private readonly string $message;
-
public function __construct(
- string $message = '',
+ private readonly string $message,
) {
- if (!$message) {
- $message = WCF::getLanguage()->get('wcf.message.content.not.available.title');
- }
-
- $this->message = $message;
}
public function __toString(): string
'message' => $this->message,
], true);
}
+
+ public static function forNotAvailable(): self
+ {
+ return new self(WCF::getLanguage()->getDynamicVariable('wcf.message.content.not.available.title'));
+ }
+
+ public static function forNoPermission(): self
+ {
+ return new self(WCF::getLanguage()->getDynamicVariable('wcf.message.content.no.permission.title'));
+ }
}