diff --git a/core.php b/core.php index d44e60d..2119dbe 100644 --- a/core.php +++ b/core.php @@ -49,9 +49,9 @@ else // and get out of here $env->is_logged_in = false; $env->user = "Anonymous"; - unset($pass); + $env->pass = ""; // Clear the session data - $_SESSION = []; //delete al lthe variables + $_SESSION = []; //delete all the variables session_destroy(); //destroy the session } } diff --git a/modules/action-raw.php b/modules/action-raw.php index 2530b83..b0e84e1 100644 --- a/modules/action-raw.php +++ b/modules/action-raw.php @@ -1,18 +1,18 @@ "Raw page source", - "version" => "0.2", + "version" => "0.3", "author" => "Starbeamrainbowlabs", "description" => "Adds a 'raw' action that shows you the raw source of a page.", "id" => "action-raw", "code" => function() { add_action("raw", function() { - global $page; + global $env; http_response_code(307); - header("x-filename: " . rawurlencode($page) . ".md"); + header("x-filename: " . rawurlencode($env->page) . ".md"); header("content-type: text/markdown"); - exit(file_get_contents("$page.md")); + exit(file_get_contents("$env->page.md")); exit(); }); } diff --git a/modules/page-delete.php b/modules/page-delete.php index d4d2e77..3c84894 100644 --- a/modules/page-delete.php +++ b/modules/page-delete.php @@ -1,36 +1,37 @@ "Page deleter", - "version" => "0.5", + "version" => "0.6", "author" => "Starbeamrainbowlabs", "description" => "Adds an action to allow administrators to delete pages.", "id" => "page-delete", "code" => function() { add_action("delete", function() { - global $pageindex, $settings, $page, $isadmin; + global $pageindex, $settings, $env; if(!$settings->editing) { - exit(page_renderer::render_main("Deleting $page - error", "
You tried to delete $page, but editing is disabled on this wiki.
+ exit(page_renderer::render_main("Deleting $env->page - error", "You tried to delete $env->page, but editing is disabled on this wiki.
If you wish to delete this page, please re-enable editing on this wiki first.
- +Nothing has been changed.
")); } - if(!$isadmin) + if(!$env->is_admin) { - exit(page_renderer::render_main("Deleting $page - error", "You tried to delete $page, but you are not an admin so you don't have permission to do that.
+ exit(page_renderer::render_main("Deleting $env->page - error", "You tried to delete $env->page, but you are not an admin so you don't have permission to do that.
You should try logging in as an admin.
")); } if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes") { - exit(page_renderer::render_main("Deleting $page", "You are about to delete $page. You can't undo this!
- -Click here to go back.")); + exit(page_renderer::render_main("Deleting $env->page", "
You are about to delete $env->page. You can't undo this!
+Click here to delete $env->page.
+Click here to go back.")); } + $page = $env->page unset($pageindex->$page); //delete the page from the page index file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); //save the new page index - unlink("./$page.md"); //delete the page from the disk + unlink("./$env->page.md"); //delete the page from the disk - exit(page_renderer::render_main("Deleting $page - $settings->sitename", "
$page has been deleted. Go back to the main page.
")); + exit(page_renderer::render_main("Deleting $env->page - $settings->sitename", "$env->page has been deleted. Go back to the main page.
")); }); } ]); diff --git a/modules/page-edit.php b/modules/page-edit.php index 79ee5e7..dd22429 100644 --- a/modules/page-edit.php +++ b/modules/page-edit.php @@ -1,7 +1,7 @@ "Page editor", - "version" => "0.8", + "version" => "0.9", "author" => "Starbeamrainbowlabs", "description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "id" => "page-edit", @@ -17,20 +17,21 @@ register_module([ * %edit% */ add_action("edit", function() { - global $pageindex, $settings, $page, $isloggedin; + global $pageindex, $settings, $env; - $filename = "$page.md"; + $filename = "$env->page.md"; $creatingpage = !isset($pageindex->$page); if((isset($_GET["newpage"]) and $_GET["newpage"] == "true") or $creatingpage) { - $title = "Creating $page"; + $title = "Creating $env->page"; } else { - $title = "Editing $page"; + $title = "Editing $env->page"; } $pagetext = ""; + $page = $env->$page; if(isset($pageindex->$page)) { $pagetext = file_get_contents($filename); @@ -41,17 +42,17 @@ register_module([ if(!$creatingpage) { // The page already exists - let the user view the page source - exit(page_renderer::render_main("Viewing source for $page", "$settings->sitename does not allow anonymous users to make edits. You can view the source of $page below, but you can't edit it.
")); + exit(page_renderer::render_main("Viewing source for $env->page", "$settings->sitename does not allow anonymous users to make edits. You can view the source of $env->page below, but you can't edit it.
")); } else { http_response_code(404); - exit(page_renderer::render_main("404 - $page", "The page $page
does not exist, but you do not have permission to create it.
If you haven't already, perhaps you should try logging in.
")); + exit(page_renderer::render_main("404 - $env->page", "The page $env->page
does not exist, but you do not have permission to create it.
If you haven't already, perhaps you should try logging in.
")); } } $content = "Warning: You are not logged in! Your IP address may be recorded.
"; } @@ -71,35 +72,36 @@ register_module([ * %save% */ add_action("save", function() { - global $pageindex, $settings, $page, $isloggedin, $user; + global $pageindex, $settings, $env; if(!$settings->editing) { - header("location: index.php?page=$page"); + header("location: index.php?page=$env->page"); exit(page_renderer::render_main("Error saving edit", "Editing is currently disabled on this wiki.
")); } - if(!$isloggedin and !$settings->anonedits) + if(!$env->is_logged_in and !$settings->anonedits) { http_response_code(403); - header("refresh: 5; url=index.php?page=$page"); + header("refresh: 5; url=index.php?page=$env->page"); exit("You are not logged in, so you are not allowed to save pages on $settings->sitename. Redirecting in 5 seconds...."); } if(!isset($_POST["content"])) { http_response_code(400); - header("refresh: 5; url=index.php?page=$page"); + header("refresh: 5; url=index.php?page=$env->page"); exit("Bad request: No content specified."); } // Make sure that the directory in which the page needs to be saved exists - if(!is_dir(dirname("$page.md"))) + if(!is_dir(dirname("$env->page.md"))) { // Recursively create the directory if needed - mkdir(dirname("$page.md"), null, true); + mkdir(dirname("$env->page.md"), null, true); } - if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) + if(file_put_contents("$env->page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) { + $page = $env->page; // Make sure that this page's parents exist check_subpage_parents($page); @@ -107,12 +109,12 @@ register_module([ if(!isset($pageindex->$page)) { $pageindex->$page = new stdClass(); - $pageindex->$page->filename = "$page.md"; + $pageindex->$page->filename = "$env->page.md"; } $pageindex->$page->size = strlen($_POST["content"]); $pageindex->$page->lastmodified = time(); if($isloggedin) - $pageindex->$page->lasteditor = utf8_encode($user); + $pageindex->$page->lasteditor = utf8_encode($env->user); else $pageindex->$page->lasteditor = utf8_encode("anonymous"); @@ -123,7 +125,7 @@ register_module([ else http_response_code(200); - header("location: index.php?page=$page&edit_status=success"); + header("location: index.php?page=$env->page&edit_status=success"); exit(); } else diff --git a/modules/page-export.php b/modules/page-export.php index ebd61c9..46657a8 100644 --- a/modules/page-export.php +++ b/modules/page-export.php @@ -1,15 +1,15 @@ "Export", - "version" => "0.1", + "version" => "0.2", "author" => "Starbeamrainbowlabs", "description" => "Adds a page that you can use to export your wiki as a .zip file. Uses \$settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.", "id" => "page-export", "code" => function() { add_action("export", function() { - global $settings, $pageindex, $isadmin; + global $settings, $pageindex, $env; - if($settings->export_allow_only_admins && !$isadmin) + if($settings->export_allow_only_admins && !$env->is_admin) { http_response_code(401); exit(page_renderer::render("Export error - $settings->sitename", "Only administrators of $settings->sitename are allowed to export the wiki as a zip. Return to the $settings->defaultpage.")); diff --git a/modules/page-login.php b/modules/page-login.php index 9f9553a..a1631a8 100644 --- a/modules/page-login.php +++ b/modules/page-login.php @@ -1,7 +1,7 @@ "Login", - "version" => "0.5", + "version" => "0.6", "author" => "Starbeamrainbowlabs", "description" => "Adds a pair of actions (login and checklogin) that allow users to login. You need this one if you want your users to be able to login.", "id" => "page-login", @@ -41,7 +41,7 @@ register_module([ * %checklogin% |___/ */ add_action("checklogin", function() { - global $settings; + global $settings, $env; //actually do the login if(isset($_POST["user"]) and isset($_POST["pass"])) @@ -51,7 +51,7 @@ register_module([ $pass = $_POST["pass"]; if($settings->users[$user] == hash("sha256", $pass)) { - $isloggedin = true; + $env->is_logged_in = true; $expiretime = time() + 60*60*24*30; //30 days from now $_SESSION["$settings->sessionprefix-user"] = $user; $_SESSION["$settings->sessionprefix-pass"] = hash("sha256", $pass); diff --git a/modules/page-logout.php b/modules/page-logout.php index 1450ecf..bfda77d 100644 --- a/modules/page-logout.php +++ b/modules/page-logout.php @@ -1,16 +1,16 @@ "Logout", - "version" => "0.5", + "version" => "0.6", "author" => "Starbeamrainbowlabs", "description" => "Adds an action to let users user out. For security reasons it is wise to add this module since logging in automatically opens a session that is valid for 30 days.", "id" => "page-logout", "code" => function() { add_action("logout", function() { - global $user, $pass, $isloggedin; - $isloggedin = false; - unset($user); - unset($pass); + global $env; + $env->is_logged_in = false; + unset($env->user); + unset($env->pass); //clear the session variables $_SESSION = []; session_destroy(); diff --git a/modules/page-move.php b/modules/page-move.php index 3b61eed..26ea3a3 100644 --- a/modules/page-move.php +++ b/modules/page-move.php @@ -1,32 +1,32 @@ "Page mover", - "version" => "0.5", + "version" => "0.6", "author" => "Starbeamrainbowlabs", "description" => "Adds an action to allow administrators to move pages.", "id" => "page-move", "code" => function() { add_action("move", function() { - global $pageindex, $settings, $page, $isadmin; + global $pageindex, $settings, $env; if(!$settings->editing) { - exit(page_renderer::render_main("Moving $page - error", "You tried to move $page, but editing is disabled on this wiki.
+ exit(page_renderer::render_main("Moving $env->page - error", "You tried to move $env->page, but editing is disabled on this wiki.
If you wish to move this page, please re-enable editing on this wiki first.
- +Nothing has been changed.
")); } - if(!$isadmin) + if(!$env->is_admin) { - exit(page_renderer::render_main("Moving $page - Error", "You tried to move $page, but you do not have permission to do that.
+ exit(page_renderer::render_main("Moving $env->page - Error", "You tried to move $env->page, but you do not have permission to do that.
You should try logging in as an admin.
")); } if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0) - exit(page_renderer::render_main("Moving $page", "