1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 05:22:59 +00:00

Fixed issue #1 and corrected 'built by' url

This commit is contained in:
Starbeamrainbowlabs 2015-01-05 18:44:11 +00:00
parent edec06fb71
commit 5ca2a644e8
2 changed files with 285 additions and 253 deletions

View file

@ -208,7 +208,7 @@ function renderpage($title, $content, $minimal = false)
$content $content
<hr class='footerdivider' /> <hr class='footerdivider' />
<footer> <footer>
<p>Powered by Pepperminty Wiki, which was built by <a href='//starbeamrainbowlabs'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue <a href='//github.com/sbrl/Pepperminty-Wiki'>on github</a>.</p> <p>Powered by Pepperminty Wiki, which was built by <a href='//starbeamrainbowlabs.com/'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue <a href='//github.com/sbrl/Pepperminty-Wiki'>on github</a>.</p>
<p>Your local friendly administrators are " . implode(", ", $admins) . ". <p>Your local friendly administrators are " . implode(", ", $admins) . ".
<p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p> <p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p>
</footer> </footer>
@ -526,6 +526,13 @@ switch($_GET["action"])
* %delete% * %delete%
*/ */
case "delete": case "delete":
if(!$editing)
{
exit(renderpage("Deleting $page - error", "<p>You tried to delete $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>Nothing has been changed.</p>"));
}
if(!$isadmin) if(!$isadmin)
{ {
exit(renderpage("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(renderpage("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>
@ -553,9 +560,18 @@ switch($_GET["action"])
* %move% * %move%
*/ */
case "move": case "move":
if(!$editing)
{
exit(renderpage("Moving $page - error", "<p>You tried to move $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>Nothing has been changed.</p>"));
}
if(!$isadmin) if(!$isadmin)
{
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but you do not have permission to do that.</p> exit(renderpage("Moving $page - Error", "<p>You tried to move $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(renderpage("Moving $page", "<h2>Moving $page</h2> exit(renderpage("Moving $page", "<h2>Moving $page</h2>

520
index.php
View file

@ -1,5 +1,5 @@
<?php <?php
$start_time = time(true); $start_time = time(true);
/* /*
@ -116,7 +116,7 @@ Actions:
page - page name page - page name
delete=yes - actually do the deletion (otherwise we display a prompt) delete=yes - actually do the deletion (otherwise we display a prompt)
*/ */
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/////////////// 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! ///////////////
@ -149,19 +149,19 @@ else
setcookie($cookieprefix . "-pass", null, -1, "/"); setcookie($cookieprefix . "-pass", null, -1, "/");
} }
} }
//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; $isadmin = false;
if($isloggedin) if($isloggedin)
{ {
foreach($admins as $admin_username) foreach($admins as $admin_username)
{ {
if($admin_username == $user) if($admin_username == $user)
{ {
$isadmin = true; $isadmin = true;
break; break;
} }
} }
} }
/////// Login System End /////// /////// Login System End ///////
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -242,7 +242,7 @@ 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"]; $page = $_GET["page"];
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -252,22 +252,22 @@ $page = $_GET["page"];
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
function renderpage($title, $content, $minimal = false) function renderpage($title, $content, $minimal = false)
{ {
global $sitename, $page, $css, $favicon, $user, $isloggedin, $isadmin, $admins, $admindisplaychar, $navlinks, $admindetails, $start_time, $pageindex; global $sitename, $page, $css, $favicon, $user, $isloggedin, $isadmin, $admins, $admindisplaychar, $navlinks, $admindetails, $start_time, $pageindex;
$html = "<!DOCTYPE HTML> $html = "<!DOCTYPE HTML>
<html><head> <html><head>
<meta charset='utf-8' /> <meta charset='utf-8' />
<title>$title</title> <title>$title</title>
<link rel='shortcut icon' href='$favicon' />"; <link rel='shortcut icon' href='$favicon' />";
if(preg_match("/^[^\/]*\/\/|^\//", $css)) if(preg_match("/^[^\/]*\/\/|^\//", $css))
{ {
$html .= "\n\t\t<link rel='stylesheet' href='$css' />\n"; $html .= "\n\t\t<link rel='stylesheet' href='$css' />\n";
} }
else else
{ {
$html .= "\n\t\t<style>$css</style>\n"; $html .= "\n\t\t<style>$css</style>\n";
} }
$html .= "</head><body>\n"; $html .= "</head><body>\n";
////////// //////////
@ -284,47 +284,47 @@ function renderpage($title, $content, $minimal = false)
$html .= "<nav>\n"; $html .= "<nav>\n";
if($isloggedin) if($isloggedin)
{ {
$html .= "\t\tLogged in as "; $html .= "\t\tLogged in as ";
if($isadmin) if($isadmin)
$html .= $admindisplaychar; $html .= $admindisplaychar;
$html .= "$user. <a href='index.php?action=logout'>Logout</a>. | \n"; $html .= "$user. <a href='index.php?action=logout'>Logout</a>. | \n";
} }
else else
$html .= "\t\tBrowsing as Anonymous. <a href='index.php?action=login'>Login</a>. | \n"; $html .= "\t\tBrowsing as Anonymous. <a href='index.php?action=login'>Login</a>. | \n";
foreach($navlinks as $item) foreach($navlinks as $item)
{ {
if(is_string($item)) if(is_string($item))
{ {
//the item is a string //the item is a string
switch($item) switch($item)
{ {
//keywords //keywords
case "search": //displays a search bar case "search": //displays a search bar
$html .= "<form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /></form>"; $html .= "<form method='get' action='index.php' style='display: inline;'><input type='search' name='page' list='allpages' placeholder='Type a page name here and hit enter' /></form>";
break; break;
//it isn't a keyword, so just output it directly //it isn't a keyword, so just output it directly
default: default:
$html .= $item; $html .= $item;
} }
} }
else else
{ {
//output the display as a link to the url //output the display as a link to the url
$html .= "\t\t<a href='" . str_replace("{page}", $page, $item[1]) . "'>$item[0]</a>\n"; $html .= "\t\t<a href='" . str_replace("{page}", $page, $item[1]) . "'>$item[0]</a>\n";
} }
} }
$html .= " </nav> $html .= " </nav>
<h1 class='sitename'>$sitename</h1> <h1 class='sitename'>$sitename</h1>
$content $content
<hr class='footerdivider' /> <hr class='footerdivider' />
<footer> <footer>
<p>Powered by Pepperminty Wiki, which was built by <a href='//starbeamrainbowlabs'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue <a href='//github.com/sbrl/Pepperminty-Wiki'>on github</a>.</p> <p>Powered by Pepperminty Wiki, which was built by <a href='//starbeamrainbowlabs.com/'>Starbeamrainbowlabs</a>. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue <a href='//github.com/sbrl/Pepperminty-Wiki'>on github</a>.</p>
<p>Your local friendly administrators are " . implode(", ", $admins) . ". <p>Your local friendly administrators are " . implode(", ", $admins) . ".
<p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p> <p>This wiki is managed by <a href='mailto:" . hide_email($admindetails["email"]) . "'>" . $admindetails["name"] . "</a>.</p>
</footer> </footer>
<datalist id='allpages'>\n"; <datalist id='allpages'>\n";
@ -347,7 +347,7 @@ function renderpage($title, $content, $minimal = false)
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// Slimdown ///////////////////////////////////////// ///////////////////////////////////////// Slimdown /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// %slimdown% // ////////////////////////////////////////////////////////////////////////////// %slimdown% //
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* Slimdown - A very basic regex-based Markdown parser. Supports the * Slimdown - A very basic regex-based Markdown parser. Supports the
@ -390,7 +390,7 @@ class Slimdown {
'/\~\~(.*?)\~\~/' => '<del>\1</del>', // del '/\~\~(.*?)\~\~/' => '<del>\1</del>', // del
'/\:\"(.*?)\"\:/' => '<q>\1</q>', // quote '/\:\"(.*?)\"\:/' => '<q>\1</q>', // quote
'/`(.*?)`/' => '<code>\1</code>', // inline code '/`(.*?)`/' => '<code>\1</code>', // inline code
'/\n\s*(\*|-)(.*)/' => 'self::ul_list', // ul lists '/\n\s*(\*|-)(.*)/' => 'self::ul_list', // ul lists
'/\n[0-9]+\.(.*)/' => 'self::ol_list', // ol lists '/\n[0-9]+\.(.*)/' => 'self::ol_list', // ol lists
'/\n(&gt;|\>)(.*)/' => 'self::blockquote', // blockquotes '/\n(&gt;|\>)(.*)/' => 'self::blockquote', // blockquotes
'/\n-{3,}/' => "\n<hr />", // horizontal rule '/\n-{3,}/' => "\n<hr />", // horizontal rule
@ -408,7 +408,7 @@ class Slimdown {
return sprintf ("\n<p>%s</p>\n", $trimmed); return sprintf ("\n<p>%s</p>\n", $trimmed);
} }
private static function ul_list ($regs) { private static function ul_list ($regs) {
$item = $regs[2]; $item = $regs[2];
return sprintf ("\n<ul>\n\t<li>%s</li>\n</ul>", trim($item)); return sprintf ("\n<ul>\n\t<li>%s</li>\n</ul>", trim($item));
} }
private static function ol_list ($regs) { private static function ol_list ($regs) {
@ -482,104 +482,104 @@ function human_time_since($time)
switch($_GET["action"]) switch($_GET["action"])
{ {
/* /*
* _ _ _ * _ _ _
* ___ __| (_) |_ * ___ __| (_) |_
* / _ \/ _` | | __| * / _ \/ _` | | __|
* | __/ (_| | | |_ * | __/ (_| | | |_
* \___|\__,_|_|\__| * \___|\__,_|_|\__|
* %edit% * %edit%
*/ */
case "edit": case "edit":
if(!$editing) if(!$editing)
{ {
http_response_code(203); http_response_code(203);
header("location: index.php?page=$page"); header("location: index.php?page=$page");
} }
$filename = "$page.md"; $filename = "$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 $page";
} }
else else
{ {
$title = "Editing $page"; $title = "Editing $page";
} }
$pagetext = ""; $pagetext = "";
if(isset($pageindex->$page)) if(isset($pageindex->$page))
{ {
$pagetext = file_get_contents($filename); $pagetext = file_get_contents($filename);
} }
if((!$isloggedin and !$anonedits) or !$editing) if((!$isloggedin and !$anonedits) or !$editing)
{ {
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(renderpage("Viewing source for $page", "<textarea readonly>$pagetext</textarea>")); exit(renderpage("Viewing source for $page", "<textarea readonly>$pagetext</textarea>"));
} }
else else
{ {
http_response_code(404); http_response_code(404);
exit(renderpage("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(renderpage("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>"));
} }
} }
$content = "<h1>$title</h1>"; $content = "<h1>$title</h1>";
if(!$isloggedin and $anonedits) if(!$isloggedin and $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>";
} }
$content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save'> $content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save'>
<textarea name='content'>$pagetext</textarea> <textarea name='content'>$pagetext</textarea>
<input type='submit' value='Save Page' /> <input type='submit' value='Save Page' />
</form>"; </form>";
exit(renderpage("$title - $sitename", $content)); exit(renderpage("$title - $sitename", $content));
break; break;
/* /*
* *
* ___ __ ___ _____ * ___ __ ___ _____
* / __|/ _` \ \ / / _ \ * / __|/ _` \ \ / / _ \
* \__ \ (_| |\ V / __/ * \__ \ (_| |\ V / __/
* |___/\__,_| \_/ \___| * |___/\__,_| \_/ \___|
* %save% * %save%
*/ */
case "save": case "save":
if(!$editing) if(!$editing)
{ {
header("location: index.php?page=$page"); header("location: index.php?page=$page");
exit(renderpage("Error saving edit", "<p>Editing is currently disabled on this wiki.</p>")); exit(renderpage("Error saving edit", "<p>Editing is currently disabled on this wiki.</p>"));
} }
if(!$isloggedin and !$anonedits) if(!$isloggedin and !$anonedits)
{ {
http_response_code(403); http_response_code(403);
header("refresh: 5; url=index.php?page=$page"); header("refresh: 5; url=index.php?page=$page");
exit("You are not logged in, so you are not allowed to save pages on $sitename. Redirecting in 5 seconds...."); exit("You are not logged in, so you are not allowed to save pages on $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=$page");
exit("Bad request: No content specified."); exit("Bad request: No content specified.");
} }
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
{ {
//update the page index //update the page index
if(!isset($pageindex->$page)) if(!isset($pageindex->$page))
{ {
$pageindex->$page = new stdClass(); $pageindex->$page = new stdClass();
$pageindex->$page->filename = "$page.md"; $pageindex->$page->filename = "$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($user);
else else
$pageindex->$page->lasteditor = utf8_encode("anonymous"); $pageindex->$page->lasteditor = utf8_encode("anonymous");
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
@ -588,7 +588,7 @@ switch($_GET["action"])
else else
http_response_code(200); http_response_code(200);
header("location: index.php?page=$page"); header("location: index.php?page=$page");
exit(); exit();
} }
else else
@ -599,14 +599,14 @@ switch($_GET["action"])
} }
break; break;
/* /*
* _ _ _ * _ _ _
* | (_)___| |_ * | (_)___| |_
* | | / __| __| * | | / __| __|
* | | \__ \ |_ * | | \__ \ |_
* |_|_|___/\__| * |_|_|___/\__|
* %list% * %list%
*/ */
case "list": case "list":
$title = "All Pages"; $title = "All Pages";
$content = " <h1>$title on $sitename</h1> $content = " <h1>$title on $sitename</h1>
@ -632,93 +632,109 @@ switch($_GET["action"])
exit(renderpage("$title - $sitename", $content)); exit(renderpage("$title - $sitename", $content));
break; break;
/* /*
* _ _ _ * _ _ _
* __| | ___| | ___| |_ ___ * __| | ___| | ___| |_ ___
* / _` |/ _ \ |/ _ \ __/ _ \ * / _` |/ _ \ |/ _ \ __/ _ \
* | (_| | __/ | __/ || __/ * | (_| | __/ | __/ || __/
* \__,_|\___|_|\___|\__\___| * \__,_|\___|_|\___|\__\___|
* %delete% * %delete%
*/ */
case "delete": case "delete":
if(!$isadmin) if(!$editing)
{ {
exit(renderpage("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(renderpage("Deleting $page - error", "<p>You tried to delete $page, but editing is disabled on this wiki.</p>
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</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>
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes") <p>Nothing has been changed.</p>"));
{ }
exit(renderpage("Deleting $page", "<p>You are about to <strong>delete</strong> $page. You can't undo this!</p> if(!$isadmin)
<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(renderpage("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>
} <p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
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 if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
unlink("./$page.md"); //delete the page from the disk {
exit(renderpage("Deleting $page", "<p>You are about to <strong>delete</strong> $page. You can't undo this!</p>
exit(renderpage("Deleting $page - $sitename", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</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>"));
}
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
exit(renderpage("Deleting $page - $sitename", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
break; break;
/* /*
* __ __ * __ __
* | \/ | _____ _____ * | \/ | _____ _____
* | |\/| |/ _ \ \ / / _ \ * | |\/| |/ _ \ \ / / _ \
* | | | | (_) \ V / __/ * | | | | (_) \ V / __/
* |_| |_|\___/ \_/ \___| * |_| |_|\___/ \_/ \___|
* %move% * %move%
*/ */
case "move": case "move":
if(!$isadmin) if(!$editing)
exit(renderpage("Moving $page - Error", "<p>You tried to move $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>")); exit(renderpage("Moving $page - error", "<p>You tried to move $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>
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0) <p><a href='index.php?page=$page'>Go back to $page</a>.</p>
exit(renderpage("Moving $page", "<h2>Moving $page</h2> <p>Nothing has been changed.</p>"));
<form method='get' action='index.php'> }
<input type='hidden' name='action' value='move' /> if(!$isadmin)
<label for='old_name'>Old Name:</label> {
<input type='text' name='page' value='$page' readonly /> exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but you do not have permission to do that.</p>
<br /> <p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
<label for='new_name'>New Name:</label> }
<input type='text' name='new_name' />
<br /> if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
<input type='submit' value='Move Page' /> exit(renderpage("Moving $page", "<h2>Moving $page</h2>
</form>")); <form method='get' action='index.php'>
<input type='hidden' name='action' value='move' />
$new_name = makepathsafe($_GET["new_name"]); <label for='old_name'>Old Name:</label>
<input type='text' name='page' value='$page' readonly />
if(!isset($pageindex->$page)) <br />
exit(renderpage("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> <label for='new_name'>New Name:</label>
<p>Nothing has been changed.</p>")); <input type='text' name='new_name' />
<br />
if($page == $new_name) <input type='submit' value='Move Page' />
exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p> </form>"));
<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>")); $new_name = makepathsafe($_GET["new_name"]);
//move the page in the page index if(!isset($pageindex->$page))
$pageindex->$new_name = new stdClass(); exit(renderpage("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>
foreach($pageindex->$page as $key => $value) <p>Nothing has been changed.</p>"));
{
$pageindex->$new_name->$key = $value; if($page == $new_name)
} exit(renderpage("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
unset($pageindex->$page); <p>It is possible that you tried to use some characters in the new name that are not allowed and were removed.</p>
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); <p>Page names may only contain alphanumeric characters, dashes, and underscores.</p>"));
//move the page on the disk //move the page in the page index
rename("$page.md", "$new_name.md"); $pageindex->$new_name = new stdClass();
foreach($pageindex->$page as $key => $value)
exit(renderpage("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>")); {
break; $pageindex->$new_name->$key = $value;
}
/* unset($pageindex->$page);
* _ _ file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
* | |__ ___| |_ __
* | '_ \ / _ \ | '_ \ //move the page on the disk
* | | | | __/ | |_) | rename("$page.md", "$new_name.md");
* |_| |_|\___|_| .__/
* %help% |_| exit(renderpage("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>"));
*/ break;
/*
* _ _
* | |__ ___| |_ __
* | '_ \ / _ \ | '_ \
* | | | | __/ | |_) |
* |_| |_|\___|_| .__/
* %help% |_|
*/
case "help": case "help":
$title = "Help - $sitename"; $title = "Help - $sitename";
$content = " <h1>$sitename Help</h1> $content = " <h1>$sitename Help</h1>
@ -747,14 +763,14 @@ switch($_GET["action"])
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
/* /*
* _ _ * _ _
* | | ___ __ _(_)_ __ * | | ___ __ _(_)_ __
* | |/ _ \ / _` | | '_ \ * | |/ _ \ / _` | | '_ \
* | | (_) | (_| | | | | | * | | (_) | (_| | | | | |
* |_|\___/ \__, |_|_| |_| * |_|\___/ \__, |_|_| |_|
* |___/ %login% * |___/ %login%
*/ */
case "login": case "login":
$title = "Login to $sitename"; $title = "Login to $sitename";
$content = "<h1>Login to $sitename</h1>\n"; $content = "<h1>Login to $sitename</h1>\n";
@ -770,14 +786,14 @@ switch($_GET["action"])
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
/* /*
* _ _ _ _ * _ _ _ _
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __ * ___| |__ ___ ___| | _| | ___ __ _(_)_ __
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \ * / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
* | (__| | | | __/ (__| <| | (_) | (_| | | | | | * | (__| | | | __/ (__| <| | (_) | (_| | | | | |
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_| * \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
* %checklogin% |___/ * %checklogin% |___/
*/ */
case "checklogin": case "checklogin":
if(isset($_POST["user"]) and isset($_POST["pass"])) if(isset($_POST["user"]) and isset($_POST["pass"]))
{ {
@ -813,14 +829,14 @@ switch($_GET["action"])
} }
break; break;
/* /*
* _ _ * _ _
* | | ___ __ _ ___ _ _| |_ * | | ___ __ _ ___ _ _| |_
* | |/ _ \ / _` |/ _ \| | | | __| * | |/ _ \ / _` |/ _ \| | | | __|
* | | (_) | (_| | (_) | |_| | |_ * | | (_) | (_| | (_) | |_| | |_
* |_|\___/ \__, |\___/ \__,_|\__| * |_|\___/ \__, |\___/ \__,_|\__|
* |___/ %logout% * |___/ %logout%
*/ */
case "logout": case "logout":
$isloggedin = false; $isloggedin = false;
unset($user); unset($user);
@ -831,14 +847,14 @@ switch($_GET["action"])
<p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>")); <p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>"));
break; break;
/* /*
* _ _ _ * _ _ _
* ___ _ __ ___ __| (_) |_ ___ * ___ _ __ ___ __| (_) |_ ___
* / __| '__/ _ \/ _` | | __/ __| * / __| '__/ _ \/ _` | | __/ __|
* | (__| | | __/ (_| | | |_\__ \ * | (__| | | __/ (_| | | |_\__ \
* \___|_| \___|\__,_|_|\__|___/ * \___|_| \___|\__,_|_|\__|___/
* %credits% * %credits%
*/ */
case "credits": case "credits":
$title = "Credits - $sitename"; $title = "Credits - $sitename";
$content = "<h1>$sitename credits</h1> $content = "<h1>$sitename credits</h1>
@ -848,14 +864,14 @@ switch($_GET["action"])
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
/* /*
* _ _ * _ _
* | |__ __ _ ___| |__ * | |__ __ _ ___| |__
* | '_ \ / _` / __| '_ \ * | '_ \ / _` / __| '_ \
* | | | | (_| \__ \ | | | * | | | | (_| \__ \ | | |
* |_| |_|\__,_|___/_| |_| * |_| |_|\__,_|___/_| |_|
* %hash% * %hash%
*/ */
case "hash": case "hash":
if(!isset($_GET["string"])) if(!isset($_GET["string"]))
{ {
@ -869,39 +885,39 @@ switch($_GET["action"])
} }
break; break;
/* /*
* _ * _
* __ _(_) _____ __ * __ _(_) _____ __
* \ \ / / |/ _ \ \ /\ / / * \ \ / / |/ _ \ \ /\ / /
* \ V /| | __/\ V V / * \ V /| | __/\ V V /
* \_/ |_|\___| \_/\_/ * \_/ |_|\___| \_/\_/
* %view% * %view%
*/ */
case "view": case "view":
default: default:
//check to make sure that the page exists //check to make sure that the page exists
if(!isset($pageindex->$page)) if(!isset($pageindex->$page))
{ {
if($editing) if($editing)
{ {
//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($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(renderpage("$page - 404 - $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(renderpage("$page - 404 - $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>"));
} }
} }
$title = "$page - $sitename"; $title = "$page - $sitename";
$content = "<h1>$page</h1>"; $content = "<h1>$page</h1>";
$slimdown_start = microtime(true); $slimdown_start = microtime(true);
$content .= Slimdown::render(file_get_contents("$page.md")); $content .= Slimdown::render(file_get_contents("$page.md"));
$content .= "\n\t<!-- Took " . (microtime(true) - $slimdown_start) . " seconds to parse markdown -->\n"; $content .= "\n\t<!-- Took " . (microtime(true) - $slimdown_start) . " seconds to parse markdown -->\n";