Erm what's happening here...?

This commit is contained in:
Starbeamrainbowlabs 2015-09-19 10:19:56 +01:00
parent 3fe38f5d86
commit e465a05083
23 changed files with 3450 additions and 3450 deletions

14
.gitignore vendored
View File

@ -1,7 +1,7 @@
# all wiki pages # all wiki pages
*.md *.md
# include the README # include the README
!README.md !README.md
# the page index # the page index
pageindex.json pageindex.json

178
README.md
View File

@ -1,90 +1,90 @@
# Pepperminty Wiki # Pepperminty Wiki
A Wiki in a box A Wiki in a box
Pepperminty Wiki is a complete wiki contained in a single file, inspired by @am2064's [Minty Wiki](https://github.com/am2064/Minty-Wiki). Pepperminty Wiki is a complete wiki contained in a single file, inspired by @am2064's [Minty Wiki](https://github.com/am2064/Minty-Wiki).
## Screenshots ## Screenshots
![Main Page Example](https://cloud.githubusercontent.com/assets/9929737/9069904/12acfad6-3ae4-11e5-8ec4-6ec0e3de7249.png) ![Main Page Example](https://cloud.githubusercontent.com/assets/9929737/9069904/12acfad6-3ae4-11e5-8ec4-6ec0e3de7249.png)
Above: A Main Page with the sidebar enabled. Above: A Main Page with the sidebar enabled.
## Features ## Features
- Configurable settings - Configurable settings
- User login system - User login system
- Page creation - Page creation
- Sub pages - Sub pages
- Markdown-powered syntax - Markdown-powered syntax
- Internal links - Internal links
- Printable page view - Printable page view
- Customisable theme - Customisable theme
- Basic 'search' bar - Basic 'search' bar
- (Optional) Sidebar with a tree of all the current pages - (Optional) Sidebar with a tree of all the current pages
- List of all pages & details - List of all pages & details
- Inbuilt help page - Inbuilt help page
## Demo ## Demo
A Live demo of the latest stable version can be found over at [my website](//starbeamrainbowlabs.com/labs/peppermint) A Live demo of the latest stable version can be found over at [my website](//starbeamrainbowlabs.com/labs/peppermint)
## Getting Started ## Getting Started
### Requirements ### Requirements
- PHP-enabled webserver - PHP-enabled webserver
- PHP session support (for logging in, see [here](https://php.net/manual/en/session.installation.php) for more information) - PHP session support (for logging in, see [here](https://php.net/manual/en/session.installation.php) for more information)
- Write access to own folder (only for editing) - Write access to own folder (only for editing)
### Getting your own copy ### Getting your own copy
Setting up your own copy of Pepperminty Wiki is easy. Since Pepperminty Wiki works on a module based system, all you need to do is choose the modules you want installed, and then configure your new installation so that it fits your needs. There are several ways to do this: Setting up your own copy of Pepperminty Wiki is easy. Since Pepperminty Wiki works on a module based system, all you need to do is choose the modules you want installed, and then configure your new installation so that it fits your needs. There are several ways to do this:
#### Method 1: Using the latest pre-built stable release #### Method 1: Using the latest pre-built stable release
If you want a pre-built stable version, then you can [use the latest release](https://github.com/sbrl/Pepperminty-Wiki/releases/latest). It has a changelog that tells you what has changed since the last release, along with a pre-built version with all the latest modules. If you want a pre-built stable version, then you can [use the latest release](https://github.com/sbrl/Pepperminty-Wiki/releases/latest). It has a changelog that tells you what has changed since the last release, along with a pre-built version with all the latest modules.
#### Method 2: Grabbing the pre-built verion from the repository #### Method 2: Grabbing the pre-built verion from the repository
If you're feeling lazy, you can grab the bleeding-edge version from this respository, which comes with all the latest modules. You can get it [here](https://raw.githubusercontent.com/sbrl/Pepperminty-Wiki/master/build/index.php). If you're feeling lazy, you can grab the bleeding-edge version from this respository, which comes with all the latest modules. You can get it [here](https://raw.githubusercontent.com/sbrl/Pepperminty-Wiki/master/build/index.php).
#### Method 3: Using the online downloader #### Method 3: Using the online downloader
Pepperminty Wiki has a downloader that you can use to select the modules you want to include in your install. The online downloader will give you the latest stable release. You can find it [here](//starbeamrainbowlabs.com/labs/peppermint/download.php). Pepperminty Wiki has a downloader that you can use to select the modules you want to include in your install. The online downloader will give you the latest stable release. You can find it [here](//starbeamrainbowlabs.com/labs/peppermint/download.php).
#### Method 3.5: Using the downloader offline #### Method 3.5: Using the downloader offline
You can also you the downloader offline. Simply clone this repository to your web server and then point your web browser at `your.server/path/to/perppminty/wiki/download.php`. You can also you the downloader offline. Simply clone this repository to your web server and then point your web browser at `your.server/path/to/perppminty/wiki/download.php`.
#### Method 4: Building your own from source #### Method 4: Building your own from source
Pepperminty Wiki can also be built from source (and I do this all the time when testing). Start by cloning the repository. Then go into the `modules` folder and append `.disabled` to the names of any modules you don't want to be included (e.g. `modules/page-edit.php` would become `modules/page-edit.php.disabled`). Then follow the instructions for your platform: Pepperminty Wiki can also be built from source (and I do this all the time when testing). Start by cloning the repository. Then go into the `modules` folder and append `.disabled` to the names of any modules you don't want to be included (e.g. `modules/page-edit.php` would become `modules/page-edit.php.disabled`). Then follow the instructions for your platform:
##### Windows ##### Windows
Simply run the `build.bat` script in the root of the repository. It will handle everything for you. Simply run the `build.bat` script in the root of the repository. It will handle everything for you.
##### Linux and Everyone Else ##### Linux and Everyone Else
Run the following commands from the root of the repository in order, adjusting them for your specific platform (these are for a standard Ubuntu Server install): Run the following commands from the root of the repository in order, adjusting them for your specific platform (these are for a standard Ubuntu Server install):
```bash ```bash
rm build/index.php rm build/index.php
php rebuild_module_index.php php rebuild_module_index.php
php build.php php build.php
``` ```
Here's an explanation of what each command does: Here's an explanation of what each command does:
1. Deletes the old `index.php` in the build folder that comes with the repository 1. Deletes the old `index.php` in the build folder that comes with the repository
2. Rebuilds the module index that the build scripts uses to determine what modules it should include when building 2. Rebuilds the module index that the build scripts uses to determine what modules it should include when building
3. Actually builds Pepperminty Wiki. Outputs to `index.php`. 3. Actually builds Pepperminty Wiki. Outputs to `index.php`.
### Configuring ### Configuring
To configure your new install, open `index.php` in your favourite text editor and take a look at the comments. They should be self explanatory, but if you need any help, just contact me or [open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new). To configure your new install, open `index.php` in your favourite text editor and take a look at the comments. They should be self explanatory, but if you need any help, just contact me or [open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new).
## Reference ## Reference
At some point (soon I hope!), I am going to write a reference here for those who would like to build their own modules. At some point (soon I hope!), I am going to write a reference here for those who would like to build their own modules.
## Real World Usage ## Real World Usage
None yet! Contact me or [open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new) and tell me about where you are using Pepperminty Wiki and I will add you to this section! None yet! Contact me or [open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new) and tell me about where you are using Pepperminty Wiki and I will add you to this section!
## Todo ## Todo
Here's a list of things that I want to add at some point (please feel free to [send a pull request](//github.com/sbrl/Pepperminty-Wiki/pulls) and help out!). Here's a list of things that I want to add at some point (please feel free to [send a pull request](//github.com/sbrl/Pepperminty-Wiki/pulls) and help out!).
- Page history - Page history
- Password changing - Password changing
- Intelligent auto-updating system that doesn't wipe your settings / module choices - Intelligent auto-updating system that doesn't wipe your settings / module choices
- Make links to non-existent pages red - Make links to non-existent pages red
- Optional module support - Optional module support
- Redirect pages - Redirect pages
- ...? - ...?
Is the feature you want to see not on this list? [Open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new) or [send a pull request](//github.com/sbrl/Pepperminty-Wiki/pulls)! Is the feature you want to see not on this list? [Open an issue](//github.com/sbrl/Pepperminty-Wiki/issues/new) or [send a pull request](//github.com/sbrl/Pepperminty-Wiki/pulls)!

View File

@ -1,5 +1,5 @@
@echo off @echo off
echo Deleting old index.php echo Deleting old index.php
del build\index.php del build\index.php
php rebuild_module_index.php php rebuild_module_index.php
php build.php php build.php

158
build.php
View File

@ -1,79 +1,79 @@
<?php <?php
if(php_sapi_name() == "cli") if(php_sapi_name() == "cli")
{ {
echo("Beginning build...\n"); echo("Beginning build...\n");
echo("Reading in module index...\n"); echo("Reading in module index...\n");
} }
$module_index = json_decode(file_get_contents("module_index.json")); $module_index = json_decode(file_get_contents("module_index.json"));
$module_list = []; $module_list = [];
foreach($module_index as $module) foreach($module_index as $module)
{ {
$module_list[] = $module->id; $module_list[] = $module->id;
} }
if(isset($_GET["modules"])) if(isset($_GET["modules"]))
{ {
$module_list = explode(",", $_GET["modules"]); $module_list = explode(",", $_GET["modules"]);
} }
if(php_sapi_name() != "cli") if(php_sapi_name() != "cli")
{ {
header("content-type: text/php"); header("content-type: text/php");
} }
if(php_sapi_name() == "cli") echo("Reading in core files..."); if(php_sapi_name() == "cli") echo("Reading in core files...");
$core = file_get_contents("core.php"); $core = file_get_contents("core.php");
$settings = file_get_contents("settings.fragment.php"); $settings = file_get_contents("settings.fragment.php");
$settings = str_replace([ "<?php", "?>" ], "", $settings); $settings = str_replace([ "<?php", "?>" ], "", $settings);
$core = str_replace("{settings}", $settings, $core); $core = str_replace("{settings}", $settings, $core);
$result = $core; $result = $core;
foreach($module_list as $module_id) foreach($module_list as $module_id)
{ {
if($module_id == "") continue; if($module_id == "") continue;
if(php_sapi_name() == "cli") echo("Adding $module_id\n"); if(php_sapi_name() == "cli") echo("Adding $module_id\n");
$module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php"; $module_filepath = "modules/" . preg_replace("[^a-zA-Z0-9\-]", "", $module_id) . ".php";
//echo("id: $module_id | filepath: $module_filepath\n"); //echo("id: $module_id | filepath: $module_filepath\n");
if(!file_exists($module_filepath)) if(!file_exists($module_filepath))
{ {
http_response_code(400); http_response_code(400);
exit("Failed to load module with name: $module_filepath"); exit("Failed to load module with name: $module_filepath");
} }
$modulecode = file_get_contents($module_filepath); $modulecode = file_get_contents($module_filepath);
$modulecode = str_replace([ "<?php", "?>" ], "", $modulecode); $modulecode = str_replace([ "<?php", "?>" ], "", $modulecode);
$result = str_replace( $result = str_replace(
"// %next_module% //", "// %next_module% //",
"$modulecode\n// %next_module% //", "$modulecode\n// %next_module% //",
$result); $result);
} }
if(php_sapi_name() == "cli") if(php_sapi_name() == "cli")
{ {
if(file_exists("build/index.php")) if(file_exists("build/index.php"))
{ {
echo("index.php already exists in the build folder, exiting\n"); echo("index.php already exists in the build folder, exiting\n");
exit(1); exit(1);
} }
else else
{ {
echo("Done. Saving to disk..."); echo("Done. Saving to disk...");
file_put_contents("build/index.php", $result); file_put_contents("build/index.php", $result);
echo("complete!\n"); echo("complete!\n");
echo("*** Build Completed ***\n"); echo("*** Build Completed ***\n");
} }
} }
else else
{ {
exit($result); exit($result);
} }
?> ?>

File diff suppressed because it is too large Load Diff

1226
core.php

File diff suppressed because it is too large Load Diff

View File

@ -1,90 +1,90 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Pepperminty Wiki Download</title> <title>Pepperminty Wiki Download</title>
</head> </head>
<body> <body>
<h1>Pepperminty Wiki Download</h1> <h1>Pepperminty Wiki Download</h1>
<!--------------> <!-------------->
<h2>Module selector</h2> <h2>Module selector</h2>
<p>Choose the modules that you want to include in your installation of Pepperminty Wiki.</p> <p>Choose the modules that you want to include in your installation of Pepperminty Wiki.</p>
<p> <p>
<button onclick="select(true);">Select All</button> <button onclick="select(true);">Select All</button>
<button onclick="select(false);">Select None</button> <button onclick="select(false);">Select None</button>
</p> </p>
<table> <table>
<tr> <tr>
<th></th> <th></th>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Author</th> <th>Author</th>
<th>Version</th> <th>Version</th>
<th style="width: 9rem;">Last Updated</th> <th style="width: 9rem;">Last Updated</th>
</tr> </tr>
<?php <?php
$module_index = json_decode(file_get_contents("module_index.json")); $module_index = json_decode(file_get_contents("module_index.json"));
foreach($module_index as $module) foreach($module_index as $module)
{ {
echo("<tr> echo("<tr>
<td><input type='checkbox' id='$module->id' checked /></td> <td><input type='checkbox' id='$module->id' checked /></td>
<td><label for='$module->id'>$module->name</label></td> <td><label for='$module->id'>$module->name</label></td>
<td>$module->description</td> <td>$module->description</td>
<td>$module->author</td> <td>$module->author</td>
<td>$module->version</td> <td>$module->version</td>
<td>" . date("D jS M Y", $module->lastupdate) . "</td> <td>" . date("D jS M Y", $module->lastupdate) . "</td>
</tr>"); </tr>");
} }
?> ?>
</table> </table>
<br /> <br />
<br /> <br />
<button onclick="download()" class="largebutton">Download</button> <button onclick="download()" class="largebutton">Download</button>
<hr /> <hr />
<p> <p>
Pepperminty Wiki was built by <a href="//starbeamrainbowlabs.com/">Starbeamrainbowlabs</a>. The code is available on <a href="//github.com/sbrl/pepperminty-wiki">GitHub</a>. Pepperminty Wiki was built by <a href="//starbeamrainbowlabs.com/">Starbeamrainbowlabs</a>. The code is available on <a href="//github.com/sbrl/pepperminty-wiki">GitHub</a>.
</p> </p>
<p> <p>
Other contributors: (none yet! Contribute and I will put your name here) Other contributors: (none yet! Contribute and I will put your name here)
</p> </p>
<!-------------------> <!------------------->
<link rel="stylesheet" href="//starbeamrainbowlabs.com/theme/basic.css" /> <link rel="stylesheet" href="//starbeamrainbowlabs.com/theme/basic.css" />
<style> <style>
body { padding: 1rem; color: #442772; background-colour: #eee8f2; } /* syntaxtic gets confused sometimes */ body { padding: 1rem; color: #442772; background-colour: #eee8f2; } /* syntaxtic gets confused sometimes */
a { color: #9e7eb4; } a { color: #9e7eb4; }
.largebutton { font-size: 2rem; } .largebutton { font-size: 2rem; }
</style> </style>
<script> <script>
function select(state) function select(state)
{ {
var checkboxes = document.querySelectorAll("input[type=checkbox]"); var checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++) for(var i = 0; i < checkboxes.length; i++)
{ {
checkboxes[i].checked = state; checkboxes[i].checked = state;
} }
} }
function download() function download()
{ {
var url = "build.php?web=true&modules=", var url = "build.php?web=true&modules=",
checkboxes = document.querySelectorAll("input[type=checkbox]"); checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++) for(var i = 0; i < checkboxes.length; i++)
{ {
url += encodeURIComponent(checkboxes[i].id) + ","; url += encodeURIComponent(checkboxes[i].id) + ",";
} }
location.href = url; location.href = url;
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -1,24 +1,24 @@
<?php <?php
register_module([ register_module([
"name" => "Password hashing action", "name" => "Password hashing action",
"version" => "0.5", "version" => "0.5",
"author" => "Starbeamrainbowlabs", "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.", "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", "id" => "action-hash",
"code" => function() { "code" => function() {
add_action("hash", function() { add_action("hash", function() {
if(!isset($_GET["string"])) if(!isset($_GET["string"]))
{ {
http_response_code(422); http_response_code(422);
exit(page_renderer::render_main("Missing parameter", "<p>The <code>GET</code> parameter <code>string</code> must be specified.</p> exit(page_renderer::render_main("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>")); <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 else
{ {
exit(page_renderer::render_main("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>"))); exit(page_renderer::render_main("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
} }
}); });
} }
]); ]);
?> ?>

View File

@ -1,109 +1,109 @@
<?php <?php
register_module([ register_module([
"name" => "Sidebar", "name" => "Sidebar",
"version" => "0.2", "version" => "0.2",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds a sidebar to the left hand side of every page. Add '\$settings->sidebar_show = true;' to your configuration, or append '&sidebar=yes' to the url to enable. Adding to the url sets a cookie to remember your setting.", "description" => "Adds a sidebar to the left hand side of every page. Add '\$settings->sidebar_show = true;' to your configuration, or append '&sidebar=yes' to the url to enable. Adding to the url sets a cookie to remember your setting.",
"id" => "extra-sidebar", "id" => "extra-sidebar",
"code" => function() { "code" => function() {
$show_sidebar = false; $show_sidebar = false;
// Show the sidebar if it is enabled in the settings // Show the sidebar if it is enabled in the settings
if(isset($settings->sidebar_show) && $settings->sidebar_show === true) if(isset($settings->sidebar_show) && $settings->sidebar_show === true)
$show_sidebar = true; $show_sidebar = true;
// Also show and persist the sidebar if the special GET parameter // Also show and persist the sidebar if the special GET parameter
// sidebar is seet // sidebar is seet
if(!$show_sidebar && isset($_GET["sidebar"])) if(!$show_sidebar && isset($_GET["sidebar"]))
{ {
$show_sidebar = true; $show_sidebar = true;
// Set a cookie to persist the display of the sidebar // Set a cookie to persist the display of the sidebar
setcookie("sidebar_show", "true", time() + (60 * 60 * 24 * 30)); setcookie("sidebar_show", "true", time() + (60 * 60 * 24 * 30));
} }
// Show the sidebar if the cookie is set // Show the sidebar if the cookie is set
if(!$show_sidebar && isset($_COOKIE["sidebar_show"])) if(!$show_sidebar && isset($_COOKIE["sidebar_show"]))
$show_sidebar = true; $show_sidebar = true;
// Delete the cookie and hide the sidebar if the special GET paramter // Delete the cookie and hide the sidebar if the special GET paramter
// nosidebar is set // nosidebar is set
if(isset($_GET["nosidebar"])) if(isset($_GET["nosidebar"]))
{ {
$show_sidebar = false; $show_sidebar = false;
unset($_COOKIE["sidebar_show"]); unset($_COOKIE["sidebar_show"]);
setcookie("sidebar_show", null, time() - 3600); setcookie("sidebar_show", null, time() - 3600);
} }
page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) { page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) {
global $settings, $pageindex; global $settings, $pageindex;
if($show_sidebar && !isset($_GET["printable"])) if($show_sidebar && !isset($_GET["printable"]))
{ {
// Show the sidebar // Show the sidebar
$exec_start = microtime(true); $exec_start = microtime(true);
// Sort the pageindex // Sort the pageindex
$sorted_pageindex = get_object_vars($pageindex); $sorted_pageindex = get_object_vars($pageindex);
ksort($sorted_pageindex, SORT_NATURAL); ksort($sorted_pageindex, SORT_NATURAL);
$sidebar_contents = ""; $sidebar_contents = "";
$sidebar_contents .= render_sidebar($sorted_pageindex); $sidebar_contents .= render_sidebar($sorted_pageindex);
$parts["{body}"] = "<aside class='sidebar'> $parts["{body}"] = "<aside class='sidebar'>
$sidebar_contents $sidebar_contents
<!-- Sidebar rendered in " . (microtime(true) - $exec_start) . "s --> <!-- Sidebar rendered in " . (microtime(true) - $exec_start) . "s -->
</aside> </aside>
<div class='main-container'>" . $parts["{body}"] . "</div> <div class='main-container'>" . $parts["{body}"] . "</div>
<!--------------> <!-------------->
<style> <style>
body { display: flex; } body { display: flex; }
.main-container { flex: 1; } .main-container { flex: 1; }
</style>"; </style>";
} }
}); });
} }
]); ]);
/* /*
* @summary Renders the sidebar for a given pageindex. * @summary Renders the sidebar for a given pageindex.
* *
* @param $pageindex {array} - The pageindex to render the sidebar for * @param $pageindex {array} - The pageindex to render the sidebar for
* @param $root_pagename {string} - The pagename that should be considered the root of the rendering. You don't usually need to use this, it is used by the algorithm itself since it is recursive. * @param $root_pagename {string} - The pagename that should be considered the root of the rendering. You don't usually need to use this, it is used by the algorithm itself since it is recursive.
* *
* @returns {string} A HTML rendering of the sidebar for the given pageindex * @returns {string} A HTML rendering of the sidebar for the given pageindex
*/ */
function render_sidebar($pageindex, $root_pagename = "") function render_sidebar($pageindex, $root_pagename = "")
{ {
global $settings; global $settings;
$result = "<ul"; $result = "<ul";
// If this is the very root of the tree, add an extra class to it // If this is the very root of the tree, add an extra class to it
if($root_pagename == "") $result .= " class='sidebar-tree'"; if($root_pagename == "") $result .= " class='sidebar-tree'";
$result .=">"; $result .=">";
foreach ($pageindex as $pagename => $details) foreach ($pageindex as $pagename => $details)
{ {
// If we have a valid root pagename, and it isn't present at the // If we have a valid root pagename, and it isn't present at the
// beginning of the current pagename, skip it // beginning of the current pagename, skip it
if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0) if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0)
continue; continue;
// The current page is the same as the root page, skip it // The current page is the same as the root page, skip it
if($pagename == $root_pagename) if($pagename == $root_pagename)
continue; continue;
// If the part of the current pagename that comes after the root // If the part of the current pagename that comes after the root
// pagename has a slash in it, skip it as it is a sub-sub page. // pagename has a slash in it, skip it as it is a sub-sub page.
if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false) if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false)
continue; continue;
$result .= "<li><a href='?action=$settings->defaultaction&page=$pagename'>$pagename</a>\n"; $result .= "<li><a href='?action=$settings->defaultaction&page=$pagename'>$pagename</a>\n";
$result .= render_sidebar($pageindex, $pagename); $result .= render_sidebar($pageindex, $pagename);
$result .= "</li>\n"; $result .= "</li>\n";
} }
$result .= "</ul>\n"; $result .= "</ul>\n";
return $result == "<ul></ul>\n" ? "" : $result; return $result == "<ul></ul>\n" ? "" : $result;
} }
?> ?>

View File

@ -1,61 +1,61 @@
<?php <?php
register_module([ register_module([
"name" => "Credits", "name" => "Credits",
"version" => "0.6", "version" => "0.6",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds the credits page. You *must* have this module :D", "description" => "Adds the credits page. You *must* have this module :D",
"id" => "page-credits", "id" => "page-credits",
"code" => function() { "code" => function() {
add_action("credits", function() { add_action("credits", function() {
global $settings, $version, $pageindex, $modules; global $settings, $version, $pageindex, $modules;
$credits = [ $credits = [
"Code" => [ "Code" => [
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"author_url" => "https://starbeamrmainbowlabs.com/", "author_url" => "https://starbeamrmainbowlabs.com/",
"thing_url" => "https://github.com/sbrl/Pepprminty-Wiki" "thing_url" => "https://github.com/sbrl/Pepprminty-Wiki"
], ],
"Slightly modified version of Slimdown" => [ "Slightly modified version of Slimdown" => [
"author" => "Johnny Broadway", "author" => "Johnny Broadway",
"author_url" => "https://github.com/jbroadway", "author_url" => "https://github.com/jbroadway",
"thing_url" => "https://gist.github.com/jbroadway/2836900" "thing_url" => "https://gist.github.com/jbroadway/2836900"
], ],
"Default Favicon" => [ "Default Favicon" => [
"author" => "bluefrog23", "author" => "bluefrog23",
"author_url" => "https://openclipart.org/user-detail/bluefrog23/", "author_url" => "https://openclipart.org/user-detail/bluefrog23/",
"thing_url" => "https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23" "thing_url" => "https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23"
], ],
"Bug Reports" => [ "Bug Reports" => [
"author" => "nibreh", "author" => "nibreh",
"author_url" => "https://github.com/nibreh/", "author_url" => "https://github.com/nibreh/",
"thing_url" => "" "thing_url" => ""
] ]
]; ];
$credits_html = "<ul>\n"; $credits_html = "<ul>\n";
foreach($credits as $thing => $author_details) foreach($credits as $thing => $author_details)
{ {
$credits_html .= " <li>"; $credits_html .= " <li>";
$credits_html .= "<a href='" . $author_details["thing_url"] . "'>$thing</a> by "; $credits_html .= "<a href='" . $author_details["thing_url"] . "'>$thing</a> by ";
$credits_html .= "<a href='" . $author_details["author_url"] . "'>" . $author_details["author"] . "</a>"; $credits_html .= "<a href='" . $author_details["author_url"] . "'>" . $author_details["author"] . "</a>";
$credits_html .= "</li>\n"; $credits_html .= "</li>\n";
} }
$credits_html .= "</ul>"; $credits_html .= "</ul>";
$title = "Credits - $settings->sitename"; $title = "Credits - $settings->sitename";
$content = "<h1>$settings->sitename credits</h1> $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='//starbeamrainbowlabs.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>$settings->sitename is powered by Pepperminty Wiki - an entire wiki packed inside a single file, which was built by <a href='//starbeamrainbowlabs.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>
<h2>Main Credits</h2> <h2>Main Credits</h2>
$credits_html $credits_html
<h2>Site status</h2> <h2>Site status</h2>
<table> <table>
<tr><th>Site name:</th><td>$settings->sitename (<a href='?action=update'>Update - Administrators only</a>, <a href='?action=export'>Export as zip - Check for permission first</a>)</td></tr> <tr><th>Site name:</th><td>$settings->sitename (<a href='?action=update'>Update - Administrators only</a>, <a href='?action=export'>Export as zip - Check for permission first</a>)</td></tr>
<tr><th>Pepperminty Wiki version:</th><td>$version</td></tr> <tr><th>Pepperminty Wiki version:</th><td>$version</td></tr>
<tr><th>Number of pages:</th><td>" . count(get_object_vars($pageindex)) . "</td></tr> <tr><th>Number of pages:</th><td>" . count(get_object_vars($pageindex)) . "</td></tr>
<tr><th>Number of modules:</th><td>" . count($modules) . "</td></tr> <tr><th>Number of modules:</th><td>" . count($modules) . "</td></tr>
</table>"; </table>";
exit(page_renderer::render_main($title, $content)); exit(page_renderer::render_main($title, $content));
}); });
} }
]); ]);
?> ?>

View File

@ -1,38 +1,38 @@
<?php <?php
register_module([ register_module([
"name" => "Page deleter", "name" => "Page deleter",
"version" => "0.5", "version" => "0.5",
"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, $page, $isadmin;
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 $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>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=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>")); <p>Nothing has been changed.</p>"));
} }
if(!$isadmin) if(!$isadmin)
{ {
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 $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>")); <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 $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=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>")); <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 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("./$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 $page - $settings->sitename", "<p>$page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
}); });
} }
]); ]);
?> ?>

View File

@ -1,139 +1,139 @@
<?php <?php
register_module([ register_module([
"name" => "Page editor", "name" => "Page editor",
"version" => "0.8", "version" => "0.8",
"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",
"code" => function() { "code" => function() {
/* /*
* _ _ _ * _ _ _
* ___ __| (_) |_ * ___ __| (_) |_
* / _ \/ _` | | __| * / _ \/ _` | | __|
* | __/ (_| | | |_ * | __/ (_| | | |_
* \___|\__,_|_|\__| * \___|\__,_|_|\__|
* %edit% * %edit%
*/ */
add_action("edit", function() { add_action("edit", function() {
global $pageindex, $settings, $page, $isloggedin; global $pageindex, $settings, $page, $isloggedin;
$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 !$settings->anonedits) or !$settings->editing) if((!$isloggedin and !$settings->anonedits) or !$settings->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(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 $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>"));
} }
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 - $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 $settings->anonedits) if(!$isloggedin 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>";
} }
$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(page_renderer::render_main("$title - $settings->sitename", $content)); exit(page_renderer::render_main("$title - $settings->sitename", $content));
}); });
/* /*
* *
* ___ __ ___ _____ * ___ __ ___ _____
* / __|/ _` \ \ / / _ \ * / __|/ _` \ \ / / _ \
* \__ \ (_| |\ V / __/ * \__ \ (_| |\ V / __/
* |___/\__,_| \_/ \___| * |___/\__,_| \_/ \___|
* %save% * %save%
*/ */
add_action("save", function() { add_action("save", function() {
global $pageindex, $settings, $page, $isloggedin, $user; global $pageindex, $settings, $page, $isloggedin, $user;
if(!$settings->editing) if(!$settings->editing)
{ {
header("location: index.php?page=$page"); header("location: index.php?page=$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(!$isloggedin 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=$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=$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("$page.md")))
{ {
// Recursively create the directory if needed // Recursively create the directory if needed
mkdir(dirname("$page.md"), null, true); mkdir(dirname("$page.md"), null, true);
} }
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false) if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
{ {
// Make sure that this page's parents exist // Make sure that this page's parents exist
check_subpage_parents($page); check_subpage_parents($page);
//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));
if(isset($_GET["newpage"])) if(isset($_GET["newpage"]))
http_response_code(201); http_response_code(201);
else else
http_response_code(200); http_response_code(200);
header("location: index.php?page=$page&edit_status=success"); header("location: index.php?page=$page&edit_status=success");
exit(); exit();
} }
else else
{ {
http_response_code(507); http_response_code(507);
exit(page_renderer::render_main("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> exit(page_renderer::render_main("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>")); <p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
} }
}); });
} }
]); ]);
?> ?>

View File

@ -1,51 +1,51 @@
<?php <?php
register_module([ register_module([
"name" => "Export", "name" => "Export",
"version" => "0.1", "version" => "0.1",
"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, $isadmin;
if($settings->export_allow_only_admins && !$isadmin) if($settings->export_allow_only_admins && !$isadmin)
{ {
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>."));
} }
$tmpfilename = tempnam(sys_get_temp_dir(), "pepperminty-wiki-"); $tmpfilename = tempnam(sys_get_temp_dir(), "pepperminty-wiki-");
$zip = new ZipArchive(); $zip = new ZipArchive();
if($zip->open($tmpfilename, ZipArchive::CREATE) !== true) if($zip->open($tmpfilename, ZipArchive::CREATE) !== true)
{ {
http_response_code(507); http_response_code(507);
exit(page_renderer::render("Export error - $settings->sitename", "Pepperminty Wiki was unable to open a temporary file to store the exported data in. Please contact $settings->sitename's administrator (" . $settings->admindetails["name"] . " at " . hide_email($settings->admindetails["email"]) . ") for assistance.")); exit(page_renderer::render("Export error - $settings->sitename", "Pepperminty Wiki was unable to open a temporary file to store the exported data in. Please contact $settings->sitename's administrator (" . $settings->admindetails["name"] . " at " . hide_email($settings->admindetails["email"]) . ") for assistance."));
} }
foreach($pageindex as $entry) foreach($pageindex as $entry)
{ {
$zip->addFile("./$entry->filename", $entry->filename); $zip->addFile("./$entry->filename", $entry->filename);
} }
if($zip->close() !== true) if($zip->close() !== true)
{ {
http_response_code(500); http_response_code(500);
exit(page_renderer::render("Export error - $settings->sitename", "Pepperminty wiki was unable to close the temporary zip file after creating it. Please contact $settings->sitename's administrator (" . $settings->admindetails["name"] . " at " . hide_email($settings->admindetails["email"]) . ") for assistance.")); exit(page_renderer::render("Export error - $settings->sitename", "Pepperminty wiki was unable to close the temporary zip file after creating it. Please contact $settings->sitename's administrator (" . $settings->admindetails["name"] . " at " . hide_email($settings->admindetails["email"]) . ") for assistance."));
} }
header("content-type: application/zip"); header("content-type: application/zip");
header("content-disposition: attachment; filename=$settings->sitename-export.zip"); header("content-disposition: attachment; filename=$settings->sitename-export.zip");
header("content-length: " . filesize($tmpfilename)); header("content-length: " . filesize($tmpfilename));
$zip_handle = fopen($tmpfilename, "rb"); $zip_handle = fopen($tmpfilename, "rb");
fpassthru($zip_handle); fpassthru($zip_handle);
fclose($zip_handle); fclose($zip_handle);
unlink($tmpfilename); unlink($tmpfilename);
}); });
} }
]); ]);
?> ?>

