mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 05:22:59 +00:00
the new build system is done! Next up: testing.
This commit is contained in:
parent
a05edd6138
commit
0840170750
4 changed files with 1093 additions and 901 deletions
|
@ -1,2 +1,2 @@
|
|||
del index.php
|
||||
php build.old.php
|
||||
php build.php
|
||||
|
|
65
build.php
65
build.php
|
@ -1,3 +1,66 @@
|
|||
<?php
|
||||
exit("The new build system hasn't been written yet!");
|
||||
|
||||
$module_index = json_decode(file_get_contents("module_index.json"));
|
||||
$module_list = [];
|
||||
foreach($module_index as $module)
|
||||
{
|
||||
$module_list[] = $module->id;
|
||||
}
|
||||
|
||||
if(isset($_GET["modules"]))
|
||||
{
|
||||
$module_list = explode(",", $_GET["modules"]);
|
||||
}
|
||||
|
||||
if(php_sapi_name() != "cli")
|
||||
{
|
||||
header("content-type: text/php");
|
||||
}
|
||||
|
||||
$core = file_get_contents("core.php");
|
||||
$settings = file_get_contents("settings.fragment.php");
|
||||
$settings = str_replace([ "<?php", "?>" ], "", $settings);
|
||||
$core = str_replace("{settings}", $settings, $core);
|
||||
|
||||
$result = $core;
|
||||
|
||||
foreach($module_list as $module_id)
|
||||
{
|
||||
if($module_id == "") continue;
|
||||
|
||||
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php";
|
||||
|
||||
//echo("id: $module_id | filepath: $module_filepath\n");
|
||||
|
||||
if(!file_exists($module_filepath))
|
||||
{
|
||||
http_response_code(400);
|
||||
exit("Failed to load module with name: $module_filepath");
|
||||
}
|
||||
|
||||
$modulecode = file_get_contents($module_filepath);
|
||||
$modulecode = str_replace([ "<?php", "?>" ], "", $modulecode);
|
||||
$result = str_replace(
|
||||
"// %next_module% //",
|
||||
"$modulecode\n// %next_module% //",
|
||||
$result);
|
||||
}
|
||||
|
||||
if(php_sapi_name() == "cli")
|
||||
{
|
||||
if(file_exists("index.php"))
|
||||
{
|
||||
echo("index.php already exists, exiting");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
file_put_contents("index.php", $result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit($result);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
checkboxes = document.querySelectorAll("input[type=checkbox]");
|
||||
for(var i = 0; i < checkboxes.length; i++)
|
||||
{
|
||||
url += encodeURIComponent(checkboxes[i].id);
|
||||
url += encodeURIComponent(checkboxes[i].id) + ",";
|
||||
}
|
||||
location.href = url;
|
||||
}
|
||||
|
|
643
index.php
Executable file → Normal file
643
index.php
Executable file → Normal file
|
@ -41,6 +41,9 @@ $settings->anonedits = false;
|
|||
// the name of the page that will act as the home page for the wiki. This page will be served if the user didn't specify a page.
|
||||
$settings->defaultpage = "Main Page";
|
||||
|
||||
// the default action. This action will be performed if no other action is specified.
|
||||
$settings->defaultaction = "view";
|
||||
|
||||
// usernames and passwords - passwords should be hashed with sha256
|
||||
$settings->users = [
|
||||
"admin" => "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", //password
|
||||
|
@ -127,6 +130,7 @@ Actions:
|
|||
*/
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////// Do not edit below this line unless you know what you are doing! ///////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -243,7 +247,7 @@ function hide_email($str)
|
|||
if(!isset($_GET["action"]) and !isset($_GET["page"]))
|
||||
{
|
||||
http_response_code(302);
|
||||
header("location: index.php?action=view&page=$defaultpage");
|
||||
header("location: index.php?action=$settings->defaultaction&page=$defaultpage");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -503,17 +507,141 @@ function human_time_since($time)
|
|||
}
|
||||
///////////////////////////////////////////
|
||||
|
||||
switch($_GET["action"])
|
||||
//////////////////////////
|
||||
/// Module functions ///
|
||||
//////////////////////////
|
||||
// These functions are //
|
||||
// used by modules to //
|
||||
// register themselves //
|
||||
// or new pages. //
|
||||
//////////////////////////
|
||||
$modules = []; // list that contains all the loaded modules
|
||||
// function to register a module
|
||||
function register_module($moduledata)
|
||||
{
|
||||
$modules[] = $moduledata;
|
||||
}
|
||||
|
||||
// function to register an action handler
|
||||
$actions = new stdClass();
|
||||
function add_action($action_name, $func)
|
||||
{
|
||||
$actions->$action_name = $func;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Password hashing action",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Adds a utility action (that anyone can use) called hash that hashes a given string. Useful when changing a user's password.",
|
||||
"id" => "action-hash",
|
||||
"code" => function() {
|
||||
add_action("hash", function() {
|
||||
if(!isset($_GET["string"]))
|
||||
{
|
||||
http_response_code(422);
|
||||
exit(renderpage("Missing parameter", "<p>The <code>GET</code> parameter <code>string</code> must be specified.</p>
|
||||
<p>It is strongly recommended that you utilise this page via a private or incognito window in order to prevent your password from appearing in your browser history.</p>"));
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(renderpage("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
|
||||
}
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Credits",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Adds the credits page. You *must* have this module :D",
|
||||
"id" => "page-credits",
|
||||
"code" => function() {
|
||||
add_action("credits", function() {
|
||||
global $settings, $version;
|
||||
|
||||
$title = "Credits - $settings->sitename";
|
||||
$content = "<h1>$settings->sitename credits</h1>
|
||||
<p>$settings->sitename is powered by Pepperminty Wiki - an entire wiki packed inside a single file, which was built by <a href='//starbeamrainboowlabs.com'>Starbeamrainbowlabs</a>, and can be found <a href='//github.com/sbrl/Pepperminty-Wiki/'>on github</a> (contributors will ablso be listed here in the future).</p>
|
||||
<p>A slightly modified version of slimdown is used to parse text source into HTML. Slimdown is by <a href='https://github.com/jbroadway'>Johnny Broadway</a>, which can be found <a href='https://gist.github.com/jbroadway/2836900'>on github</a>.</p>
|
||||
<p>The default favicon is from <a href='//openclipart.org'>Open Clipart</a> by bluefrog23, and can be found <a href='https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23'>here</a>.</p>
|
||||
<p>Administrators can update $settings->sitename here: <a href='?action=update'>Update $settings->sitename</a>.</p>
|
||||
<p>$settings->sitename is currently running on Pepperminty Wiki <code>$version</code></p>";
|
||||
exit(renderpage($title, $content));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Page deleter",
|
||||
"version" => "0.4",
|
||||
"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;
|
||||
if(!$settings->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)
|
||||
{
|
||||
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>"));
|
||||
}
|
||||
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
|
||||
{
|
||||
exit(renderpage("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>"));
|
||||
}
|
||||
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 - $settings->sitename", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Page editor",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
||||
"id" => "page-edit",
|
||||
|
||||
"code" => function() {
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
*/
|
||||
case "edit":
|
||||
add_action("edit", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin;
|
||||
|
||||
$filename = "$page.md";
|
||||
$creatingpage = !isset($pageindex->$page);
|
||||
if((isset($_GET["newpage"]) and $_GET["newpage"] == "true") or $creatingpage)
|
||||
|
@ -555,17 +683,19 @@ switch($_GET["action"])
|
|||
<input type='submit' value='Save Page' />
|
||||
</form>";
|
||||
exit(renderpage("$title - $settings->sitename", $content));
|
||||
break;
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* ___ __ ___ _____
|
||||
* / __|/ _` \ \ / / _ \
|
||||
* \__ \ (_| |\ V / __/
|
||||
* |___/\__,_| \_/ \___|
|
||||
* %save%
|
||||
* _ _ _
|
||||
* ___ __| (_) |_
|
||||
* / _ \/ _` | | __|
|
||||
* | __/ (_| | | |_
|
||||
* \___|\__,_|_|\__|
|
||||
* %edit%
|
||||
*/
|
||||
case "save":
|
||||
add_action("save", function() {
|
||||
global $pageindex, $settings, $page, $isloggedin, $user;
|
||||
if(!$settings->editing)
|
||||
{
|
||||
header("location: index.php?page=$page");
|
||||
|
@ -614,17 +744,71 @@ switch($_GET["action"])
|
|||
exit(renderpage("Error saving page - $settings->sitename", "<p>$settings->sitename failed to write your changes to the disk. Your changes have not been saved, but you might be able to recover your edit by pressing the back button in your browser.</p>
|
||||
<p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
|
||||
}
|
||||
break;
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* | (_)___| |_
|
||||
* | | / __| __|
|
||||
* | | \__ \ |_
|
||||
* |_|_|___/\__|
|
||||
* %list%
|
||||
*/
|
||||
case "list":
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Help page",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Adds the help action. You really want this one.",
|
||||
"id" => "page-help",
|
||||
"code" => function() {
|
||||
add_action("help", function() {
|
||||
global $settings, $version;
|
||||
|
||||
$title = "Help - $settings->sitename";
|
||||
$content = " <h1>$settings->sitename Help</h1>
|
||||
<p>Welcome to $settings->sitename!</p>
|
||||
<p>$settings->sitename is powered by Pepperminty wiki, a complete wiki in a box you can drop into your server.</p>
|
||||
<h2>Navigating</h2>
|
||||
<p>All the navigation links can be found in the top right corner, along with a box in which you can type a page name and hit enter to be taken to that page (if your site administrator has enabled it).</p>
|
||||
<p>In order to edit pages on $settings->sitename, you probably need to be logged in. If you do not already have an account you will need to ask $settings->sitename's administrator for an account since there is not registration form. Note that the $settings->sitename's administrator may have changed these settings to allow anonymous edits.</p>
|
||||
<h2>Editing</h2>
|
||||
<p>$settings->sitename's editor uses a modified version of slimdown, a flavour of markdown that is implementated using regular expressions. See the credits page for more information and links to the original source for this. A quick reference can be found below:</p>
|
||||
<table>
|
||||
<tr><th>Type This</th><th>To get this</th>
|
||||
<tr><td><code>_italics_</code></td><td><em>italics</em></td></tr>
|
||||
<tr><td><code>*bold*</code></td><td><strong>bold</strong></td></tr>
|
||||
<tr><td><code># Heading</code></td><td><h2>Heading</h2></td></tr>
|
||||
<tr><td><code>## Sub Heading</code></td><td><h3>Sub Heading</h3></td></tr>
|
||||
<tr><td><code>[[Internal Link]]</code></td><td><a href='index.php?page=Internal Link'>Internal Link</a></td></tr>
|
||||
<tr><td><code>[[Display Text|Internal Link]]</code></td><td><a href='index.php?page=Internal Link'>Display Text</a></td></tr>
|
||||
<tr><td><code>[Display text](//google.com/)</code></td><td><a href='//google.com/'>Display Text</a></td></tr>
|
||||
<tr><td><code>~~Strikethrough~~</code></td><td><del>Strikethough</del></td></tr>
|
||||
<tr><td><code>> Blockquote<br />> Some text</code></td><td><blockquote> Blockquote<br />Some text</td></tr>
|
||||
<tr><td><code>
|
||||
---
|
||||
</code></td><td><hr /></td></tr>
|
||||
<tr><tds><code> - One
|
||||
- Two
|
||||
- Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>
|
||||
</table>
|
||||
<h2>Administrator Actions</h2>
|
||||
<p>By default, the <code>delete</code> and <code>move</code> actions are shown on the nav bar. These can be used by administrators to delete or move pages.</p>
|
||||
<p>The other thing admininistrators can do is update the wiki (provided they know the site's secret). This page can be found here: <a href='?action=update'>Update $settings->sitename</a>.</p>
|
||||
<p>$settings->sitename is currently running on Pepperminty Wiki <code>$version</code></p>";
|
||||
exit(renderpage($title, $content));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Page list",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"description" => "Adds a page that lists all the pages in the index long with their metadata.",
|
||||
"id" => "page-list",
|
||||
"code" => function() {
|
||||
add_action("list", function() {
|
||||
global $pageindex, $settings;
|
||||
$title = "All Pages";
|
||||
$content = " <h1>$title on $settings->sitename</h1>
|
||||
<table>
|
||||
|
@ -646,51 +830,129 @@ switch($_GET["action"])
|
|||
}
|
||||
$content .= " </table>";
|
||||
exit(renderpage("$title - $settings->sitename", $content));
|
||||
break;
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Login",
|
||||
"version" => "0.4",
|
||||
"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",
|
||||
"code" => function() {
|
||||
/*
|
||||
* _ _
|
||||
* | | ___ __ _(_)_ __
|
||||
* | |/ _ \ / _` | | '_ \
|
||||
* | | (_) | (_| | | | | |
|
||||
* |_|\___/ \__, |_|_| |_|
|
||||
* |___/ %login%
|
||||
*/
|
||||
add_action("login", function() {
|
||||
global $settings;
|
||||
$title = "Login to $settings->sitename";
|
||||
$content = "<h1>Login to $settings->sitename</h1>\n";
|
||||
if(isset($_GET["failed"]))
|
||||
$content .= "\t\t<p><em>Login failed.</em></p>\n";
|
||||
$content .= "\t\t<form method='post' action='index.php?action=checklogin&returnto=" . rawurlencode($_SERVER['REQUEST_URI']) . "'><label for='user'>Username:</label>
|
||||
<input type='text' name='user' />
|
||||
<br />
|
||||
<label for='pass'>Password:</label>
|
||||
<input type='password' name='pass' />
|
||||
<input type='submit' value='Login' />
|
||||
</form>";
|
||||
exit(renderpage($title, $content));
|
||||
});
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* __| | ___| | ___| |_ ___
|
||||
* / _` |/ _ \ |/ _ \ __/ _ \
|
||||
* | (_| | __/ | __/ || __/
|
||||
* \__,_|\___|_|\___|\__\___|
|
||||
* %delete%
|
||||
* _ _ _ _
|
||||
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __
|
||||
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
|
||||
* | (__| | | | __/ (__| <| | (_) | (_| | | | | |
|
||||
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
|
||||
* %checklogin% |___/
|
||||
*/
|
||||
case "delete":
|
||||
if(!$settings->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)
|
||||
{
|
||||
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>"));
|
||||
}
|
||||
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
|
||||
{
|
||||
exit(renderpage("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>"));
|
||||
}
|
||||
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
|
||||
add_action("checklogin", function() {
|
||||
global $settings;
|
||||
|
||||
exit(renderpage("Deleting $page - $settings->sitename", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
|
||||
break;
|
||||
//actually do the login
|
||||
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
||||
{
|
||||
//the user wants to log in
|
||||
$user = $_POST["user"];
|
||||
$pass = $_POST["pass"];
|
||||
if($settings->users[$user] == hash("sha256", $pass))
|
||||
{
|
||||
$isloggedin = true;
|
||||
$expiretime = time() + 60*60*24*30; //30 days from now
|
||||
$_SESSION["$settings->sessionprefix-user"] = $user;
|
||||
$_SESSION["$settings->sessionprefix-pass"] = hash("sha256", $pass);
|
||||
$_SESSION["$settings->sessionprefix-expiretime"] = $expiretime;
|
||||
//redirect to wherever the user was going
|
||||
http_response_code(302);
|
||||
if(isset($_POST["goto"]))
|
||||
header("location: " . $_POST["returnto"]);
|
||||
else
|
||||
header("location: index.php");
|
||||
exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(302);
|
||||
header("location: index.php?action=login&failed=yes");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(302);
|
||||
header("location: index.php?action=login&failed=yes&badrequest=yes");
|
||||
exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
/*
|
||||
* __ __
|
||||
* | \/ | _____ _____
|
||||
* | |\/| |/ _ \ \ / / _ \
|
||||
* | | | | (_) \ V / __/
|
||||
* |_| |_|\___/ \_/ \___|
|
||||
* %move%
|
||||
*/
|
||||
case "move":
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Logout",
|
||||
"version" => "0.4",
|
||||
"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);
|
||||
//clear the session variables
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
exit(renderpage("Logout Successful", "<h1>Logout Successful</h1>
|
||||
<p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>"));
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Page mover",
|
||||
"version" => "0.4",
|
||||
"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;
|
||||
if(!$settings->editing)
|
||||
{
|
||||
exit(renderpage("Moving $page - error", "<p>You tried to move $page, but editing is disabled on this wiki.</p>
|
||||
|
@ -741,167 +1003,23 @@ switch($_GET["action"])
|
|||
rename("$page.md", "$new_name.md");
|
||||
|
||||
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":
|
||||
$title = "Help - $settings->sitename";
|
||||
$content = " <h1>$settings->sitename Help</h1>
|
||||
<p>Welcome to $settings->sitename!</p>
|
||||
<p>$settings->sitename is powered by Pepperminty wiki, a complete wiki in a box you can drop into your server.</p>
|
||||
<h2>Navigating</h2>
|
||||
<p>All the navigation links can be found in the top right corner, along with a box in which you can type a page name and hit enter to be taken to that page (if your site administrator has enabled it).</p>
|
||||
<p>In order to edit pages on $settings->sitename, you probably need to be logged in. If you do not already have an account you will need to ask $settings->sitename's administrator for an account since there is not registration form. Note that the $settings->sitename's administrator may have changed these settings to allow anonymous edits.</p>
|
||||
<h2>Editing</h2>
|
||||
<p>$settings->sitename's editor uses a modified version of slimdown, a flavour of markdown that is implementated using regular expressions. See the credits page for more information and links to the original source for this. A quick reference can be found below:</p>
|
||||
<table>
|
||||
<tr><th>Type This</th><th>To get this</th>
|
||||
<tr><td><code>_italics_</code></td><td><em>italics</em></td></tr>
|
||||
<tr><td><code>*bold*</code></td><td><strong>bold</strong></td></tr>
|
||||
<tr><td><code># Heading</code></td><td><h2>Heading</h2></td></tr>
|
||||
<tr><td><code>## Sub Heading</code></td><td><h3>Sub Heading</h3></td></tr>
|
||||
<tr><td><code>[[Internal Link]]</code></td><td><a href='index.php?page=Internal Link'>Internal Link</a></td></tr>
|
||||
<tr><td><code>[[Display Text|Internal Link]]</code></td><td><a href='index.php?page=Internal Link'>Display Text</a></td></tr>
|
||||
<tr><td><code>[Display text](//google.com/)</code></td><td><a href='//google.com/'>Display Text</a></td></tr>
|
||||
<tr><td><code>~~Strikethrough~~</code></td><td><del>Strikethough</del></td></tr>
|
||||
<tr><td><code>> Blockquote<br />> Some text</code></td><td><blockquote> Blockquote<br />Some text</td></tr>
|
||||
<tr><td><code>
|
||||
---
|
||||
</code></td><td><hr /></td></tr>
|
||||
<tr><tds><code> - One
|
||||
- Two
|
||||
- Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>
|
||||
</table>
|
||||
<h2>Administrator Actions</h2>
|
||||
<p>By default, the <code>delete</code> and <code>move</code> actions are shown on the nav bar. These can be used by administrators to delete or move pages.</p>
|
||||
<p>The other thing admininistrators can do is update the wiki (provided they know the site's secret). This page can be found here: <a href='?action=update'>Update $settings->sitename</a>.</p>
|
||||
<p>$settings->sitename is currently running on Pepperminty Wiki <code>$version</code></p>";
|
||||
exit(renderpage($title, $content));
|
||||
break;
|
||||
|
||||
/*
|
||||
* _ _
|
||||
* | | ___ __ _(_)_ __
|
||||
* | |/ _ \ / _` | | '_ \
|
||||
* | | (_) | (_| | | | | |
|
||||
* |_|\___/ \__, |_|_| |_|
|
||||
* |___/ %login%
|
||||
*/
|
||||
case "login":
|
||||
$title = "Login to $settings->sitename";
|
||||
$content = "<h1>Login to $settings->sitename</h1>\n";
|
||||
if(isset($_GET["failed"]))
|
||||
$content .= "\t\t<p><em>Login failed.</em></p>\n";
|
||||
$content .= "\t\t<form method='post' action='index.php?action=checklogin&returnto=" . rawurlencode($_SERVER['REQUEST_URI']) . "'><label for='user'>Username:</label>
|
||||
<input type='text' name='user' />
|
||||
<br />
|
||||
<label for='pass'>Password:</label>
|
||||
<input type='password' name='pass' />
|
||||
<input type='submit' value='Login' />
|
||||
</form>";
|
||||
exit(renderpage($title, $content));
|
||||
break;
|
||||
|
||||
/*
|
||||
* _ _ _ _
|
||||
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __
|
||||
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
|
||||
* | (__| | | | __/ (__| <| | (_) | (_| | | | | |
|
||||
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
|
||||
* %checklogin% |___/
|
||||
*/
|
||||
case "checklogin":
|
||||
//actually do the login
|
||||
if(isset($_POST["user"]) and isset($_POST["pass"]))
|
||||
{
|
||||
//the user wants to log in
|
||||
$user = $_POST["user"];
|
||||
$pass = $_POST["pass"];
|
||||
if($settings->users[$user] == hash("sha256", $pass))
|
||||
{
|
||||
$isloggedin = true;
|
||||
$expiretime = time() + 60*60*24*30; //30 days from now
|
||||
$_SESSION["$settings->sessionprefix-user"] = $user;
|
||||
$_SESSION["$settings->sessionprefix-pass"] = hash("sha256", $pass);
|
||||
$_SESSION["$settings->sessionprefix-expiretime"] = $expiretime;
|
||||
//redirect to wherever the user was going
|
||||
http_response_code(302);
|
||||
if(isset($_POST["goto"]))
|
||||
header("location: " . $_POST["returnto"]);
|
||||
else
|
||||
header("location: index.php");
|
||||
exit();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(302);
|
||||
header("location: index.php?action=login&failed=yes");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(302);
|
||||
header("location: index.php?action=login&failed=yes&badrequest=yes");
|
||||
exit();
|
||||
}
|
||||
break;
|
||||
]);
|
||||
|
||||
/*
|
||||
* _ _
|
||||
* | | ___ __ _ ___ _ _| |_
|
||||
* | |/ _ \ / _` |/ _ \| | | | __|
|
||||
* | | (_) | (_| | (_) | |_| | |_
|
||||
* |_|\___/ \__, |\___/ \__,_|\__|
|
||||
* |___/ %logout%
|
||||
*/
|
||||
case "logout":
|
||||
$isloggedin = false;
|
||||
unset($user);
|
||||
unset($pass);
|
||||
//clear the session variables
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
|
||||
exit(renderpage("Logout Successful", "<h1>Logout Successful</h1>
|
||||
<p>Logout Successful. You can login again <a href='index.php?action=login'>here</a>.</p>"));
|
||||
break;
|
||||
|
||||
/*
|
||||
* _ _ _
|
||||
* ___ _ __ ___ __| (_) |_ ___
|
||||
* / __| '__/ _ \/ _` | | __/ __|
|
||||
* | (__| | | __/ (_| | | |_\__ \
|
||||
* \___|_| \___|\__,_|_|\__|___/
|
||||
* %credits%
|
||||
*/
|
||||
case "credits":
|
||||
$title = "Credits - $settings->sitename";
|
||||
$content = "<h1>$settings->sitename credits</h1>
|
||||
<p>$settings->sitename is powered by Pepperminty Wiki - an entire wiki packed inside a single file, which was built by <a href='//starbeamrainboowlabs.com'>Starbeamrainbowlabs</a>, and can be found <a href='//github.com/sbrl/Pepperminty-Wiki/'>on github</a>.</p>
|
||||
<p>A slightly modified version of slimdown is used to parse text source into HTML. Slimdown is by <a href='https://github.com/jbroadway'>Johnny Broadway</a>, which can be found <a href='https://gist.github.com/jbroadway/2836900'>on github</a>.</p>
|
||||
<p>The default favicon is from <a href='//openclipart.org'>Open Clipart</a> by bluefrog23, and can be found <a href='https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23'>here</a>.</p>
|
||||
<p>Administrators can update $settings->sitename here: <a href='?action=update'>Update $settings->sitename</a>.</p>
|
||||
<p>$settings->sitename is currently running on Pepperminty Wiki <code>$version</code></p>";
|
||||
exit(renderpage($title, $content));
|
||||
break;
|
||||
register_module([
|
||||
"name" => "Update",
|
||||
"version" => "0.4",
|
||||
"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;
|
||||
|
||||
/*
|
||||
* _ _
|
||||
* _ _ _ __ __| |__ _| |_ ___
|
||||
* | || | '_ \/ _` / _` | _/ -_)
|
||||
* \_,_| .__/\__,_\__,_|\__\___|
|
||||
* |_| %update%
|
||||
*/
|
||||
case "update":
|
||||
if(!$settings->isadmin)
|
||||
if(!$isadmin)
|
||||
{
|
||||
http_response_code(401);
|
||||
exit(renderpage("Update - Error", "<p>You must be an administrator to do that.</p>"));
|
||||
|
@ -934,7 +1052,7 @@ switch($_GET["action"])
|
|||
$log .= "I am <code>" . __FILE__ . "</code>.\n";
|
||||
$oldcode = file_get_contents(__FILE__);
|
||||
$log .= "Fetching new code...";
|
||||
$newcode = file_get_contents($updateurl);
|
||||
$newcode = file_get_contents($settings->updateurl);
|
||||
$log .= "done.\n";
|
||||
|
||||
$log .= "Rewriting <code>" . __FILE__ . "</code>...";
|
||||
|
@ -951,40 +1069,22 @@ switch($_GET["action"])
|
|||
$log .= "The version number that I have updated to can be found on the credits or help ages.";
|
||||
|
||||
exit(renderpage("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>"));
|
||||
|
||||
break;
|
||||
|
||||
/*
|
||||
* _ _
|
||||
* | |__ __ _ ___| |__
|
||||
* | '_ \ / _` / __| '_ \
|
||||
* | | | | (_| \__ \ | | |
|
||||
* |_| |_|\__,_|___/_| |_|
|
||||
* %hash%
|
||||
*/
|
||||
case "hash":
|
||||
if(!isset($_GET["string"]))
|
||||
{
|
||||
http_response_code(400);
|
||||
exit(renderpage("Bad request", "<p>The <code>GET</code> parameter <code>string</code> must be specified.</p>
|
||||
<p>It is strongly recommended that you utilise this page via a private or incognito window in order to prevent your password from appearing in your browser history.</p>"));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(renderpage("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
|
||||
}
|
||||
break;
|
||||
]);
|
||||
|
||||
|
||||
|
||||
register_module([
|
||||
"name" => "Page viewer",
|
||||
"version" => "0.4",
|
||||
"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;
|
||||
|
||||
/*
|
||||
* _
|
||||
* __ _(_) _____ __
|
||||
* \ \ / / |/ _ \ \ /\ / /
|
||||
* \ V /| | __/\ V V /
|
||||
* \_/ |_|\___| \_/\_/
|
||||
* %view%
|
||||
*/
|
||||
case "view":
|
||||
default:
|
||||
//check to make sure that the page exists
|
||||
if(!isset($pageindex->$page))
|
||||
{
|
||||
|
@ -1017,6 +1117,35 @@ switch($_GET["action"])
|
|||
else
|
||||
$minimal = false;
|
||||
exit(renderpage($title, $content, $minimal));
|
||||
break;
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
// %next_module% //
|
||||
|
||||
|
||||
// execute each module's code
|
||||
foreach($modules as $moduledata)
|
||||
{
|
||||
$moduledata["code"]();
|
||||
}
|
||||
// make sure that the credits page exists
|
||||
if(!isset($actions["credits"]))
|
||||
{
|
||||
exit(renderpage("Error - $settings->$sitename", "<p>No credits page detected. The credits page is a required module!</p>"))
|
||||
}
|
||||
|
||||
// Perform the appropriate action
|
||||
if(isset($actions[strtolower($_GET["action"])]))
|
||||
{
|
||||
$req_action = strtolower($_GET["action"]);
|
||||
$req_action_data = $action_name->$req_action;
|
||||
$req_action_data["code"]();
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(renderpage("Error - $settings->sitename", ",p>No action called " . strtolower($_GET["action"]) ." has been registered. Perhaps you are missing a module?</p>"));
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue