--- /dev/null
+<?php
+
+namespace wcf\http\error;
+
+use Laminas\Diactoros\Response\HtmlResponse;
+use Laminas\Diactoros\Response\JsonResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use wcf\http\Helper;
+use wcf\system\box\BoxHandler;
+use wcf\system\notice\NoticeHandler;
+use wcf\system\WCF;
+use wcf\util\HeaderUtil;
+
+/**
+ * Returns an "Offline" response.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+final class OfflineHandler implements RequestHandlerInterface
+{
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ BoxHandler::disablePageLayout();
+ NoticeHandler::disableNotices();
+
+ $preferredType = Helper::getPreferredContentType($request, [
+ 'text/html',
+ 'application/json',
+ ]);
+
+ return HeaderUtil::withNoCacheHeaders(match ($preferredType) {
+ 'application/json' => new JsonResponse(
+ [
+ 'message' => WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'),
+ ],
+ 503,
+ [],
+ \JSON_PRETTY_PRINT
+ ),
+ 'text/html' => new HtmlResponse(
+ HeaderUtil::parseOutputStream(WCF::getTPL()->fetchStream(
+ 'offline',
+ 'wcf',
+ [
+ 'templateName' => 'offline',
+ 'templateNameApplication' => 'wcf',
+ ]
+ )),
+ 503
+ ),
+ });
+ }
+}
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
-use wcf\system\exception\IllegalLinkException;
+use wcf\http\error\NotFoundHandler;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
&& \constant($requestHandler->getActiveRequest()->getClassName() . '::BLACKLISTED_IN_ENTERPRISE_MODE')
&& !WCF::getUser()->hasOwnerAccess()
) {
- throw new IllegalLinkException();
+ return (new NotFoundHandler())->handle($request);
}
return $handler->handle($request);
namespace wcf\http\middleware;
+use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
+use wcf\http\error\HtmlErrorRenderer;
use wcf\system\application\ApplicationHandler;
-use wcf\system\exception\NamedUserException;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
$isWoltLab = true;
}
- throw new NamedUserException(WCF::getLanguage()->getDynamicVariable(
- 'wcf.acp.package.evaluation.expired',
- [
- 'packageName' => $package->getName(),
- 'pluginStoreFileID' => $pluginStoreFileID,
- 'isWoltLab' => $isWoltLab,
- ]
- ));
+ return new HtmlResponse(
+ (new HtmlErrorRenderer())->renderHtmlMessage(
+ WCF::getLanguage()->getDynamicVariable('wcf.global.error.title'),
+ WCF::getLanguage()->getDynamicVariable(
+ 'wcf.acp.package.evaluation.expired',
+ [
+ 'packageName' => $package->getName(),
+ 'pluginStoreFileID' => $pluginStoreFileID,
+ 'isWoltLab' => $isWoltLab,
+ ]
+ ),
+ ),
+ 503
+ );
}
}
namespace wcf\http\middleware;
-use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
-use wcf\http\Helper;
-use wcf\system\box\BoxHandler;
-use wcf\system\exception\AJAXException;
-use wcf\system\notice\NoticeHandler;
+use wcf\http\error\OfflineHandler;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
-use wcf\util\HeaderUtil;
/**
* Checks whether the offline mode is enabled and the request must be intercepted.
return $handler->handle($request);
}
- return HeaderUtil::withNoCacheHeaders($this->getOfflineResponse($request));
- }
-
- private function getOfflineResponse(ServerRequestInterface $request): ResponseInterface
- {
- if (Helper::isAjaxRequest($request)) {
- throw new AJAXException(
- WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'),
- AJAXException::INSUFFICIENT_PERMISSIONS
- );
- } else {
- BoxHandler::disablePageLayout();
- NoticeHandler::disableNotices();
-
- return new HtmlResponse(
- HeaderUtil::parseOutputStream(WCF::getTPL()->fetchStream(
- 'offline',
- 'wcf',
- [
- 'templateName' => 'offline',
- 'templateNameApplication' => 'wcf',
- ]
- )),
- 503
- );
- }
+ return (new OfflineHandler())->handle($request);
}
private function offlineModeEnabled(): bool
namespace wcf\http\middleware;
+use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
-use wcf\system\exception\NamedUserException;
+use wcf\http\error\HtmlErrorRenderer;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
{
if (!RequestHandler::getInstance()->isACPRequest()) {
if (!(80100 <= \PHP_VERSION_ID && \PHP_VERSION_ID <= 80299)) {
- \header('HTTP/1.1 500 Internal Server Error');
-
- throw new NamedUserException(WCF::getLanguage()->get('wcf.global.incompatiblePhpVersion'));
+ return new HtmlResponse(
+ (new HtmlErrorRenderer())->render(
+ WCF::getLanguage()->getDynamicVariable('wcf.global.error.title'),
+ WCF::getLanguage()->get('wcf.global.incompatiblePhpVersion'),
+ ),
+ 500
+ );
}
}
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use wcf\data\user\User;
+use wcf\http\error\ErrorDetail;
+use wcf\http\error\PermissionDeniedHandler;
use wcf\http\Helper;
-use wcf\system\exception\AJAXException;
-use wcf\system\exception\NamedUserException;
use wcf\system\WCF;
/**
$user = WCF::getUser();
if ($this->isBanned($user)) {
- if (Helper::isAjaxRequest($request)) {
- throw new AJAXException(
- WCF::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'),
- AJAXException::INSUFFICIENT_PERMISSIONS
- );
- } else {
+ if (!Helper::isAjaxRequest($request)) {
// Delete sessions only for non-AJAX requests to ensure
// that the user was able to see the message properly
WCF::getSession()->deleteUserSessionsExcept($user);
-
- throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'));
}
+
+ return (new PermissionDeniedHandler())->handle(
+ ErrorDetail::fromMessage(WCF::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'))
+ ->attachToRequest($request)
+ );
}
return $handler->handle($request);
use wcf\data\acp\session\access\log\ACPSessionAccessLogEditor;
use wcf\data\acp\session\log\ACPSessionLog;
use wcf\data\acp\session\log\ACPSessionLogEditor;
+use wcf\http\error\ErrorDetail;
+use wcf\http\error\PermissionDeniedHandler;
use wcf\http\Helper;
-use wcf\system\exception\AJAXException;
use wcf\system\request\LinkHandler;
use wcf\system\request\RequestHandler;
use wcf\system\user\multifactor\TMultifactorRequirementEnforcer;
private function handleGuest(ServerRequestInterface $request): ResponseInterface
{
if (Helper::isAjaxRequest($request)) {
- throw new AJAXException(
- WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.sessionExpired'),
- AJAXException::SESSION_EXPIRED,
- ''
- );
+ return (new PermissionDeniedHandler())->handle($request);
}
return new RedirectResponse(
]);
if (Helper::isAjaxRequest($request)) {
- throw new AJAXException(
- WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'),
- AJAXException::INSUFFICIENT_PERMISSIONS
- );
+ return (new PermissionDeniedHandler())->handle($request);
}
return new HtmlResponse(
private function handleReauthentication(ServerRequestInterface $request): ResponseInterface
{
if (Helper::isAjaxRequest($request)) {
- throw new AJAXException(
- WCF::getLanguage()->getDynamicVariable('wcf.user.reauthentication.explanation'),
- AJAXException::SESSION_EXPIRED
+ return (new PermissionDeniedHandler())->handle(
+ ErrorDetail::fromMessage(WCF::getLanguage()->getDynamicVariable('wcf.user.reauthentication.explanation'))
+ ->attachToRequest($request)
);
}
use wcf\http\Helper;
use wcf\system\valinor\formatter\PrependPath;
use wcf\system\WCF;
-use wcf\util\StringUtil;
/**
* Catches Valinor's MappingErrors and returns a HTTP 400 Bad Request.