View File

@ -1,61 +1,61 @@
<?php <?php
register_module([ register_module([
"name" => "Help page", "name" => "Help page",
"version" => "0.6", "version" => "0.6",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds the help action. You really want this one.", "description" => "Adds the help action. You really want this one.",
"id" => "page-help", "id" => "page-help",
"code" => function() { "code" => function() {
add_action("help", function() { add_action("help", function() {
global $settings, $version; global $settings, $version;
$title = "Help - $settings->sitename"; $title = "Help - $settings->sitename";
$content = " <h1>$settings->sitename Help</h1> $content = " <h1>$settings->sitename Help</h1>
<p>Welcome to $settings->sitename!</p> <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> <p>$settings->sitename is powered by Pepperminty wiki, a complete wiki in a box you can drop into your server.</p>
<h2>Navigating</h2> <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>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> <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> <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> <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> <table>
<tr><th>Type This</th><th>To get this</th> <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>_italics_</code></td><td><em>italics</em></td></tr>
<tr><td><code>*bold*</code></td><td><strong>bold</strong></td></tr> <tr><td><code>*bold*</code></td><td><strong>bold</strong></td></tr>
<tr><td><code>~~Strikethrough~~</code></td><td><del>Strikethough</del></td></tr> <tr><td><code>~~Strikethrough~~</code></td><td><del>Strikethough</del></td></tr>
<tr><td><code>`code`</code></td><td><code>code</code></td></tr> <tr><td><code>`code`</code></td><td><code>code</code></td></tr>
<tr><td><code># Heading</code></td><td><h2>Heading</h2></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>## 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>[[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|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>[Display text](//google.com/)</code></td><td><a href='//google.com/'>Display Text</a></td></tr>
<tr><td><code>&gt; Blockquote<br />&gt; Some text</code></td><td><blockquote> Blockquote<br />Some text</td></tr> <tr><td><code>&gt; Blockquote<br />&gt; Some text</code></td><td><blockquote> Blockquote<br />Some text</td></tr>
<tr><td><code> - Apples<br /> * Oranges</code></td><td><ul><li>Apples</li><li>Oranges</li></ul></td></tr> <tr><td><code> - Apples<br /> * Oranges</code></td><td><ul><li>Apples</li><li>Oranges</li></ul></td></tr>
<tr><td><code>1. This is<br />2. an ordered list</code></td><td><ol><li>This is</li><li>an ordered list</li></ol></td></tr> <tr><td><code>1. This is<br />2. an ordered list</code></td><td><ol><li>This is</li><li>an ordered list</li></ol></td></tr>
<tr><td><code> <tr><td><code>
--- ---
</code></td><td><hr /></td></tr> </code></td><td><hr /></td></tr>
<!--<tr><tds><code> - One <!--<tr><tds><code> - One
- Two - Two
- Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>--> - Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>-->
<tr><td><code>![Alt text](//starbeamrainbowlabs.com/favicon-small.png)</code></td><td><img src='//starbeamrainbowlabs.com/favicon-small.png' alt='Alt text' /></td></code> <tr><td><code>![Alt text](//starbeamrainbowlabs.com/favicon-small.png)</code></td><td><img src='//starbeamrainbowlabs.com/favicon-small.png' alt='Alt text' /></td></code>
</table> </table>
<p>In addition, the following extra syntax is supported for images:</p> <p>In addition, the following extra syntax is supported for images:</p>
<pre><code>Size the image to at most 250 pixels wide: <pre><code>Size the image to at most 250 pixels wide:
![Alt text](//starbeamrainbowlabs.com/favicon-small.png 250px) ![Alt text](//starbeamrainbowlabs.com/favicon-small.png 250px)
Size the image to at most 120px wide and have it float at the right ahnd size of the page: Size the image to at most 120px wide and have it float at the right ahnd size of the page:
![Alt text](//starbeamrainbowlabs.com/favicon-small.png 120px right)</code></pre> ![Alt text](//starbeamrainbowlabs.com/favicon-small.png 120px right)</code></pre>
<h2>Administrator Actions</h2> <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>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>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>"; <p>$settings->sitename is currently running on Pepperminty Wiki <code>$version</code></p>";
exit(page_renderer::render_main($title, $content)); exit(page_renderer::render_main($title, $content));
}); });
} }
]); ]);
?> ?>

View File

@ -1,40 +1,40 @@
<?php <?php
register_module([ register_module([
"name" => "Page list", "name" => "Page list",
"version" => "0.6", "version" => "0.6",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds a page that lists all the pages in the index along with their metadata.", "description" => "Adds a page that lists all the pages in the index along with their metadata.",
"id" => "page-list", "id" => "page-list",
"code" => function() { "code" => function() {
add_action("list", function() { add_action("list", function() {
global $pageindex, $settings; global $pageindex, $settings;
$sorted_pageindex = get_object_vars($pageindex); $sorted_pageindex = get_object_vars($pageindex);
ksort($sorted_pageindex, SORT_NATURAL); ksort($sorted_pageindex, SORT_NATURAL);
$title = "All Pages"; $title = "All Pages";
$content = " <h1>$title on $settings->sitename</h1> $content = " <h1>$title on $settings->sitename</h1>
<table> <table>
<tr> <tr>
<th>Page Name</th> <th>Page Name</th>
<th>Size</th> <th>Size</th>
<th>Last Editor</th> <th>Last Editor</th>
<th>Last Edit Time</th> <th>Last Edit Time</th>
</tr>\n"; </tr>\n";
// todo list the pages in alphabetical order // todo list the pages in alphabetical order
foreach($sorted_pageindex as $pagename => $pagedetails) foreach($sorted_pageindex as $pagename => $pagedetails)
{ {
$content .= "\t\t<tr> $content .= "\t\t<tr>
<td><a href='index.php?page=$pagename'>$pagename</a></td> <td><a href='index.php?page=$pagename'>$pagename</a></td>
<td>" . human_filesize($pagedetails->size) . "</td> <td>" . human_filesize($pagedetails->size) . "</td>
<td>$pagedetails->lasteditor</td> <td>$pagedetails->lasteditor</td>
<td>" . human_time_since($pagedetails->lastmodified) . " <small>(" . date("l jS \of F Y \a\\t h:ia T", $pagedetails->lastmodified) . ")</small></td> <td>" . human_time_since($pagedetails->lastmodified) . " <small>(" . date("l jS \of F Y \a\\t h:ia T", $pagedetails->lastmodified) . ")</small></td>
</tr>\n"; </tr>\n";
} }
$content .= " </table>"; $content .= " </table>";
exit(page_renderer::render_main("$title - $settings->sitename", $content)); exit(page_renderer::render_main("$title - $settings->sitename", $content));
}); });
} }
]); ]);
?> ?>

View File

@ -1,83 +1,83 @@
<?php <?php
register_module([ register_module([
"name" => "Login", "name" => "Login",
"version" => "0.5", "version" => "0.5",
"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",
"code" => function() { "code" => function() {
/* /*
* _ _ * _ _
* | | ___ __ _(_)_ __ * | | ___ __ _(_)_ __
* | |/ _ \ / _` | | '_ \ * | |/ _ \ / _` | | '_ \
* | | (_) | (_| | | | | | * | | (_) | (_| | | | | |
* |_|\___/ \__, |_|_| |_| * |_|\___/ \__, |_|_| |_|
* |___/ %login% * |___/ %login%
*/ */
add_action("login", function() { add_action("login", function() {
global $settings; global $settings;
$title = "Login to $settings->sitename"; $title = "Login to $settings->sitename";
$content = "<h1>Login to $settings->sitename</h1>\n"; $content = "<h1>Login to $settings->sitename</h1>\n";
if(isset($_GET["failed"])) if(isset($_GET["failed"]))
$content .= "\t\t<p><em>Login failed.</em></p>\n"; $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']) . "'> $content .= "\t\t<form method='post' action='index.php?action=checklogin&returnto=" . rawurlencode($_SERVER['REQUEST_URI']) . "'>
<label for='user'>Username:</label> <label for='user'>Username:</label>
<input type='text' name='user' id='user' /> <input type='text' name='user' id='user' />
<br /> <br />
<label for='pass'>Password:</label> <label for='pass'>Password:</label>
<input type='password' name='pass' id='pass' /> <input type='password' name='pass' id='pass' />
<br /> <br />
<input type='submit' value='Login' /> <input type='submit' value='Login' />
</form>"; </form>";
exit(page_renderer::render_main($title, $content)); exit(page_renderer::render_main($title, $content));
}); });
/* /*
* _ _ _ _ * _ _ _ _
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __ * ___| |__ ___ ___| | _| | ___ __ _(_)_ __
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \ * / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
* | (__| | | | __/ (__| <| | (_) | (_| | | | | | * | (__| | | | __/ (__| <| | (_) | (_| | | | | |
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_| * \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
* %checklogin% |___/ * %checklogin% |___/
*/ */
add_action("checklogin", function() { add_action("checklogin", function() {
global $settings; global $settings;
//actually do the login //actually do the login
if(isset($_POST["user"]) and isset($_POST["pass"])) if(isset($_POST["user"]) and isset($_POST["pass"]))
{ {
//the user wants to log in //the user wants to log in
$user = $_POST["user"]; $user = $_POST["user"];
$pass = $_POST["pass"]; $pass = $_POST["pass"];
if($settings->users[$user] == hash("sha256", $pass)) if($settings->users[$user] == hash("sha256", $pass))
{ {
$isloggedin = true; $isloggedin = 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);
$_SESSION["$settings->sessionprefix-expiretime"] = $expiretime; $_SESSION["$settings->sessionprefix-expiretime"] = $expiretime;
//redirect to wherever the user was going //redirect to wherever the user was going
http_response_code(302); http_response_code(302);
if(isset($_POST["goto"])) if(isset($_POST["goto"]))
header("location: " . $_POST["returnto"]); header("location: " . $_POST["returnto"]);
else else
header("location: index.php"); header("location: index.php");
exit(); exit();
} }
else else
{ {
http_response_code(302); http_response_code(302);
header("location: index.php?action=login&failed=yes"); header("location: index.php?action=login&failed=yes");
exit(); exit();
} }
} }
else else
{ {
http_response_code(302); http_response_code(302);
header("location: index.php?action=login&failed=yes&badrequest=yes"); header("location: index.php?action=login&failed=yes&badrequest=yes");
exit(); exit();
} }
}); });
} }
]); ]);
?> ?>

View File

@ -1,24 +1,24 @@
<?php <?php
register_module([ register_module([
"name" => "Logout", "name" => "Logout",
"version" => "0.5", "version" => "0.5",
"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 $user, $pass, $isloggedin;
$isloggedin = false; $isloggedin = false;
unset($user); unset($user);
unset($pass); unset($pass);
//clear the session variables //clear the session variables
$_SESSION = []; $_SESSION = [];
session_destroy(); session_destroy();
exit(page_renderer::render_main("Logout Successful", "<h1>Logout Successful</h1> exit(page_renderer::render_main("Logout Successful", "<h1>Logout Successful</h1>
<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>"));
}); });
} }
]); ]);
?> ?>

