From 3cb5ef43bc32c549d4489a913475a04eae2fd57d Mon Sep 17 00:00:00 2001
From: Marcel Werk <burntime@woltlab.com>
Date: Tue, 11 Oct 2016 18:10:34 +0200
Subject: [PATCH] Error pages no longer load special box layouts

Fixes #2115
---
 .../files/lib/system/box/BoxHandler.class.php  | 18 ++++++++++++++++--
 .../exception/NamedUserException.class.php     |  2 ++
 .../PermissionDeniedException.class.php        |  2 ++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php
index d35fab4d2a..09320cebed 100644
--- a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php
+++ b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php
@@ -36,14 +36,21 @@ class BoxHandler extends SingletonFactory {
 	 */
 	protected $boxesByPosition = [];
 	
+	/**
+	 * @var bool
+	 */
+	protected $disablePageLayout = false;
+	
 	/**
 	 * @inheritDoc
 	 */
 	protected function init() {
 		// get active page id
 		$pageID = 0;
-		if (($request = RequestHandler::getInstance()->getActiveRequest()) !== null) {
-			$pageID = $request->getPageID();
+		if (!$this->disablePageLayout) {
+			if (($request = RequestHandler::getInstance()->getActiveRequest()) !== null) {
+				$pageID = $request->getPageID();
+			}
 		}
 		
 		// load box layout for active page
@@ -192,4 +199,11 @@ class BoxHandler extends SingletonFactory {
 			}
 		}
 	}
+	
+	/**
+	 * Disables the loading of the box layout for the active page.
+	 */
+	public function disablePageLayout() {
+		$this->disablePageLayout = true;
+	}
 }
diff --git a/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php b/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php
index 473bac5a4e..258ff7eb6a 100644
--- a/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php
+++ b/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\box\BoxHandler;
 use wcf\system\session\SessionHandler;
 use wcf\system\WCF;
 
@@ -16,6 +17,7 @@ class NamedUserException extends UserException {
 	 * Shows a styled page with the given error message.
 	 */
 	public function show() {
+		BoxHandler::getInstance()->disablePageLayout();
 		SessionHandler::getInstance()->disableTracking();
 		
 		WCF::getTPL()->assign([
diff --git a/wcfsetup/install/files/lib/system/exception/PermissionDeniedException.class.php b/wcfsetup/install/files/lib/system/exception/PermissionDeniedException.class.php
index 555b55ae94..d2fe446972 100644
--- a/wcfsetup/install/files/lib/system/exception/PermissionDeniedException.class.php
+++ b/wcfsetup/install/files/lib/system/exception/PermissionDeniedException.class.php
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\box\BoxHandler;
 use wcf\system\session\SessionHandler;
 use wcf\system\WCF;
 
@@ -24,6 +25,7 @@ class PermissionDeniedException extends UserException {
 	 * Prints a permission denied exception.
 	 */
 	public function show() {
+		BoxHandler::getInstance()->disablePageLayout();
 		SessionHandler::getInstance()->disableTracking();
 		
 		@header('HTTP/1.0 403 Forbidden');
-- 
2.20.1