Passed
Push — master ( a242ec...733515 )
by Roeland
11:31
created
lib/private/legacy/template.php 1 patch
Indentation   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -46,315 +46,315 @@
 block discarded – undo
46 46
  */
47 47
 class OC_Template extends \OC\Template\Base {
48 48
 
49
-	/** @var string */
50
-	private $renderAs; // Create a full page?
51
-
52
-	/** @var string */
53
-	private $path; // The path to the template
54
-
55
-	/** @var array */
56
-	private $headers = array(); //custom headers
57
-
58
-	/** @var string */
59
-	protected $app; // app id
60
-
61
-	protected static $initTemplateEngineFirstRun = true;
62
-
63
-	/**
64
-	 * Constructor
65
-	 *
66
-	 * @param string $app app providing the template
67
-	 * @param string $name of the template file (without suffix)
68
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
69
-	 *                         produce a full page in the according layout. For
70
-	 *                         now, $renderAs can be set to "guest", "user" or
71
-	 *                         "admin".
72
-	 * @param bool $registerCall = true
73
-	 */
74
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
-		// Read the selected theme from the config file
76
-		self::initTemplateEngine($renderAs);
77
-
78
-		$theme = OC_Util::getTheme();
79
-
80
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
-
82
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
-		$l10n = \OC::$server->getL10N($parts[0]);
84
-		/** @var \OCP\Defaults $themeDefaults */
85
-		$themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
-
87
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
88
-
89
-		// Set the private data
90
-		$this->renderAs = $renderAs;
91
-		$this->path = $path;
92
-		$this->app = $app;
93
-
94
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
-	}
96
-
97
-	/**
98
-	 * @param string $renderAs
99
-	 */
100
-	public static function initTemplateEngine($renderAs) {
101
-		if (self::$initTemplateEngineFirstRun){
102
-
103
-			//apps that started before the template initialization can load their own scripts/styles
104
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
-			//meaning the last script/style in this list will be loaded first
106
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
-					OC_Util::addScript ( 'backgroundjobs', null, true );
109
-				}
110
-			}
111
-
112
-			OC_Util::addStyle('css-variables', null, true);
113
-			OC_Util::addStyle('server', null, true);
114
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
115
-			OC_Util::addStyle('jquery.ocdialog');
116
-			OC_Util::addTranslations("core", null, true);
117
-			OC_Util::addStyle('search', 'results');
118
-			OC_Util::addScript('search', 'search', true);
119
-			OC_Util::addScript('search', 'searchprovider');
120
-			OC_Util::addScript('merged-template-prepend', null, true);
121
-			OC_Util::addScript('files/fileinfo');
122
-			OC_Util::addScript('files/client');
123
-			OC_Util::addScript('core', 'dist/main', true);
124
-
125
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
126
-				// shim for the davclient.js library
127
-				\OCP\Util::addScript('files/iedavclient');
128
-			}
129
-
130
-			self::$initTemplateEngineFirstRun = false;
131
-		}
132
-
133
-	}
134
-
135
-
136
-	/**
137
-	 * find the template with the given name
138
-	 * @param string $name of the template file (without suffix)
139
-	 *
140
-	 * Will select the template file for the selected theme.
141
-	 * Checking all the possible locations.
142
-	 * @param string $theme
143
-	 * @param string $app
144
-	 * @return string[]
145
-	 */
146
-	protected function findTemplate($theme, $app, $name) {
147
-		// Check if it is a app template or not.
148
-		if( $app !== '' ) {
149
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
150
-		} else {
151
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
152
-		}
153
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
154
-		$template = $locator->find($name);
155
-		$path = $locator->getPath();
156
-		return array($path, $template);
157
-	}
158
-
159
-	/**
160
-	 * Add a custom element to the header
161
-	 * @param string $tag tag name of the element
162
-	 * @param array $attributes array of attributes for the element
163
-	 * @param string $text the text content for the element. If $text is null then the
164
-	 * element will be written as empty element. So use "" to get a closing tag.
165
-	 */
166
-	public function addHeader($tag, $attributes, $text=null) {
167
-		$this->headers[]= array(
168
-			'tag' => $tag,
169
-			'attributes' => $attributes,
170
-			'text' => $text
171
-		);
172
-	}
173
-
174
-	/**
175
-	 * Process the template
176
-	 * @return boolean|string
177
-	 *
178
-	 * This function process the template. If $this->renderAs is set, it
179
-	 * will produce a full page.
180
-	 */
181
-	public function fetchPage($additionalParams = null) {
182
-		$data = parent::fetchPage($additionalParams);
183
-
184
-		if( $this->renderAs ) {
185
-			$page = new TemplateLayout($this->renderAs, $this->app);
186
-
187
-			if(is_array($additionalParams)) {
188
-				foreach ($additionalParams as $key => $value) {
189
-					$page->assign($key, $value);
190
-				}
191
-			}
192
-
193
-			// Add custom headers
194
-			$headers = '';
195
-			foreach(OC_Util::$headers as $header) {
196
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
197
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
198
-					$headers .= ' defer';
199
-				}
200
-				foreach($header['attributes'] as $name=>$value) {
201
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
202
-				}
203
-				if ($header['text'] !== null) {
204
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
205
-				} else {
206
-					$headers .= '/>';
207
-				}
208
-			}
209
-
210
-			$page->assign('headers', $headers);
211
-
212
-			$page->assign('content', $data);
213
-			return $page->fetchPage($additionalParams);
214
-		}
215
-
216
-		return $data;
217
-	}
218
-
219
-	/**
220
-	 * Include template
221
-	 *
222
-	 * @param string $file
223
-	 * @param array|null $additionalParams
224
-	 * @return string returns content of included template
225
-	 *
226
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
227
-	 * do this.
228
-	 */
229
-	public function inc( $file, $additionalParams = null ) {
230
-		return $this->load($this->path.$file.'.php', $additionalParams);
231
-	}
232
-
233
-	/**
234
-	 * Shortcut to print a simple page for users
235
-	 * @param string $application The application we render the template for
236
-	 * @param string $name Name of the template
237
-	 * @param array $parameters Parameters for the template
238
-	 * @return boolean|null
239
-	 */
240
-	public static function printUserPage( $application, $name, $parameters = array() ) {
241
-		$content = new OC_Template( $application, $name, "user" );
242
-		foreach( $parameters as $key => $value ) {
243
-			$content->assign( $key, $value );
244
-		}
245
-		print $content->printPage();
246
-	}
247
-
248
-	/**
249
-	 * Shortcut to print a simple page for admins
250
-	 * @param string $application The application we render the template for
251
-	 * @param string $name Name of the template
252
-	 * @param array $parameters Parameters for the template
253
-	 * @return bool
254
-	 */
255
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
256
-		$content = new OC_Template( $application, $name, "admin" );
257
-		foreach( $parameters as $key => $value ) {
258
-			$content->assign( $key, $value );
259
-		}
260
-		return $content->printPage();
261
-	}
262
-
263
-	/**
264
-	 * Shortcut to print a simple page for guests
265
-	 * @param string $application The application we render the template for
266
-	 * @param string $name Name of the template
267
-	 * @param array|string $parameters Parameters for the template
268
-	 * @return bool
269
-	 */
270
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
271
-		$content = new OC_Template( $application, $name, "guest" );
272
-		foreach( $parameters as $key => $value ) {
273
-			$content->assign( $key, $value );
274
-		}
275
-		return $content->printPage();
276
-	}
277
-
278
-	/**
279
-	 * Print a fatal error page and terminates the script
280
-	 * @param string $error_msg The error message to show
281
-	 * @param string $hint An optional hint message - needs to be properly escape
282
-	 * @param int $statusCode
283
-	 * @suppress PhanAccessMethodInternal
284
-	 */
285
-	public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
286
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
287
-			\OC_App::loadApp('theming');
288
-		}
289
-
290
-
291
-		if ($error_msg === $hint) {
292
-			// If the hint is the same as the message there is no need to display it twice.
293
-			$hint = '';
294
-		}
295
-
296
-		http_response_code($statusCode);
297
-		try {
298
-			$content = new \OC_Template( '', 'error', 'error', false );
299
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
300
-			$content->assign( 'errors', $errors );
301
-			$content->printPage();
302
-		} catch (\Exception $e) {
303
-			$logger = \OC::$server->getLogger();
304
-			$logger->error("$error_msg $hint", ['app' => 'core']);
305
-			$logger->logException($e, ['app' => 'core']);
306
-
307
-			header('Content-Type: text/plain; charset=utf-8');
308
-			print("$error_msg $hint");
309
-		}
310
-		die();
311
-	}
312
-
313
-	/**
314
-	 * print error page using Exception details
315
-	 * @param Exception|Throwable $exception
316
-	 * @param int $statusCode
317
-	 * @return bool|string
318
-	 * @suppress PhanAccessMethodInternal
319
-	 */
320
-	public static function printExceptionErrorPage($exception, $statusCode = 503) {
321
-		http_response_code($statusCode);
322
-		try {
323
-			$request = \OC::$server->getRequest();
324
-			$content = new \OC_Template('', 'exception', 'error', false);
325
-			$content->assign('errorClass', get_class($exception));
326
-			$content->assign('errorMsg', $exception->getMessage());
327
-			$content->assign('errorCode', $exception->getCode());
328
-			$content->assign('file', $exception->getFile());
329
-			$content->assign('line', $exception->getLine());
330
-			$content->assign('trace', $exception->getTraceAsString());
331
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
332
-			$content->assign('remoteAddr', $request->getRemoteAddress());
333
-			$content->assign('requestID', $request->getId());
334
-			$content->printPage();
335
-		} catch (\Exception $e) {
336
-			try {
337
-				$logger = \OC::$server->getLogger();
338
-				$logger->logException($exception, ['app' => 'core']);
339
-				$logger->logException($e, ['app' => 'core']);
340
-			} catch (Throwable $e) {
341
-				// no way to log it properly - but to avoid a white page of death we send some output
342
-				header('Content-Type: text/plain; charset=utf-8');
343
-				print("Internal Server Error\n\n");
344
-				print("The server encountered an internal error and was unable to complete your request.\n");
345
-				print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
346
-				print("More details can be found in the server log.\n");
347
-
348
-				// and then throw it again to log it at least to the web server error log
349
-				throw $e;
350
-			}
351
-
352
-			header('Content-Type: text/plain; charset=utf-8');
353
-			print("Internal Server Error\n\n");
354
-			print("The server encountered an internal error and was unable to complete your request.\n");
355
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
356
-			print("More details can be found in the server log.\n");
357
-		}
358
-		die();
359
-	}
49
+    /** @var string */
50
+    private $renderAs; // Create a full page?
51
+
52
+    /** @var string */
53
+    private $path; // The path to the template
54
+
55
+    /** @var array */
56
+    private $headers = array(); //custom headers
57
+
58
+    /** @var string */
59
+    protected $app; // app id
60
+
61
+    protected static $initTemplateEngineFirstRun = true;
62
+
63
+    /**
64
+     * Constructor
65
+     *
66
+     * @param string $app app providing the template
67
+     * @param string $name of the template file (without suffix)
68
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
69
+     *                         produce a full page in the according layout. For
70
+     *                         now, $renderAs can be set to "guest", "user" or
71
+     *                         "admin".
72
+     * @param bool $registerCall = true
73
+     */
74
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
+        // Read the selected theme from the config file
76
+        self::initTemplateEngine($renderAs);
77
+
78
+        $theme = OC_Util::getTheme();
79
+
80
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
+
82
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
+        $l10n = \OC::$server->getL10N($parts[0]);
84
+        /** @var \OCP\Defaults $themeDefaults */
85
+        $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
+
87
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
88
+
89
+        // Set the private data
90
+        $this->renderAs = $renderAs;
91
+        $this->path = $path;
92
+        $this->app = $app;
93
+
94
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
+    }
96
+
97
+    /**
98
+     * @param string $renderAs
99
+     */
100
+    public static function initTemplateEngine($renderAs) {
101
+        if (self::$initTemplateEngineFirstRun){
102
+
103
+            //apps that started before the template initialization can load their own scripts/styles
104
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
+            //meaning the last script/style in this list will be loaded first
106
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
109
+                }
110
+            }
111
+
112
+            OC_Util::addStyle('css-variables', null, true);
113
+            OC_Util::addStyle('server', null, true);
114
+            OC_Util::addStyle('jquery-ui-fixes',null,true);
115
+            OC_Util::addStyle('jquery.ocdialog');
116
+            OC_Util::addTranslations("core", null, true);
117
+            OC_Util::addStyle('search', 'results');
118
+            OC_Util::addScript('search', 'search', true);
119
+            OC_Util::addScript('search', 'searchprovider');
120
+            OC_Util::addScript('merged-template-prepend', null, true);
121
+            OC_Util::addScript('files/fileinfo');
122
+            OC_Util::addScript('files/client');
123
+            OC_Util::addScript('core', 'dist/main', true);
124
+
125
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
126
+                // shim for the davclient.js library
127
+                \OCP\Util::addScript('files/iedavclient');
128
+            }
129
+
130
+            self::$initTemplateEngineFirstRun = false;
131
+        }
132
+
133
+    }
134
+
135
+
136
+    /**
137
+     * find the template with the given name
138
+     * @param string $name of the template file (without suffix)
139
+     *
140
+     * Will select the template file for the selected theme.
141
+     * Checking all the possible locations.
142
+     * @param string $theme
143
+     * @param string $app
144
+     * @return string[]
145
+     */
146
+    protected function findTemplate($theme, $app, $name) {
147
+        // Check if it is a app template or not.
148
+        if( $app !== '' ) {
149
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
150
+        } else {
151
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
152
+        }
153
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
154
+        $template = $locator->find($name);
155
+        $path = $locator->getPath();
156
+        return array($path, $template);
157
+    }
158
+
159
+    /**
160
+     * Add a custom element to the header
161
+     * @param string $tag tag name of the element
162
+     * @param array $attributes array of attributes for the element
163
+     * @param string $text the text content for the element. If $text is null then the
164
+     * element will be written as empty element. So use "" to get a closing tag.
165
+     */
166
+    public function addHeader($tag, $attributes, $text=null) {
167
+        $this->headers[]= array(
168
+            'tag' => $tag,
169
+            'attributes' => $attributes,
170
+            'text' => $text
171
+        );
172
+    }
173
+
174
+    /**
175
+     * Process the template
176
+     * @return boolean|string
177
+     *
178
+     * This function process the template. If $this->renderAs is set, it
179
+     * will produce a full page.
180
+     */
181
+    public function fetchPage($additionalParams = null) {
182
+        $data = parent::fetchPage($additionalParams);
183
+
184
+        if( $this->renderAs ) {
185
+            $page = new TemplateLayout($this->renderAs, $this->app);
186
+
187
+            if(is_array($additionalParams)) {
188
+                foreach ($additionalParams as $key => $value) {
189
+                    $page->assign($key, $value);
190
+                }
191
+            }
192
+
193
+            // Add custom headers
194
+            $headers = '';
195
+            foreach(OC_Util::$headers as $header) {
196
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
197
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
198
+                    $headers .= ' defer';
199
+                }
200
+                foreach($header['attributes'] as $name=>$value) {
201
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
202
+                }
203
+                if ($header['text'] !== null) {
204
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
205
+                } else {
206
+                    $headers .= '/>';
207
+                }
208
+            }
209
+
210
+            $page->assign('headers', $headers);
211
+
212
+            $page->assign('content', $data);
213
+            return $page->fetchPage($additionalParams);
214
+        }
215
+
216
+        return $data;
217
+    }
218
+
219
+    /**
220
+     * Include template
221
+     *
222
+     * @param string $file
223
+     * @param array|null $additionalParams
224
+     * @return string returns content of included template
225
+     *
226
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
227
+     * do this.
228
+     */
229
+    public function inc( $file, $additionalParams = null ) {
230
+        return $this->load($this->path.$file.'.php', $additionalParams);
231
+    }
232
+
233
+    /**
234
+     * Shortcut to print a simple page for users
235
+     * @param string $application The application we render the template for
236
+     * @param string $name Name of the template
237
+     * @param array $parameters Parameters for the template
238
+     * @return boolean|null
239
+     */
240
+    public static function printUserPage( $application, $name, $parameters = array() ) {
241
+        $content = new OC_Template( $application, $name, "user" );
242
+        foreach( $parameters as $key => $value ) {
243
+            $content->assign( $key, $value );
244
+        }
245
+        print $content->printPage();
246
+    }
247
+
248
+    /**
249
+     * Shortcut to print a simple page for admins
250
+     * @param string $application The application we render the template for
251
+     * @param string $name Name of the template
252
+     * @param array $parameters Parameters for the template
253
+     * @return bool
254
+     */
255
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
256
+        $content = new OC_Template( $application, $name, "admin" );
257
+        foreach( $parameters as $key => $value ) {
258
+            $content->assign( $key, $value );
259
+        }
260
+        return $content->printPage();
261
+    }
262
+
263
+    /**
264
+     * Shortcut to print a simple page for guests
265
+     * @param string $application The application we render the template for
266
+     * @param string $name Name of the template
267
+     * @param array|string $parameters Parameters for the template
268
+     * @return bool
269
+     */
270
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
271
+        $content = new OC_Template( $application, $name, "guest" );
272
+        foreach( $parameters as $key => $value ) {
273
+            $content->assign( $key, $value );
274
+        }
275
+        return $content->printPage();
276
+    }
277
+
278
+    /**
279
+     * Print a fatal error page and terminates the script
280
+     * @param string $error_msg The error message to show
281
+     * @param string $hint An optional hint message - needs to be properly escape
282
+     * @param int $statusCode
283
+     * @suppress PhanAccessMethodInternal
284
+     */
285
+    public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
286
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
287
+            \OC_App::loadApp('theming');
288
+        }
289
+
290
+
291
+        if ($error_msg === $hint) {
292
+            // If the hint is the same as the message there is no need to display it twice.
293
+            $hint = '';
294
+        }
295
+
296
+        http_response_code($statusCode);
297
+        try {
298
+            $content = new \OC_Template( '', 'error', 'error', false );
299
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
300
+            $content->assign( 'errors', $errors );
301
+            $content->printPage();
302
+        } catch (\Exception $e) {
303
+            $logger = \OC::$server->getLogger();
304
+            $logger->error("$error_msg $hint", ['app' => 'core']);
305
+            $logger->logException($e, ['app' => 'core']);
306
+
307
+            header('Content-Type: text/plain; charset=utf-8');
308
+            print("$error_msg $hint");
309
+        }
310
+        die();
311
+    }
312
+
313
+    /**
314
+     * print error page using Exception details
315
+     * @param Exception|Throwable $exception
316
+     * @param int $statusCode
317
+     * @return bool|string
318
+     * @suppress PhanAccessMethodInternal
319
+     */
320
+    public static function printExceptionErrorPage($exception, $statusCode = 503) {
321
+        http_response_code($statusCode);
322
+        try {
323
+            $request = \OC::$server->getRequest();
324
+            $content = new \OC_Template('', 'exception', 'error', false);
325
+            $content->assign('errorClass', get_class($exception));
326
+            $content->assign('errorMsg', $exception->getMessage());
327
+            $content->assign('errorCode', $exception->getCode());
328
+            $content->assign('file', $exception->getFile());
329
+            $content->assign('line', $exception->getLine());
330
+            $content->assign('trace', $exception->getTraceAsString());
331
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
332
+            $content->assign('remoteAddr', $request->getRemoteAddress());
333
+            $content->assign('requestID', $request->getId());
334
+            $content->printPage();
335
+        } catch (\Exception $e) {
336
+            try {
337
+                $logger = \OC::$server->getLogger();
338
+                $logger->logException($exception, ['app' => 'core']);
339
+                $logger->logException($e, ['app' => 'core']);
340
+            } catch (Throwable $e) {
341
+                // no way to log it properly - but to avoid a white page of death we send some output
342
+                header('Content-Type: text/plain; charset=utf-8');
343
+                print("Internal Server Error\n\n");
344
+                print("The server encountered an internal error and was unable to complete your request.\n");
345
+                print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
346
+                print("More details can be found in the server log.\n");
347
+
348
+                // and then throw it again to log it at least to the web server error log
349
+                throw $e;
350
+            }
351
+
352
+            header('Content-Type: text/plain; charset=utf-8');
353
+            print("Internal Server Error\n\n");
354
+            print("The server encountered an internal error and was unable to complete your request.\n");
355
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
356
+            print("More details can be found in the server log.\n");
357
+        }
358
+        die();
359
+    }
360 360
 }
Please login to merge, or discard this patch.