View File

@ -1,64 +1,64 @@
<?php <?php
register_module([ register_module([
"name" => "Page mover", "name" => "Page mover",
"version" => "0.5", "version" => "0.5",
"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, $page, $isadmin;
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 $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>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=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>")); <p>Nothing has been changed.</p>"));
} }
if(!$isadmin) if(!$isadmin)
{ {
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 $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(page_renderer::render_main("Moving $page", "<h2>Moving $page</h2> exit(page_renderer::render_main("Moving $page", "<h2>Moving $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='$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' />
<br /> <br />
<input type='submit' value='Move Page' /> <input type='submit' value='Move Page' />
</form>")); </form>"));
$new_name = makepathsafe($_GET["new_name"]); $new_name = makepathsafe($_GET["new_name"]);
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 $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>
<p>Nothing has been changed.</p>")); <p>Nothing has been changed.</p>"));
if($page == $new_name) if($page == $new_name)
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p> 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>
<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>"));
//move the page in the page index //move the page in the page index
$pageindex->$new_name = new stdClass(); $pageindex->$new_name = new stdClass();
foreach($pageindex->$page as $key => $value) foreach($pageindex->$page as $key => $value)
{ {
$pageindex->$new_name->$key = $value; $pageindex->$new_name->$key = $value;
} }
unset($pageindex->$page); unset($pageindex->$page);
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("$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 $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>"));
}); });
} }
]); ]);
?> ?>

