mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Convert all existing modules over to new $env
This commit is contained in:
parent
2cfea69ecb
commit
4cabf42666
11 changed files with 77 additions and 73 deletions
4
core.php
4
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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", "<p>You tried to delete $page, but editing is disabled on this wiki.</p>
|
||||
exit(page_renderer::render_main("Deleting $env->page - error", "<p>You tried to delete $env->page, but editing is disabled on this wiki.</p>
|
||||
<p>If you wish to delete this page, please re-enable editing on this wiki first.</p>
|
||||
<p><a href='index.php?page=$page'>Go back to $page</a>.</p>
|
||||
<p><a href='index.php?page=$env->page'>Go back to $env->page</a>.</p>
|
||||
<p>Nothing has been changed.</p>"));
|
||||
}
|
||||
if(!$isadmin)
|
||||
if(!$env->is_admin)
|
||||
{
|
||||
exit(page_renderer::render_main("Deleting $page - error", "<p>You tried to delete $page, but you are not an admin so you don't have permission to do that.</p>
|
||||
exit(page_renderer::render_main("Deleting $env->page - error", "<p>You tried to delete $env->page, but you are not an admin so you don't have permission to do that.</p>
|
||||
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
|
||||
}
|
||||
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
|
||||
{
|
||||
exit(page_renderer::render_main("Deleting $page", "<p>You are about to <strong>delete</strong> $page. You can't undo this!</p>
|
||||
<p><a href='index.php?action=delete&page=$page&delete=yes'>Click here to delete $page.</a></p>
|
||||
<p><a href='index.php?action=view&page=$page'>Click here to go back.</a>"));
|
||||
exit(page_renderer::render_main("Deleting $env->page", "<p>You are about to <strong>delete</strong> $env->page. You can't undo this!</p>
|
||||
<p><a href='index.php?action=delete&page=$env->page&delete=yes'>Click here to delete $env->page.</a></p>
|
||||
<p><a href='index.php?action=view&page=$env->page'>Click here to go back.</a>"));
|
||||
}
|
||||
$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", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
|
||||
exit(page_renderer::render_main("Deleting $env->page - $settings->sitename", "<p>$env->page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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", "<p>$settings->sitename does not allow anonymous users to make edits. You can view the source of $page below, but you can't edit it.</p><textarea name='content' readonly>$pagetext</textarea>"));
|
||||
exit(page_renderer::render_main("Viewing source for $env->page", "<p>$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.</p><textarea name='content' readonly>$pagetext</textarea>"));
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(404);
|
||||
exit(page_renderer::render_main("404 - $page", "<p>The page <code>$page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login'>logging in</a>.</p>"));
|
||||
exit(page_renderer::render_main("404 - $env->page", "<p>The page <code>$env->page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login'>logging in</a>.</p>"));
|
||||
}
|
||||
}
|
||||
|
||||
$content = "<h1>$title</h1>";
|
||||
if(!$isloggedin and $settings->anonedits)
|
||||
if(!$env->is_logged_in and $settings->anonedits)
|
||||
{
|
||||
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||
}
|
||||
|
@ -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", "<p>Editing is currently disabled on this wiki.</p>"));
|
||||
}
|
||||
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
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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. <a href='?action=$settings->defaultaction&page='>Return to the $settings->defaultpage</a>."));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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);
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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();
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "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", "<p>You tried to move $page, but editing is disabled on this wiki.</p>
|
||||
exit(page_renderer::render_main("Moving $env->page - error", "<p>You tried to move $env->page, but editing is disabled on this wiki.</p>
|
||||
<p>If you wish to move this page, please re-enable editing on this wiki first.</p>
|
||||
<p><a href='index.php?page=$page'>Go back to $page</a>.</p>
|
||||
<p><a href='index.php?page=$env->page'>Go back to $env->page</a>.</p>
|
||||
<p>Nothing has been changed.</p>"));
|
||||
}
|
||||
if(!$isadmin)
|
||||
if(!$env->is_admin)
|
||||
{
|
||||
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page, but you do not have permission to do that.</p>
|
||||
exit(page_renderer::render_main("Moving $env->page - Error", "<p>You tried to move $env->page, but you do not have permission to do that.</p>
|
||||
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
|
||||
}
|
||||
|
||||
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
|
||||
exit(page_renderer::render_main("Moving $page", "<h2>Moving $page</h2>
|
||||
exit(page_renderer::render_main("Moving $env->page", "<h2>Moving $env->page</h2>
|
||||
<form method='get' action='index.php'>
|
||||
<input type='hidden' name='action' value='move' />
|
||||
<label for='old_name'>Old Name:</label>
|
||||
<input type='text' name='page' value='$page' readonly />
|
||||
<input type='text' name='page' value='$env->page' readonly />
|
||||
<br />
|
||||
<label for='new_name'>New Name:</label>
|
||||
<input type='text' name='new_name' />
|
||||
|
@ -36,12 +36,13 @@ register_module([
|
|||
|
||||
$new_name = makepathsafe($_GET["new_name"]);
|
||||
|
||||
$page = $env->page;
|
||||
if(!isset($pageindex->$page))
|
||||
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page to $new_name, but the page with the name $page does not exist in the first place.</p>
|
||||
exit(page_renderer::render_main("Moving $env->page - Error", "<p>You tried to move $env->page to $new_name, but the page with the name $env->page does not exist in the first place.</p>
|
||||
<p>Nothing has been changed.</p>"));
|
||||
|
||||
if($page == $new_name)
|
||||
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
|
||||
if($env->page == $new_name)
|
||||
exit(page_renderer::render_main("Moving $env->page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
|
||||
<p>It is possible that you tried to use some characters in the new name that are not allowed and were removed.</p>
|
||||
<p>Page names may only contain alphanumeric characters, dashes, and underscores.</p>"));
|
||||
|
||||
|
@ -55,10 +56,11 @@ register_module([
|
|||
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||
|
||||
//move the page on the disk
|
||||
rename("$page.md", "$new_name.md");
|
||||
rename("$env->page.md", "$new_name.md");
|
||||
|
||||
exit(page_renderer::render_main("Moving $page", "<p><a href='index.php?page=$page'>$page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
|
||||
exit(page_renderer::render_main("Moving $env->page", "<p><a href='index.php?page=$env->page'>$env->page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "Update",
|
||||
"version" => "0.6",
|
||||
"version" => "0.6.1",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Adds an update page that downloads the latest stable version of Pepperminty Wiki. This module is currently outdated as it doesn't save your module preferences.",
|
||||
"id" => "page-update",
|
||||
"code" => function() {
|
||||
add_action("update", function() {
|
||||
global $settings, $isadmin;
|
||||
global $settings, $env;
|
||||
|
||||
if(!$isadmin)
|
||||
if(!$env->is_admin)
|
||||
{
|
||||
http_response_code(401);
|
||||
exit(page_renderer::render_main("Update - Error", "<p>You must be an administrator to do that.</p>"));
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "Page viewer",
|
||||
"version" => "0.8",
|
||||
"version" => "0.9",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Allows you to view pages. You should include this one.",
|
||||
"id" => "page-view",
|
||||
"code" => function() {
|
||||
add_action("view", function() {
|
||||
global $pageindex, $settings, $page, $parse_page_source;
|
||||
global $pageindex, $settings, $env, $parse_page_source;
|
||||
|
||||
// Check to make sure that the page exists
|
||||
$page = $env->page;
|
||||
if(!isset($pageindex->$page))
|
||||
{
|
||||
// todo make this intelligent so we only redirect if the user is acutally able to create the page
|
||||
|
@ -17,26 +18,26 @@ register_module([
|
|||
{
|
||||
// Editing is enabled, redirect to the editing page
|
||||
http_response_code(307); // Temporary redirect
|
||||
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($page));
|
||||
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($env->page));
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Editing is disabled, show an error message
|
||||
http_response_code(404);
|
||||
exit(page_renderer::render_main("$page - 404 - $settings->sitename", "<p>$page does not exist.</p><p>Since editing is currently disabled on this wiki, you may not create this page. If you feel that this page should exist, try contacting this wiki's Administrator.</p>"));
|
||||
exit(page_renderer::render_main("$env->page - 404 - $settings->sitename", "<p>$env->page does not exist.</p><p>Since editing is currently disabled on this wiki, you may not create this page. If you feel that this page should exist, try contacting this wiki's Administrator.</p>"));
|
||||
}
|
||||
}
|
||||
$title = "$page - $settings->sitename";
|
||||
$content = "<h1>$page</h1>";
|
||||
$title = "$env->page - $settings->sitename";
|
||||
$content = "<h1>$env->page</h1>";
|
||||
|
||||
$parsing_start = microtime(true);
|
||||
|
||||
$content .= $parse_page_source(file_get_contents("$page.md"));
|
||||
$content .= $parse_page_source(file_get_contents("$env->page.md"));
|
||||
|
||||
if($settings->show_subpages)
|
||||
{
|
||||
$subpages = get_object_vars(get_subpages($pageindex, $page));
|
||||
$subpages = get_object_vars(get_subpages($pageindex, $env->page));
|
||||
|
||||
if(count($subpages) > 0)
|
||||
{
|
||||
|
|
|
@ -54,11 +54,9 @@ class Slimdown {
|
|||
'/(\*)(.*?)\1/' => '<strong>\2</strong>', // bold
|
||||
'/(_)(.*?)\1/' => '<em>\2</em>', // emphasis
|
||||
|
||||
// todo test these
|
||||
'/!\[(.*)\]\(([^\s]+)\s(\d+.+)\s(left|right)\)/' => '<img src="\2" alt="\1" style="max-width: \3; float: \4;" />', // images with size
|
||||
'/!\[(.*)\]\(([^\s]+)\s(\d+.+)\)/' => '<img src="\2" alt="\1" style="max-width: \3;" />', // images with size
|
||||
'/!\[(.*)\]\((.*)\)/' => '<img src="\2" alt="\1" />', // basic images
|
||||
// todo end
|
||||
|
||||
'/\[\[([a-zA-Z0-9\_\- ]+)\|([a-zA-Z0-9\_\- ]+)\]\]/' => '<a href=\'index.php?page=\1\'>\2</a>', //internal links with display text
|
||||
'/\[\[([a-zA-Z0-9\_\- ]+)\]\]/' => '<a href=\'index.php?page=\1\'>\1</a>', //internal links
|
||||
|
|
Loading…
Reference in a new issue