mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Bugfix: undefined variable on line 1831
This commit is contained in:
parent
2daca17294
commit
7d425c3998
3 changed files with 135 additions and 116 deletions
209
build/index.php
209
build/index.php
|
@ -228,53 +228,63 @@ Actions:
|
||||||
/////////////// Do not edit below this line unless you know what you are doing! ///////////////
|
/////////////// Do not edit below this line unless you know what you are doing! ///////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
$version = "0.7";
|
$version = "0.7";
|
||||||
|
$env = new stdClass();
|
||||||
|
$env->action = $settings->defaultaction;
|
||||||
|
$env->page = "";
|
||||||
|
$env->user = "Anonymous";
|
||||||
|
$env->is_logged_in = false;
|
||||||
|
$env->is_admin = false;
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
///////// Login System /////////
|
///////// Login System /////////
|
||||||
//clear expired sessions
|
// Clear expired sessions
|
||||||
if(isset($_SESSION["$settings->sessionprefix-expiretime"]) and
|
if(isset($_SESSION["$settings->sessionprefix-expiretime"]) and
|
||||||
$_SESSION["$settings->sessionprefix-expiretime"] < time())
|
$_SESSION["$settings->sessionprefix-expiretime"] < time())
|
||||||
{
|
{
|
||||||
//clear the session variables
|
// Clear the session variables
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
$env->is_logged_in = false;
|
||||||
|
$env->user = "Anonymous";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($_SESSION[$settings->sessionprefix . "-user"]) and
|
if(!isset($_SESSION[$settings->sessionprefix . "-user"]) and
|
||||||
!isset($_SESSION[$settings->sessionprefix . "-pass"]))
|
!isset($_SESSION[$settings->sessionprefix . "-pass"]))
|
||||||
{
|
{
|
||||||
//the user is not logged in
|
// The user is not logged in
|
||||||
$isloggedin = false;
|
$env->is_logged_in = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$user = $_SESSION[$settings->sessionprefix . "-user"];
|
$env->user = $_SESSION[$settings->sessionprefix . "-user"];
|
||||||
$pass = $_SESSION[$settings->sessionprefix . "-pass"];
|
$env->pass = $_SESSION[$settings->sessionprefix . "-pass"];
|
||||||
if($settings->users[$user] == $pass)
|
if($settings->users[$env->user] == $env->pass)
|
||||||
{
|
{
|
||||||
//the user is logged in
|
// The user is logged in
|
||||||
$isloggedin = true;
|
$env->is_logged_in = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//the user's login details are invalid (what is going on here?)
|
// The user's login details are invalid (what is going on here?)
|
||||||
//unset the session variables, treat them as an anonymous user, and get out of here
|
// Unset the session variables, treat them as an anonymous user,
|
||||||
$isloggedin = false;
|
// and get out of here
|
||||||
unset($user);
|
$env->is_logged_in = false;
|
||||||
unset($pass);
|
$env->user = "Anonymous";
|
||||||
//clear the session data
|
$env->pass = "";
|
||||||
|
// Clear the session data
|
||||||
$_SESSION = []; //delete all the variables
|
$_SESSION = []; //delete all the variables
|
||||||
session_destroy(); //destroy the session
|
session_destroy(); //destroy the session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check to see if the currently logged in user is an admin
|
//check to see if the currently logged in user is an admin
|
||||||
$isadmin = false;
|
$env->is_admin = false;
|
||||||
if($isloggedin)
|
if($env->is_logged_in)
|
||||||
{
|
{
|
||||||
foreach($settings->admins as $admin_username)
|
foreach($settings->admins as $admin_username)
|
||||||
{
|
{
|
||||||
if($admin_username == $user)
|
if($admin_username == $env->user)
|
||||||
{
|
{
|
||||||
$isadmin = true;
|
$env->is_admin = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,7 +545,9 @@ if(makepathsafe($_GET["page"]) !== $_GET["page"])
|
||||||
header("x-actual-page: " . makepathsafe($_GET["page"]));
|
header("x-actual-page: " . makepathsafe($_GET["page"]));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
$page = $_GET["page"];
|
|
||||||
|
$env->page = $_GET["page"];
|
||||||
|
$env->action = strtolower($_GET["action"]);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -591,6 +603,8 @@ class page_renderer
|
||||||
// Registers a function as a part post processor.
|
// Registers a function as a part post processor.
|
||||||
public static function register_part_preprocessor($function)
|
public static function register_part_preprocessor($function)
|
||||||
{
|
{
|
||||||
|
global $settings;
|
||||||
|
|
||||||
// Make sure that the function we are about to register is valid
|
// Make sure that the function we are about to register is valid
|
||||||
if(!is_callable($function))
|
if(!is_callable($function))
|
||||||
{
|
{
|
||||||
|
@ -685,7 +699,7 @@ class page_renderer
|
||||||
*/
|
*/
|
||||||
public static function render_navigation_bar($nav_links, $nav_links_extra, $class = "")
|
public static function render_navigation_bar($nav_links, $nav_links_extra, $class = "")
|
||||||
{
|
{
|
||||||
global $settings, $user, $isloggedin, $page;
|
global $settings, $env;
|
||||||
$result = "<nav class='$class'>\n";
|
$result = "<nav class='$class'>\n";
|
||||||
|
|
||||||
// Loop over all the navigation links
|
// Loop over all the navigation links
|
||||||
|
@ -698,7 +712,7 @@ class page_renderer
|
||||||
{
|
{
|
||||||
//keywords
|
//keywords
|
||||||
case "user-status":
|
case "user-status":
|
||||||
if($isloggedin)
|
if($env->is_logged_in)
|
||||||
{
|
{
|
||||||
$result .= "<span class='inflexible'>Logged in as " . self::render_username($user) . ".</span> "/* . page_renderer::$nav_divider*/;
|
$result .= "<span class='inflexible'>Logged in as " . self::render_username($user) . ".</span> "/* . page_renderer::$nav_divider*/;
|
||||||
$result .= "<span><a href='index.php?action=logout'>Logout</a></span>";
|
$result .= "<span><a href='index.php?action=logout'>Logout</a></span>";
|
||||||
|
@ -731,7 +745,7 @@ class page_renderer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Output the item as a link to a url
|
// Output the item as a link to a url
|
||||||
$result .= "<span><a href='" . str_replace("{page}", $page, $item[1]) . "'>$item[0]</a></span>";
|
$result .= "<span><a href='" . str_replace("{page}", $env->page, $item[1]) . "'>$item[0]</a></span>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -833,18 +847,18 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Raw page source",
|
"name" => "Raw page source",
|
||||||
"version" => "0.2",
|
"version" => "0.3",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "Adds a 'raw' action that shows you the raw source of a page.",
|
"description" => "Adds a 'raw' action that shows you the raw source of a page.",
|
||||||
"id" => "action-raw",
|
"id" => "action-raw",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("raw", function() {
|
add_action("raw", function() {
|
||||||
global $page;
|
global $env;
|
||||||
|
|
||||||
http_response_code(307);
|
http_response_code(307);
|
||||||
header("x-filename: " . rawurlencode($page) . ".md");
|
header("x-filename: " . rawurlencode($env->page) . ".md");
|
||||||
header("content-type: text/markdown");
|
header("content-type: text/markdown");
|
||||||
exit(file_get_contents("$page.md"));
|
exit(file_get_contents("$env->page.md"));
|
||||||
exit();
|
exit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1027,36 +1041,37 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Page deleter",
|
"name" => "Page deleter",
|
||||||
"version" => "0.5",
|
"version" => "0.6",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "Adds an action to allow administrators to delete pages.",
|
"description" => "Adds an action to allow administrators to delete pages.",
|
||||||
"id" => "page-delete",
|
"id" => "page-delete",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("delete", function() {
|
add_action("delete", function() {
|
||||||
global $pageindex, $settings, $page, $isadmin;
|
global $pageindex, $settings, $env;
|
||||||
if(!$settings->editing)
|
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>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>"));
|
<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>"));
|
<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")
|
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>
|
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=$page&delete=yes'>Click here to delete $page.</a></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=$page'>Click here to go back.</a>"));
|
<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
|
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
|
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>"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
@ -1066,7 +1081,7 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Page editor",
|
"name" => "Page editor",
|
||||||
"version" => "0.8",
|
"version" => "0.9",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
"description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
||||||
"id" => "page-edit",
|
"id" => "page-edit",
|
||||||
|
@ -1082,20 +1097,21 @@ register_module([
|
||||||
* %edit%
|
* %edit%
|
||||||
*/
|
*/
|
||||||
add_action("edit", function() {
|
add_action("edit", function() {
|
||||||
global $pageindex, $settings, $page, $isloggedin;
|
global $pageindex, $settings, $env;
|
||||||
|
|
||||||
$filename = "$page.md";
|
$filename = "$env->page.md";
|
||||||
$creatingpage = !isset($pageindex->$page);
|
$creatingpage = !isset($pageindex->$page);
|
||||||
if((isset($_GET["newpage"]) and $_GET["newpage"] == "true") or $creatingpage)
|
if((isset($_GET["newpage"]) and $_GET["newpage"] == "true") or $creatingpage)
|
||||||
{
|
{
|
||||||
$title = "Creating $page";
|
$title = "Creating $env->page";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$title = "Editing $page";
|
$title = "Editing $env->page";
|
||||||
}
|
}
|
||||||
|
|
||||||
$pagetext = "";
|
$pagetext = "";
|
||||||
|
$page = $env->$page;
|
||||||
if(isset($pageindex->$page))
|
if(isset($pageindex->$page))
|
||||||
{
|
{
|
||||||
$pagetext = file_get_contents($filename);
|
$pagetext = file_get_contents($filename);
|
||||||
|
@ -1106,17 +1122,17 @@ register_module([
|
||||||
if(!$creatingpage)
|
if(!$creatingpage)
|
||||||
{
|
{
|
||||||
// The page already exists - let the user view the page source
|
// 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
|
else
|
||||||
{
|
{
|
||||||
http_response_code(404);
|
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>";
|
$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>";
|
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||||
}
|
}
|
||||||
|
@ -1136,35 +1152,36 @@ register_module([
|
||||||
* %save%
|
* %save%
|
||||||
*/
|
*/
|
||||||
add_action("save", function() {
|
add_action("save", function() {
|
||||||
global $pageindex, $settings, $page, $isloggedin, $user;
|
global $pageindex, $settings, $env;
|
||||||
if(!$settings->editing)
|
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>"));
|
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);
|
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....");
|
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"]))
|
if(!isset($_POST["content"]))
|
||||||
{
|
{
|
||||||
http_response_code(400);
|
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.");
|
exit("Bad request: No content specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the directory in which the page needs to be saved exists
|
// 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
|
// 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
|
// Make sure that this page's parents exist
|
||||||
check_subpage_parents($page);
|
check_subpage_parents($page);
|
||||||
|
|
||||||
|
@ -1172,12 +1189,12 @@ register_module([
|
||||||
if(!isset($pageindex->$page))
|
if(!isset($pageindex->$page))
|
||||||
{
|
{
|
||||||
$pageindex->$page = new stdClass();
|
$pageindex->$page = new stdClass();
|
||||||
$pageindex->$page->filename = "$page.md";
|
$pageindex->$page->filename = "$env->page.md";
|
||||||
}
|
}
|
||||||
$pageindex->$page->size = strlen($_POST["content"]);
|
$pageindex->$page->size = strlen($_POST["content"]);
|
||||||
$pageindex->$page->lastmodified = time();
|
$pageindex->$page->lastmodified = time();
|
||||||
if($isloggedin)
|
if($isloggedin)
|
||||||
$pageindex->$page->lasteditor = utf8_encode($user);
|
$pageindex->$page->lasteditor = utf8_encode($env->user);
|
||||||
else
|
else
|
||||||
$pageindex->$page->lasteditor = utf8_encode("anonymous");
|
$pageindex->$page->lasteditor = utf8_encode("anonymous");
|
||||||
|
|
||||||
|
@ -1188,7 +1205,7 @@ register_module([
|
||||||
else
|
else
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
|
|
||||||
header("location: index.php?page=$page&edit_status=success");
|
header("location: index.php?page=$env->page&edit_status=success");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1206,15 +1223,15 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Export",
|
"name" => "Export",
|
||||||
"version" => "0.1",
|
"version" => "0.2",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id" => "page-export",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("export", 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);
|
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>."));
|
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>."));
|
||||||
|
@ -1361,7 +1378,7 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Login",
|
"name" => "Login",
|
||||||
"version" => "0.5",
|
"version" => "0.6",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id" => "page-login",
|
||||||
|
@ -1401,7 +1418,7 @@ register_module([
|
||||||
* %checklogin% |___/
|
* %checklogin% |___/
|
||||||
*/
|
*/
|
||||||
add_action("checklogin", function() {
|
add_action("checklogin", function() {
|
||||||
global $settings;
|
global $settings, $env;
|
||||||
|
|
||||||
//actually do the login
|
//actually do the login
|
||||||
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
||||||
|
@ -1411,7 +1428,7 @@ register_module([
|
||||||
$pass = $_POST["pass"];
|
$pass = $_POST["pass"];
|
||||||
if($settings->users[$user] == hash("sha256", $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
|
$expiretime = time() + 60*60*24*30; //30 days from now
|
||||||
$_SESSION["$settings->sessionprefix-user"] = $user;
|
$_SESSION["$settings->sessionprefix-user"] = $user;
|
||||||
$_SESSION["$settings->sessionprefix-pass"] = hash("sha256", $pass);
|
$_SESSION["$settings->sessionprefix-pass"] = hash("sha256", $pass);
|
||||||
|
@ -1445,16 +1462,16 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Logout",
|
"name" => "Logout",
|
||||||
"version" => "0.5",
|
"version" => "0.6",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id" => "page-logout",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("logout", function() {
|
add_action("logout", function() {
|
||||||
global $user, $pass, $isloggedin;
|
global $env;
|
||||||
$isloggedin = false;
|
$env->is_logged_in = false;
|
||||||
unset($user);
|
unset($env->user);
|
||||||
unset($pass);
|
unset($env->pass);
|
||||||
//clear the session variables
|
//clear the session variables
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
@ -1470,32 +1487,32 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Page mover",
|
"name" => "Page mover",
|
||||||
"version" => "0.5",
|
"version" => "0.6",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "Adds an action to allow administrators to move pages.",
|
"description" => "Adds an action to allow administrators to move pages.",
|
||||||
"id" => "page-move",
|
"id" => "page-move",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("move", function() {
|
add_action("move", function() {
|
||||||
global $pageindex, $settings, $page, $isadmin;
|
global $pageindex, $settings, $env;
|
||||||
if(!$settings->editing)
|
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>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>"));
|
<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>"));
|
<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)
|
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'>
|
<form method='get' action='index.php'>
|
||||||
<input type='hidden' name='action' value='move' />
|
<input type='hidden' name='action' value='move' />
|
||||||
<label for='old_name'>Old Name:</label>
|
<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 />
|
<br />
|
||||||
<label for='new_name'>New Name:</label>
|
<label for='new_name'>New Name:</label>
|
||||||
<input type='text' name='new_name' />
|
<input type='text' name='new_name' />
|
||||||
|
@ -1505,12 +1522,13 @@ register_module([
|
||||||
|
|
||||||
$new_name = makepathsafe($_GET["new_name"]);
|
$new_name = makepathsafe($_GET["new_name"]);
|
||||||
|
|
||||||
|
$page = $env->page;
|
||||||
if(!isset($pageindex->$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>"));
|
<p>Nothing has been changed.</p>"));
|
||||||
|
|
||||||
if($page == $new_name)
|
if($env->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>
|
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>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>"));
|
<p>Page names may only contain alphanumeric characters, dashes, and underscores.</p>"));
|
||||||
|
|
||||||
|
@ -1524,26 +1542,27 @@ register_module([
|
||||||
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
//move the page on the disk
|
//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>"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Update",
|
"name" => "Update",
|
||||||
"version" => "0.6",
|
"version" => "0.6.1",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id" => "page-update",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("update", function() {
|
add_action("update", function() {
|
||||||
global $settings, $isadmin;
|
global $settings, $env;
|
||||||
|
|
||||||
if(!$isadmin)
|
if(!$env->is_admin)
|
||||||
{
|
{
|
||||||
http_response_code(401);
|
http_response_code(401);
|
||||||
exit(page_renderer::render_main("Update - Error", "<p>You must be an administrator to do that.</p>"));
|
exit(page_renderer::render_main("Update - Error", "<p>You must be an administrator to do that.</p>"));
|
||||||
|
@ -1602,15 +1621,16 @@ register_module([
|
||||||
|
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Page viewer",
|
"name" => "Page viewer",
|
||||||
"version" => "0.8",
|
"version" => "0.9",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "Allows you to view pages. You should include this one.",
|
"description" => "Allows you to view pages. You should include this one.",
|
||||||
"id" => "page-view",
|
"id" => "page-view",
|
||||||
"code" => function() {
|
"code" => function() {
|
||||||
add_action("view", 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
|
// Check to make sure that the page exists
|
||||||
|
$page = $env->page;
|
||||||
if(!isset($pageindex->$page))
|
if(!isset($pageindex->$page))
|
||||||
{
|
{
|
||||||
// todo make this intelligent so we only redirect if the user is acutally able to create the page
|
// todo make this intelligent so we only redirect if the user is acutally able to create the page
|
||||||
|
@ -1618,26 +1638,26 @@ register_module([
|
||||||
{
|
{
|
||||||
// Editing is enabled, redirect to the editing page
|
// Editing is enabled, redirect to the editing page
|
||||||
http_response_code(307); // Temporary redirect
|
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();
|
exit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Editing is disabled, show an error message
|
// Editing is disabled, show an error message
|
||||||
http_response_code(404);
|
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";
|
$title = "$env->page - $settings->sitename";
|
||||||
$content = "<h1>$page</h1>";
|
$content = "<h1>$env->page</h1>";
|
||||||
|
|
||||||
$parsing_start = microtime(true);
|
$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)
|
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)
|
if(count($subpages) > 0)
|
||||||
{
|
{
|
||||||
|
@ -1723,11 +1743,9 @@ class Slimdown {
|
||||||
'/(\*)(.*?)\1/' => '<strong>\2</strong>', // bold
|
'/(\*)(.*?)\1/' => '<strong>\2</strong>', // bold
|
||||||
'/(_)(.*?)\1/' => '<em>\2</em>', // emphasis
|
'/(_)(.*?)\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+.+)\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
|
'/!\[(.*)\]\(([^\s]+)\s(\d+.+)\)/' => '<img src="\2" alt="\1" style="max-width: \3;" />', // images with size
|
||||||
'/!\[(.*)\]\((.*)\)/' => '<img src="\2" alt="\1" />', // basic images
|
'/!\[(.*)\]\((.*)\)/' => '<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-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
|
'/\[\[([a-zA-Z0-9\_\- ]+)\]\]/' => '<a href=\'index.php?page=\1\'>\1</a>', //internal links
|
||||||
|
@ -1810,7 +1828,7 @@ if(!isset($actions->credits))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the appropriate action
|
// Perform the appropriate action
|
||||||
$action_name = strtolower($_GET["action"]);
|
$action_name = $env->action;
|
||||||
if(isset($actions->$action_name))
|
if(isset($actions->$action_name))
|
||||||
{
|
{
|
||||||
$req_action_data = $actions->$action_name;
|
$req_action_data = $actions->$action_name;
|
||||||
|
@ -1820,4 +1838,5 @@ else
|
||||||
{
|
{
|
||||||
exit(page_renderer::render_main("Error - $settings->sitename", "<p>No action called " . strtolower($_GET["action"]) ." has been registered. Perhaps you are missing a module?</p>"));
|
exit(page_renderer::render_main("Error - $settings->sitename", "<p>No action called " . strtolower($_GET["action"]) ." has been registered. Perhaps you are missing a module?</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
2
core.php
2
core.php
|
@ -613,9 +613,9 @@ if(!isset($actions->credits))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the appropriate action
|
// Perform the appropriate action
|
||||||
|
$action_name = $env->action;
|
||||||
if(isset($actions->$action_name))
|
if(isset($actions->$action_name))
|
||||||
{
|
{
|
||||||
$action_name = $env->action;
|
|
||||||
$req_action_data = $actions->$action_name;
|
$req_action_data = $actions->$action_name;
|
||||||
$req_action_data();
|
$req_action_data();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Raw page source",
|
"name": "Raw page source",
|
||||||
"version": "0.2",
|
"version": "0.3",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds a 'raw' action that shows you the raw source of a page.",
|
"description": "Adds a 'raw' action that shows you the raw source of a page.",
|
||||||
"id": "action-raw",
|
"id": "action-raw",
|
||||||
"lastupdate": 1442855075
|
"lastupdate": 1442903519
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Sidebar",
|
"name": "Sidebar",
|
||||||
|
@ -33,27 +33,27 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Page deleter",
|
"name": "Page deleter",
|
||||||
"version": "0.5",
|
"version": "0.6",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds an action to allow administrators to delete pages.",
|
"description": "Adds an action to allow administrators to delete pages.",
|
||||||
"id": "page-delete",
|
"id": "page-delete",
|
||||||
"lastupdate": 1432497591
|
"lastupdate": 1442929182
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Page editor",
|
"name": "Page editor",
|
||||||
"version": "0.8",
|
"version": "0.9",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
||||||
"id": "page-edit",
|
"id": "page-edit",
|
||||||
"lastupdate": 1437037997
|
"lastupdate": 1442903905
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Export",
|
"name": "Export",
|
||||||
"version": "0.1",
|
"version": "0.2",
|
||||||
"author": "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id": "page-export",
|
||||||
"lastupdate": 1437213501
|
"lastupdate": 1442927946
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Help page",
|
"name": "Help page",
|
||||||
|
@ -73,43 +73,43 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Login",
|
"name": "Login",
|
||||||
"version": "0.5",
|
"version": "0.6",
|
||||||
"author": "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id": "page-login",
|
||||||
"lastupdate": 1438004499
|
"lastupdate": 1442928221
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Logout",
|
"name": "Logout",
|
||||||
"version": "0.5",
|
"version": "0.6",
|
||||||
"author": "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id": "page-logout",
|
||||||
"lastupdate": 1432497592
|
"lastupdate": 1442928225
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Page mover",
|
"name": "Page mover",
|
||||||
"version": "0.5",
|
"version": "0.6",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds an action to allow administrators to move pages.",
|
"description": "Adds an action to allow administrators to move pages.",
|
||||||
"id": "page-move",
|
"id": "page-move",
|
||||||
"lastupdate": 1432497592
|
"lastupdate": 1442928409
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Update",
|
"name": "Update",
|
||||||
"version": "0.6",
|
"version": "0.6.1",
|
||||||
"author": "Starbeamrainbowlabs",
|
"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.",
|
"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",
|
"id": "page-update",
|
||||||
"lastupdate": 1432497592
|
"lastupdate": 1442928402
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Page viewer",
|
"name": "Page viewer",
|
||||||
"version": "0.8",
|
"version": "0.9",
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Allows you to view pages. You should include this one.",
|
"description": "Allows you to view pages. You should include this one.",
|
||||||
"id": "page-view",
|
"id": "page-view",
|
||||||
"lastupdate": 1436889857
|
"lastupdate": 1442928503
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Default Parser",
|
"name": "Default Parser",
|
||||||
|
@ -117,6 +117,6 @@
|
||||||
"author": "Johnny Broadway & Starbeamrainbowlabs",
|
"author": "Johnny Broadway & Starbeamrainbowlabs",
|
||||||
"description": "The default parser for Pepperminty Wiki. Based on Johnny Broadway's Slimdown (with more than a few modifications). This parser's features are documented in the help page.",
|
"description": "The default parser for Pepperminty Wiki. Based on Johnny Broadway's Slimdown (with more than a few modifications). This parser's features are documented in the help page.",
|
||||||
"id": "parser-default",
|
"id": "parser-default",
|
||||||
"lastupdate": 1432720270
|
"lastupdate": 1442928533
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
Reference in a new issue