View File

@ -1,66 +1,66 @@
<?php <?php
register_module([ register_module([
"name" => "Update", "name" => "Update",
"version" => "0.6", "version" => "0.6",
"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, $isadmin;
if(!$isadmin) if(!$isadmin)
{ {
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>"));
} }
if(!isset($_GET["do"]) or $_GET["do"] !== "true") if(!isset($_GET["do"]) or $_GET["do"] !== "true")
{ {
exit(page_renderer::render_main("Update $settings->sitename", "<p>This page allows you to update $settings->sitename.</p> exit(page_renderer::render_main("Update $settings->sitename", "<p>This page allows you to update $settings->sitename.</p>
<p>Currently, $settings->sitename is using $settings->version of Pepperminty Wiki.</p> <p>Currently, $settings->sitename is using $settings->version of Pepperminty Wiki.</p>
<p>This script will automatically download and install the latest version of Pepperminty Wiki from the url of your choice (see settings), regardless of whether an update is actually needed (version checking isn't implemented yet).</p> <p>This script will automatically download and install the latest version of Pepperminty Wiki from the url of your choice (see settings), regardless of whether an update is actually needed (version checking isn't implemented yet).</p>
<p>To update $settings->sitename, fill out the form below and click click the update button.</p> <p>To update $settings->sitename, fill out the form below and click click the update button.</p>
<p>Note that a backup system has not been implemented yet! If this script fails you will loose your wiki's code and have to re-build it.</p> <p>Note that a backup system has not been implemented yet! If this script fails you will loose your wiki's code and have to re-build it.</p>
<form method='get' action=''> <form method='get' action=''>
<input type='hidden' name='action' value='update' /> <input type='hidden' name='action' value='update' />
<input type='hidden' name='do' value='true' /> <input type='hidden' name='do' value='true' />
<label for='secret'>$settings->sitename's secret code</label> <label for='secret'>$settings->sitename's secret code</label>
<input type='text' name='secret' value='' /> <input type='text' name='secret' value='' />
<input type='submit' value='Update' /> <input type='submit' value='Update' />
</form>")); </form>"));
} }
if(!isset($_GET["secret"]) or $_GET["secret"] !== $settings->sitesecret) if(!isset($_GET["secret"]) or $_GET["secret"] !== $settings->sitesecret)
{ {
exit(page_renderer::render_main("Update $settings->sitename - Error", "<p>You forgot to enter $settings->sitename's secret code or entered it incorrectly. $settings->sitename's secret can be found in the settings portion of <code>index.php</code>.</p>")); exit(page_renderer::render_main("Update $settings->sitename - Error", "<p>You forgot to enter $settings->sitename's secret code or entered it incorrectly. $settings->sitename's secret can be found in the settings portion of <code>index.php</code>.</p>"));
} }
$settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////"; $settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////";
$log = "Beginning update...\n"; $log = "Beginning update...\n";
$log .= "I am <code>" . __FILE__ . "</code>.\n"; $log .= "I am <code>" . __FILE__ . "</code>.\n";
$oldcode = file_get_contents(__FILE__); $oldcode = file_get_contents(__FILE__);
$log .= "Fetching new code..."; $log .= "Fetching new code...";
$newcode = file_get_contents($settings->updateurl); $newcode = file_get_contents($settings->updateurl);
$log .= "done.\n"; $log .= "done.\n";
$log .= "Rewriting <code>" . __FILE__ . "</code>..."; $log .= "Rewriting <code>" . __FILE__ . "</code>...";
$settings = substr($oldcode, 0, strpos($oldcode, $settings_separator)); $settings = substr($oldcode, 0, strpos($oldcode, $settings_separator));
$code = substr($newcode, strpos($newcode, $settings_separator)); $code = substr($newcode, strpos($newcode, $settings_separator));
$result = $settings . $code; $result = $settings . $code;
$log .= "done.\n"; $log .= "done.\n";
$log .= "Saving..."; $log .= "Saving...";
file_put_contents(__FILE__, $result); file_put_contents(__FILE__, $result);
$log .= "done.\n"; $log .= "done.\n";
$log .= "Update complete. I am now running on the latest version of Pepperminty Wiki."; $log .= "Update complete. I am now running on the latest version of Pepperminty Wiki.";
$log .= "The version number that I have updated to can be found on the credits or help ages."; $log .= "The version number that I have updated to can be found on the credits or help ages.";
exit(page_renderer::render_main("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>")); exit(page_renderer::render_main("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>"));
}); });
} }
]); ]);
?> ?>

