+ return FALSE;
+});
+
+register_shutdown_function(function () {
+ # display failure page for fatal exceptions
+ $error = error_get_last();
+ if (!($error['type'] & E_FATAL)) return;
+ fail("Fatal: $error[message] in $error[file]:$error[line]");
+});
+
+error_reporting(error_reporting() & ~E_FATAL);
+
+# user login and control
+
+include_once 'auth.inc.php'; // sets global $User
+$Edit = isset($_GET['edit']);
+
+# setup requested page
+
+$Args = '';
+$Page = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
+$Page = urldecode(trim($Page, '/')) ?: 'index';
+
+$staticpage = "$Page.html";
+if (file_exists($staticpage)) {
+ if (is_link($staticpage)) {
+ $target = preg_replace('/\.html$/', '', readlink($staticpage));
+ header("HTTP/1.1 302 Shorthand");
+ header("Location: $target");
+ exit;
+ }
+}
+elseif (file_exists("$Page/index.html")) {
+ $staticpage = "$Page/index.html";
+}
+
+require_once('article.inc.php');
+$Article = new ArchiveArticle($staticpage);
+
+$Page = $Article->handler;
+$Args = $Article->path;
+
+if ($PageAccess = $Article->restricted) {
+ # access restriction
+ if (!$User->login) {
+ http_response_code(303);
+ $target = urlencode($Article->link);
+ header("Location: /login?goto=$target");
+ exit;