View File

@ -1,67 +1,67 @@
<?php <?php
register_module([ register_module([
"name" => "Page viewer", "name" => "Page viewer",
"version" => "0.8", "version" => "0.8",
"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, $page, $parse_page_source;
// Check to make sure that the page exists // Check to make sure that the page exists
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
if($settings->editing) if($settings->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(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("$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>"));
} }
} }
$title = "$page - $settings->sitename"; $title = "$page - $settings->sitename";
$content = "<h1>$page</h1>"; $content = "<h1>$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("$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, $page));
if(count($subpages) > 0) if(count($subpages) > 0)
{ {
$content .= "<hr />"; $content .= "<hr />";
$content .= "Subpages: "; $content .= "Subpages: ";
foreach($subpages as $subpage => $times_removed) foreach($subpages as $subpage => $times_removed)
{ {
if($times_removed <= $settings->subpages_display_depth) if($times_removed <= $settings->subpages_display_depth)
{ {
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, "; $content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
} }
} }
// Remove the last comma from the content // Remove the last comma from the content
$content = substr($content, 0, -2); $content = substr($content, 0, -2);
} }
} }
$content .= "\n\t\t<!-- Took " . (microtime(true) - $parsing_start) . " seconds to parse page source -->\n"; $content .= "\n\t\t<!-- Took " . (microtime(true) - $parsing_start) . " seconds to parse page source -->\n";
if(isset($_GET["printable"]) and $_GET["printable"] === "yes") if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
exit(page_renderer::render_minimal($title, $content)); exit(page_renderer::render_minimal($title, $content));
else else
exit(page_renderer::render_main($title, $content)); exit(page_renderer::render_main($title, $content));
}); });
} }
]); ]);
?> ?>

View File

@ -1,127 +1,127 @@
<?php <?php
register_module([ register_module([
"name" => "Default Parser", "name" => "Default Parser",
"version" => "0.7", "version" => "0.7",
"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",
"code" => function() { "code" => function() {
add_parser(function($markdown) { add_parser(function($markdown) {
return Slimdown::render($markdown); return Slimdown::render($markdown);
}); });
} }
]); ]);
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// Slimdown ///////////////////////////////////////// ///////////////////////////////////////// Slimdown /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// %slimdown% // ////////////////////////////////////////////////////////////////////////////// %slimdown% //
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
/** /**
* Slimdown - A very basic regex-based Markdown parser. Supports the * Slimdown - A very basic regex-based Markdown parser. Supports the
* following elements (and can be extended via Slimdown::add_rule()): * following elements (and can be extended via Slimdown::add_rule()):
* *
* - Headers * - Headers
* - Links * - Links
* - Bold * - Bold
* - Emphasis * - Emphasis
* - Deletions * - Deletions
* - Quotes * - Quotes
* - Inline code * - Inline code
* - Blockquotes * - Blockquotes
* - Ordered/unordered lists * - Ordered/unordered lists
* - Horizontal rules * - Horizontal rules
* *
* Author: Johnny Broadway <johnny@johnnybroadway.com> * Author: Johnny Broadway <johnny@johnnybroadway.com>
* Website: https://gist.github.com/jbroadway/2836900 * Website: https://gist.github.com/jbroadway/2836900
* License: MIT * License: MIT
*/ */
/** /**
* Modified by Starbeamrainbowlabs (starbeamrainbowlabs) * Modified by Starbeamrainbowlabs (starbeamrainbowlabs)
* *
* Changed bold to use single asterisks * Changed bold to use single asterisks
* Changed italics to use single underscores * Changed italics to use single underscores
* Added one to add the heading levels (no <h1> tags allowed) * Added one to add the heading levels (no <h1> tags allowed)
* Added wiki style internal link parsing * Added wiki style internal link parsing
* Added wiki style internal link parsing with display text * Added wiki style internal link parsing with display text
* Added image support * Added image support
*/ */
class Slimdown { class Slimdown {
public static $rules = array ( public static $rules = array (
'/\r\n/' => "\n", // new line normalisation '/\r\n/' => "\n", // new line normalisation
'/(#+)(.*)/' => 'self::header', // headers '/(#+)(.*)/' => 'self::header', // headers
'/(\*)(.*?)\1/' => '<strong>\2</strong>', // bold '/(\*)(.*?)\1/' => '<strong>\2</strong>', // bold
'/(_)(.*?)\1/' => '<em>\2</em>', // emphasis '/(_)(.*?)\1/' => '<em>\2</em>', // emphasis
// todo test these // 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 // 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
'/\[([^\[]+)\]\(([^\)]+)\)/' => '<a href=\'\2\' target=\'_blank\'>\1</a>', // links '/\[([^\[]+)\]\(([^\)]+)\)/' => '<a href=\'\2\' target=\'_blank\'>\1</a>', // links
'/\~\~(.*?)\~\~/' => '<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
'/\n([^\n]+)\n\n/' => 'self::para', // add paragraphs '/\n([^\n]+)\n\n/' => 'self::para', // add paragraphs
'/<\/ul>\s?<ul>/' => '', // fix extra ul '/<\/ul>\s?<ul>/' => '', // fix extra ul
'/<\/ol>\s?<ol>/' => '', // fix extra ol '/<\/ol>\s?<ol>/' => '', // fix extra ol
'/<\/blockquote><blockquote>/' => "\n" // fix extra blockquote '/<\/blockquote><blockquote>/' => "\n" // fix extra blockquote
); );
private static function para ($regs) { private static function para ($regs) {
$line = $regs[1]; $line = $regs[1];
$trimmed = trim ($line); $trimmed = trim ($line);
if (preg_match ('/^<\/?(ul|ol|li|h|p|bl)/', $trimmed)) { if (preg_match ('/^<\/?(ul|ol|li|h|p|bl)/', $trimmed)) {
return "\n" . $line . "\n"; return "\n" . $line . "\n";
} }
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) {
$item = $regs[1]; $item = $regs[1];
return sprintf ("\n<ol>\n\t<li>%s</li>\n</ol>", trim($item)); return sprintf ("\n<ol>\n\t<li>%s</li>\n</ol>", trim($item));
} }
private static function blockquote ($regs) { private static function blockquote ($regs) {
$item = $regs[2]; $item = $regs[2];
return sprintf ("\n<blockquote>%s</blockquote>", trim($item)); return sprintf ("\n<blockquote>%s</blockquote>", trim($item));
} }
private static function header ($regs) { private static function header ($regs) {
list ($tmp, $chars, $header) = $regs; list ($tmp, $chars, $header) = $regs;
$level = strlen ($chars); $level = strlen ($chars);
return sprintf ('<h%d>%s</h%d>', $level + 1, trim($header), $level + 1); return sprintf ('<h%d>%s</h%d>', $level + 1, trim($header), $level + 1);
} }
/** /**
* Add a rule. * Add a rule.
*/ */
public static function add_rule ($regex, $replacement) { public static function add_rule ($regex, $replacement) {
self::$rules[$regex] = $replacement; self::$rules[$regex] = $replacement;
} }
/** /**
* Render some Markdown into HTML. * Render some Markdown into HTML.
*/ */
public static function render ($text) { public static function render ($text) {
foreach (self::$rules as $regex => $replacement) { foreach (self::$rules as $regex => $replacement) {
if (is_callable ( $replacement)) { if (is_callable ( $replacement)) {
$text = preg_replace_callback ($regex, $replacement, $text); $text = preg_replace_callback ($regex, $replacement, $text);
} else { } else {
$text = preg_replace ($regex, $replacement, $text); $text = preg_replace ($regex, $replacement, $text);
} }
} }
return trim ($text); return trim ($text);
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
?> ?>

View File

@ -1,32 +1,32 @@
<?php <?php
echo("Rebuilding module index...\n"); echo("Rebuilding module index...\n");
$modules = glob("modules/*.php"); $modules = glob("modules/*.php");
$module_index = []; $module_index = [];
function register_module($settings) function register_module($settings)
{ {
global $module_index; global $module_index;
$newmodule = [ $newmodule = [
"name" => $settings["name"], "name" => $settings["name"],
"version" => $settings["version"], "version" => $settings["version"],
"author" => $settings["author"], "author" => $settings["author"],
"description" => $settings["description"], "description" => $settings["description"],
"id" => $settings["id"], "id" => $settings["id"],
"lastupdate" => filemtime("modules/" . $settings["id"] . ".php") "lastupdate" => filemtime("modules/" . $settings["id"] . ".php")
]; ];
$module_index[] = $newmodule; $module_index[] = $newmodule;
} }
foreach($modules as $filename) foreach($modules as $filename)
{ {
echo("Processing $filename\n"); echo("Processing $filename\n");
require($filename); require($filename);
} }
echo("*** Processing Complete ***\n"); echo("*** Processing Complete ***\n");
echo("Writing new module index to disk..."); echo("Writing new module index to disk...");
file_put_contents("module_index.json", json_encode($module_index, JSON_PRETTY_PRINT)); file_put_contents("module_index.json", json_encode($module_index, JSON_PRETTY_PRINT));
echo("done\n"); echo("done\n");
?> ?>

View File

@ -1 +1 @@
php -S [::]:4569 php -S [::]:4569