1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-21 16:13:00 +00:00

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
*.md
# include the README
!README.md
# the page index
pageindex.json
# all wiki pages
*.md
# include the README
!README.md
# the page index
pageindex.json

178
README.md
View file

@ -1,90 +1,90 @@
# Pepperminty Wiki
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).
## Screenshots
![Main Page Example](https://cloud.githubusercontent.com/assets/9929737/9069904/12acfad6-3ae4-11e5-8ec4-6ec0e3de7249.png)
Above: A Main Page with the sidebar enabled.
## Features
- Configurable settings
- User login system
- Page creation
- Sub pages
- Markdown-powered syntax
- Internal links
- Printable page view
- Customisable theme
- Basic 'search' bar
- (Optional) Sidebar with a tree of all the current pages
- List of all pages & details
- Inbuilt help page
## Demo
A Live demo of the latest stable version can be found over at [my website](//starbeamrainbowlabs.com/labs/peppermint)
## Getting Started
### Requirements
- PHP-enabled webserver
- 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)
### 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:
#### 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.
#### 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).
#### 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).
#### 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`.
#### 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:
##### Windows
Simply run the `build.bat` script in the root of the repository. It will handle everything for you.
##### 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):
```bash
rm build/index.php
php rebuild_module_index.php
php build.php
```
Here's an explanation of what each command does:
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
3. Actually builds Pepperminty Wiki. Outputs to `index.php`.
### 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).
## 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.
## 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!
## 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!).
- Page history
- Password changing
- Intelligent auto-updating system that doesn't wipe your settings / module choices
- Make links to non-existent pages red
- Optional module support
- Redirect pages
- ...?
# Pepperminty Wiki
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).
## Screenshots
![Main Page Example](https://cloud.githubusercontent.com/assets/9929737/9069904/12acfad6-3ae4-11e5-8ec4-6ec0e3de7249.png)
Above: A Main Page with the sidebar enabled.
## Features
- Configurable settings
- User login system
- Page creation
- Sub pages
- Markdown-powered syntax
- Internal links
- Printable page view
- Customisable theme
- Basic 'search' bar
- (Optional) Sidebar with a tree of all the current pages
- List of all pages & details
- Inbuilt help page
## Demo
A Live demo of the latest stable version can be found over at [my website](//starbeamrainbowlabs.com/labs/peppermint)
## Getting Started
### Requirements
- PHP-enabled webserver
- 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)
### 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:
#### 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.
#### 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).
#### 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).
#### 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`.
#### 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:
##### Windows
Simply run the `build.bat` script in the root of the repository. It will handle everything for you.
##### 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):
```bash
rm build/index.php
php rebuild_module_index.php
php build.php
```
Here's an explanation of what each command does:
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
3. Actually builds Pepperminty Wiki. Outputs to `index.php`.
### 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).
## 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.
## 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!
## 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!).
- Page history
- Password changing
- Intelligent auto-updating system that doesn't wipe your settings / module choices
- Make links to non-existent pages red
- Optional module support
- 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)!

View file

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

158
build.php
View file

@ -1,79 +1,79 @@
<?php
if(php_sapi_name() == "cli")
{
echo("Beginning build...\n");
echo("Reading in module index...\n");
}
$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");
}
if(php_sapi_name() == "cli") echo("Reading in core files...");
$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;
if(php_sapi_name() == "cli") echo("Adding $module_id\n");
$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("build/index.php"))
{
echo("index.php already exists in the build folder, exiting\n");
exit(1);
}
else
{
echo("Done. Saving to disk...");
file_put_contents("build/index.php", $result);
echo("complete!\n");
echo("*** Build Completed ***\n");
}
}
else
{
exit($result);
}
?>
<?php
if(php_sapi_name() == "cli")
{
echo("Beginning build...\n");
echo("Reading in module index...\n");
}
$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");
}
if(php_sapi_name() == "cli") echo("Reading in core files...");
$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;
if(php_sapi_name() == "cli") echo("Adding $module_id\n");
$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("build/index.php"))
{
echo("index.php already exists in the build folder, exiting\n");
exit(1);
}
else
{
echo("Done. Saving to disk...");
file_put_contents("build/index.php", $result);
echo("complete!\n");
echo("*** Build Completed ***\n");
}
}
else
{
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>
<html>
<head>
<meta charset="utf-8" />
<title>Pepperminty Wiki Download</title>
</head>
<body>
<h1>Pepperminty Wiki Download</h1>
<!-------------->
<h2>Module selector</h2>
<p>Choose the modules that you want to include in your installation of Pepperminty Wiki.</p>
<p>
<button onclick="select(true);">Select All</button>
<button onclick="select(false);">Select None</button>
</p>
<table>
<tr>
<th></th>
<th>Name</th>
<th>Description</th>
<th>Author</th>
<th>Version</th>
<th style="width: 9rem;">Last Updated</th>
</tr>
<?php
$module_index = json_decode(file_get_contents("module_index.json"));
foreach($module_index as $module)
{
echo("<tr>
<td><input type='checkbox' id='$module->id' checked /></td>
<td><label for='$module->id'>$module->name</label></td>
<td>$module->description</td>
<td>$module->author</td>
<td>$module->version</td>
<td>" . date("D jS M Y", $module->lastupdate) . "</td>
</tr>");
}
?>
</table>
<br />
<br />
<button onclick="download()" class="largebutton">Download</button>
<hr />
<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>.
</p>
<p>
Other contributors: (none yet! Contribute and I will put your name here)
</p>
<!------------------->
<link rel="stylesheet" href="//starbeamrainbowlabs.com/theme/basic.css" />
<style>
body { padding: 1rem; color: #442772; background-colour: #eee8f2; } /* syntaxtic gets confused sometimes */
a { color: #9e7eb4; }
.largebutton { font-size: 2rem; }
</style>
<script>
function select(state)
{
var checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++)
{
checkboxes[i].checked = state;
}
}
function download()
{
var url = "build.php?web=true&modules=",
checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++)
{
url += encodeURIComponent(checkboxes[i].id) + ",";
}
location.href = url;
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Pepperminty Wiki Download</title>
</head>
<body>
<h1>Pepperminty Wiki Download</h1>
<!-------------->
<h2>Module selector</h2>
<p>Choose the modules that you want to include in your installation of Pepperminty Wiki.</p>
<p>
<button onclick="select(true);">Select All</button>
<button onclick="select(false);">Select None</button>
</p>
<table>
<tr>
<th></th>
<th>Name</th>
<th>Description</th>
<th>Author</th>
<th>Version</th>
<th style="width: 9rem;">Last Updated</th>
</tr>
<?php
$module_index = json_decode(file_get_contents("module_index.json"));
foreach($module_index as $module)
{
echo("<tr>
<td><input type='checkbox' id='$module->id' checked /></td>
<td><label for='$module->id'>$module->name</label></td>
<td>$module->description</td>
<td>$module->author</td>
<td>$module->version</td>
<td>" . date("D jS M Y", $module->lastupdate) . "</td>
</tr>");
}
?>
</table>
<br />
<br />
<button onclick="download()" class="largebutton">Download</button>
<hr />
<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>.
</p>
<p>
Other contributors: (none yet! Contribute and I will put your name here)
</p>
<!------------------->
<link rel="stylesheet" href="//starbeamrainbowlabs.com/theme/basic.css" />
<style>
body { padding: 1rem; color: #442772; background-colour: #eee8f2; } /* syntaxtic gets confused sometimes */
a { color: #9e7eb4; }
.largebutton { font-size: 2rem; }
</style>
<script>
function select(state)
{
var checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++)
{
checkboxes[i].checked = state;
}
}
function download()
{
var url = "build.php?web=true&modules=",
checkboxes = document.querySelectorAll("input[type=checkbox]");
for(var i = 0; i < checkboxes.length; i++)
{
url += encodeURIComponent(checkboxes[i].id) + ",";
}
location.href = url;
}
</script>
</body>
</html>

View file

@ -1,24 +1,24 @@
<?php
register_module([
"name" => "Password hashing action",
"version" => "0.5",
"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(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>"));
}
else
{
exit(page_renderer::render_main("Hashed string", "<p><code>" . $_GET["string"] . "</code> → <code>" . hash("sha256", $_GET["string"] . "</code></p>")));
}
});
}
]);
?>
<?php
register_module([
"name" => "Password hashing action",
"version" => "0.5",
"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(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>"));
}
else
{
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
register_module([
"name" => "Sidebar",
"version" => "0.2",
"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.",
"id" => "extra-sidebar",
"code" => function() {
$show_sidebar = false;
// Show the sidebar if it is enabled in the settings
if(isset($settings->sidebar_show) && $settings->sidebar_show === true)
$show_sidebar = true;
// Also show and persist the sidebar if the special GET parameter
// sidebar is seet
if(!$show_sidebar && isset($_GET["sidebar"]))
{
$show_sidebar = true;
// Set a cookie to persist the display of the sidebar
setcookie("sidebar_show", "true", time() + (60 * 60 * 24 * 30));
}
// Show the sidebar if the cookie is set
if(!$show_sidebar && isset($_COOKIE["sidebar_show"]))
$show_sidebar = true;
// Delete the cookie and hide the sidebar if the special GET paramter
// nosidebar is set
if(isset($_GET["nosidebar"]))
{
$show_sidebar = false;
unset($_COOKIE["sidebar_show"]);
setcookie("sidebar_show", null, time() - 3600);
}
page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) {
global $settings, $pageindex;
if($show_sidebar && !isset($_GET["printable"]))
{
// Show the sidebar
$exec_start = microtime(true);
// Sort the pageindex
$sorted_pageindex = get_object_vars($pageindex);
ksort($sorted_pageindex, SORT_NATURAL);
$sidebar_contents = "";
$sidebar_contents .= render_sidebar($sorted_pageindex);
$parts["{body}"] = "<aside class='sidebar'>
$sidebar_contents
<!-- Sidebar rendered in " . (microtime(true) - $exec_start) . "s -->
</aside>
<div class='main-container'>" . $parts["{body}"] . "</div>
<!-------------->
<style>
body { display: flex; }
.main-container { flex: 1; }
</style>";
}
});
}
]);
/*
* @summary Renders the sidebar for a given pageindex.
*
* @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.
*
* @returns {string} A HTML rendering of the sidebar for the given pageindex
*/
function render_sidebar($pageindex, $root_pagename = "")
{
global $settings;
$result = "<ul";
// If this is the very root of the tree, add an extra class to it
if($root_pagename == "") $result .= " class='sidebar-tree'";
$result .=">";
foreach ($pageindex as $pagename => $details)
{
// If we have a valid root pagename, and it isn't present at the
// beginning of the current pagename, skip it
if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0)
continue;
// The current page is the same as the root page, skip it
if($pagename == $root_pagename)
continue;
// 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.
if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false)
continue;
$result .= "<li><a href='?action=$settings->defaultaction&page=$pagename'>$pagename</a>\n";
$result .= render_sidebar($pageindex, $pagename);
$result .= "</li>\n";
}
$result .= "</ul>\n";
return $result == "<ul></ul>\n" ? "" : $result;
}
?>
<?php
register_module([
"name" => "Sidebar",
"version" => "0.2",
"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.",
"id" => "extra-sidebar",
"code" => function() {
$show_sidebar = false;
// Show the sidebar if it is enabled in the settings
if(isset($settings->sidebar_show) && $settings->sidebar_show === true)
$show_sidebar = true;
// Also show and persist the sidebar if the special GET parameter
// sidebar is seet
if(!$show_sidebar && isset($_GET["sidebar"]))
{
$show_sidebar = true;
// Set a cookie to persist the display of the sidebar
setcookie("sidebar_show", "true", time() + (60 * 60 * 24 * 30));
}
// Show the sidebar if the cookie is set
if(!$show_sidebar && isset($_COOKIE["sidebar_show"]))
$show_sidebar = true;
// Delete the cookie and hide the sidebar if the special GET paramter
// nosidebar is set
if(isset($_GET["nosidebar"]))
{
$show_sidebar = false;
unset($_COOKIE["sidebar_show"]);
setcookie("sidebar_show", null, time() - 3600);
}
page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) {
global $settings, $pageindex;
if($show_sidebar && !isset($_GET["printable"]))
{
// Show the sidebar
$exec_start = microtime(true);
// Sort the pageindex
$sorted_pageindex = get_object_vars($pageindex);
ksort($sorted_pageindex, SORT_NATURAL);
$sidebar_contents = "";
$sidebar_contents .= render_sidebar($sorted_pageindex);
$parts["{body}"] = "<aside class='sidebar'>
$sidebar_contents
<!-- Sidebar rendered in " . (microtime(true) - $exec_start) . "s -->
</aside>
<div class='main-container'>" . $parts["{body}"] . "</div>
<!-------------->
<style>
body { display: flex; }
.main-container { flex: 1; }
</style>";
}
});
}
]);
/*
* @summary Renders the sidebar for a given pageindex.
*
* @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.
*
* @returns {string} A HTML rendering of the sidebar for the given pageindex
*/
function render_sidebar($pageindex, $root_pagename = "")
{
global $settings;
$result = "<ul";
// If this is the very root of the tree, add an extra class to it
if($root_pagename == "") $result .= " class='sidebar-tree'";
$result .=">";
foreach ($pageindex as $pagename => $details)
{
// If we have a valid root pagename, and it isn't present at the
// beginning of the current pagename, skip it
if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0)
continue;
// The current page is the same as the root page, skip it
if($pagename == $root_pagename)
continue;
// 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.
if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false)
continue;
$result .= "<li><a href='?action=$settings->defaultaction&page=$pagename'>$pagename</a>\n";
$result .= render_sidebar($pageindex, $pagename);
$result .= "</li>\n";
}
$result .= "</ul>\n";
return $result == "<ul></ul>\n" ? "" : $result;
}
?>

View file

@ -1,61 +1,61 @@
<?php
register_module([
"name" => "Credits",
"version" => "0.6",
"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, $pageindex, $modules;
$credits = [
"Code" => [
"author" => "Starbeamrainbowlabs",
"author_url" => "https://starbeamrmainbowlabs.com/",
"thing_url" => "https://github.com/sbrl/Pepprminty-Wiki"
],
"Slightly modified version of Slimdown" => [
"author" => "Johnny Broadway",
"author_url" => "https://github.com/jbroadway",
"thing_url" => "https://gist.github.com/jbroadway/2836900"
],
"Default Favicon" => [
"author" => "bluefrog23",
"author_url" => "https://openclipart.org/user-detail/bluefrog23/",
"thing_url" => "https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23"
],
"Bug Reports" => [
"author" => "nibreh",
"author_url" => "https://github.com/nibreh/",
"thing_url" => ""
]
];
$credits_html = "<ul>\n";
foreach($credits as $thing => $author_details)
{
$credits_html .= " <li>";
$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 .= "</li>\n";
}
$credits_html .= "</ul>";
$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='//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>
$credits_html
<h2>Site status</h2>
<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>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 modules:</th><td>" . count($modules) . "</td></tr>
</table>";
exit(page_renderer::render_main($title, $content));
});
}
]);
?>
<?php
register_module([
"name" => "Credits",
"version" => "0.6",
"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, $pageindex, $modules;
$credits = [
"Code" => [
"author" => "Starbeamrainbowlabs",
"author_url" => "https://starbeamrmainbowlabs.com/",
"thing_url" => "https://github.com/sbrl/Pepprminty-Wiki"
],
"Slightly modified version of Slimdown" => [
"author" => "Johnny Broadway",
"author_url" => "https://github.com/jbroadway",
"thing_url" => "https://gist.github.com/jbroadway/2836900"
],
"Default Favicon" => [
"author" => "bluefrog23",
"author_url" => "https://openclipart.org/user-detail/bluefrog23/",
"thing_url" => "https://openclipart.org/detail/19571/peppermint-candy-by-bluefrog23"
],
"Bug Reports" => [
"author" => "nibreh",
"author_url" => "https://github.com/nibreh/",
"thing_url" => ""
]
];
$credits_html = "<ul>\n";
foreach($credits as $thing => $author_details)
{
$credits_html .= " <li>";
$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 .= "</li>\n";
}
$credits_html .= "</ul>";
$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='//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>
$credits_html
<h2>Site status</h2>
<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>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 modules:</th><td>" . count($modules) . "</td></tr>
</table>";
exit(page_renderer::render_main($title, $content));
});
}
]);
?>

View file

@ -1,38 +1,38 @@
<?php
register_module([
"name" => "Page deleter",
"version" => "0.5",
"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(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><a href='index.php?page=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>"));
}
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>
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
}
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
{
exit(page_renderer::render_main("Deleting $page", "<p>You are about to <strong>delete</strong> $page. You can't undo this!</p>
<p><a href='index.php?action=delete&page=$page&delete=yes'>Click here to delete $page.</a></p>
<p><a href='index.php?action=view&page=$page'>Click here to go back.</a>"));
}
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(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>"));
});
}
]);
?>
<?php
register_module([
"name" => "Page deleter",
"version" => "0.5",
"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(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><a href='index.php?page=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>"));
}
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>
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
}
if(!isset($_GET["delete"]) or $_GET["delete"] !== "yes")
{
exit(page_renderer::render_main("Deleting $page", "<p>You are about to <strong>delete</strong> $page. You can't undo this!</p>
<p><a href='index.php?action=delete&page=$page&delete=yes'>Click here to delete $page.</a></p>
<p><a href='index.php?action=view&page=$page'>Click here to go back.</a>"));
}
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(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
register_module([
"name" => "Page editor",
"version" => "0.8",
"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%
*/
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)
{
$title = "Creating $page";
}
else
{
$title = "Editing $page";
}
$pagetext = "";
if(isset($pageindex->$page))
{
$pagetext = file_get_contents($filename);
}
if((!$isloggedin and !$settings->anonedits) or !$settings->editing)
{
if(!$creatingpage)
{
// The page already exists - let the user view the page source
exit(page_renderer::render_main("Viewing source for $page", "<p>$settings->sitename does not allow anonymous users to make edits. You can view the source of $page below, but you can't edit it.</p><textarea name='content' readonly>$pagetext</textarea>"));
}
else
{
http_response_code(404);
exit(page_renderer::render_main("404 - $page", "<p>The page <code>$page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login'>logging in</a>.</p>"));
}
}
$content = "<h1>$title</h1>";
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 .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save'>
<textarea name='content'>$pagetext</textarea>
<input type='submit' value='Save Page' />
</form>";
exit(page_renderer::render_main("$title - $settings->sitename", $content));
});
/*
*
* ___ __ ___ _____
* / __|/ _` \ \ / / _ \
* \__ \ (_| |\ V / __/
* |___/\__,_| \_/ \___|
* %save%
*/
add_action("save", function() {
global $pageindex, $settings, $page, $isloggedin, $user;
if(!$settings->editing)
{
header("location: index.php?page=$page");
exit(page_renderer::render_main("Error saving edit", "<p>Editing is currently disabled on this wiki.</p>"));
}
if(!$isloggedin and !$settings->anonedits)
{
http_response_code(403);
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....");
}
if(!isset($_POST["content"]))
{
http_response_code(400);
header("refresh: 5; url=index.php?page=$page");
exit("Bad request: No content specified.");
}
// Make sure that the directory in which the page needs to be saved exists
if(!is_dir(dirname("$page.md")))
{
// Recursively create the directory if needed
mkdir(dirname("$page.md"), null, true);
}
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
{
// Make sure that this page's parents exist
check_subpage_parents($page);
//update the page index
if(!isset($pageindex->$page))
{
$pageindex->$page = new stdClass();
$pageindex->$page->filename = "$page.md";
}
$pageindex->$page->size = strlen($_POST["content"]);
$pageindex->$page->lastmodified = time();
if($isloggedin)
$pageindex->$page->lasteditor = utf8_encode($user);
else
$pageindex->$page->lasteditor = utf8_encode("anonymous");
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
if(isset($_GET["newpage"]))
http_response_code(201);
else
http_response_code(200);
header("location: index.php?page=$page&edit_status=success");
exit();
}
else
{
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>
<p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
}
});
}
]);
?>
<?php
register_module([
"name" => "Page editor",
"version" => "0.8",
"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%
*/
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)
{
$title = "Creating $page";
}
else
{
$title = "Editing $page";
}
$pagetext = "";
if(isset($pageindex->$page))
{
$pagetext = file_get_contents($filename);
}
if((!$isloggedin and !$settings->anonedits) or !$settings->editing)
{
if(!$creatingpage)
{
// The page already exists - let the user view the page source
exit(page_renderer::render_main("Viewing source for $page", "<p>$settings->sitename does not allow anonymous users to make edits. You can view the source of $page below, but you can't edit it.</p><textarea name='content' readonly>$pagetext</textarea>"));
}
else
{
http_response_code(404);
exit(page_renderer::render_main("404 - $page", "<p>The page <code>$page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login'>logging in</a>.</p>"));
}
}
$content = "<h1>$title</h1>";
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 .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save'>
<textarea name='content'>$pagetext</textarea>
<input type='submit' value='Save Page' />
</form>";
exit(page_renderer::render_main("$title - $settings->sitename", $content));
});
/*
*
* ___ __ ___ _____
* / __|/ _` \ \ / / _ \
* \__ \ (_| |\ V / __/
* |___/\__,_| \_/ \___|
* %save%
*/
add_action("save", function() {
global $pageindex, $settings, $page, $isloggedin, $user;
if(!$settings->editing)
{
header("location: index.php?page=$page");
exit(page_renderer::render_main("Error saving edit", "<p>Editing is currently disabled on this wiki.</p>"));
}
if(!$isloggedin and !$settings->anonedits)
{
http_response_code(403);
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....");
}
if(!isset($_POST["content"]))
{
http_response_code(400);
header("refresh: 5; url=index.php?page=$page");
exit("Bad request: No content specified.");
}
// Make sure that the directory in which the page needs to be saved exists
if(!is_dir(dirname("$page.md")))
{
// Recursively create the directory if needed
mkdir(dirname("$page.md"), null, true);
}
if(file_put_contents("$page.md", htmlentities($_POST["content"]), ENT_QUOTES) !== false)
{
// Make sure that this page's parents exist
check_subpage_parents($page);
//update the page index
if(!isset($pageindex->$page))
{
$pageindex->$page = new stdClass();
$pageindex->$page->filename = "$page.md";
}
$pageindex->$page->size = strlen($_POST["content"]);
$pageindex->$page->lastmodified = time();
if($isloggedin)
$pageindex->$page->lasteditor = utf8_encode($user);
else
$pageindex->$page->lasteditor = utf8_encode("anonymous");
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
if(isset($_GET["newpage"]))
http_response_code(201);
else
http_response_code(200);
header("location: index.php?page=$page&edit_status=success");
exit();
}
else
{
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>
<p>Please tell the administrator of this wiki (" . $settings->admindetails["name"] . ") about this problem.</p>"));
}
});
}
]);
?>

View file

@ -1,51 +1,51 @@
<?php
register_module([
"name" => "Export",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds a page that you can use to export your wiki as a .zip file. Uses \$settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.",
"id" => "page-export",
"code" => function() {
add_action("export", function() {
global $settings, $pageindex, $isadmin;
if($settings->export_allow_only_admins && !$isadmin)
{
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>."));
}
$tmpfilename = tempnam(sys_get_temp_dir(), "pepperminty-wiki-");
$zip = new ZipArchive();
if($zip->open($tmpfilename, ZipArchive::CREATE) !== true)
{
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."));
}
foreach($pageindex as $entry)
{
$zip->addFile("./$entry->filename", $entry->filename);
}
if($zip->close() !== true)
{
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."));
}
header("content-type: application/zip");
header("content-disposition: attachment; filename=$settings->sitename-export.zip");
header("content-length: " . filesize($tmpfilename));
$zip_handle = fopen($tmpfilename, "rb");
fpassthru($zip_handle);
fclose($zip_handle);
unlink($tmpfilename);
});
}
]);
?>
<?php
register_module([
"name" => "Export",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds a page that you can use to export your wiki as a .zip file. Uses \$settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.",
"id" => "page-export",
"code" => function() {
add_action("export", function() {
global $settings, $pageindex, $isadmin;
if($settings->export_allow_only_admins && !$isadmin)
{
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>."));
}
$tmpfilename = tempnam(sys_get_temp_dir(), "pepperminty-wiki-");
$zip = new ZipArchive();
if($zip->open($tmpfilename, ZipArchive::CREATE) !== true)
{
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."));
}
foreach($pageindex as $entry)
{
$zip->addFile("./$entry->filename", $entry->filename);
}
if($zip->close() !== true)
{
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."));
}
header("content-type: application/zip");
header("content-disposition: attachment; filename=$settings->sitename-export.zip");
header("content-length: " . filesize($tmpfilename));
$zip_handle = fopen($tmpfilename, "rb");
fpassthru($zip_handle);
fclose($zip_handle);
unlink($tmpfilename);
});
}
]);
?>

View file

@ -1,61 +1,61 @@
<?php
register_module([
"name" => "Help page",
"version" => "0.6",
"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>~~Strikethrough~~</code></td><td><del>Strikethough</del></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>## 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>&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>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>
---
</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>-->
<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>
<p>In addition, the following extra syntax is supported for images:</p>
<pre><code>Size the image to at most 250 pixels wide:
![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:
![Alt text](//starbeamrainbowlabs.com/favicon-small.png 120px right)</code></pre>
<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(page_renderer::render_main($title, $content));
});
}
]);
?>
<?php
register_module([
"name" => "Help page",
"version" => "0.6",
"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>~~Strikethrough~~</code></td><td><del>Strikethough</del></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>## 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>&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>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>
---
</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>-->
<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>
<p>In addition, the following extra syntax is supported for images:</p>
<pre><code>Size the image to at most 250 pixels wide:
![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:
![Alt text](//starbeamrainbowlabs.com/favicon-small.png 120px right)</code></pre>
<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(page_renderer::render_main($title, $content));
});
}
]);
?>

View file

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

View file

@ -1,83 +1,83 @@
<?php
register_module([
"name" => "Login",
"version" => "0.5",
"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' id='user' />
<br />
<label for='pass'>Password:</label>
<input type='password' name='pass' id='pass' />
<br />
<input type='submit' value='Login' />
</form>";
exit(page_renderer::render_main($title, $content));
});
/*
* _ _ _ _
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
* | (__| | | | __/ (__| <| | (_) | (_| | | | | |
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
* %checklogin% |___/
*/
add_action("checklogin", function() {
global $settings;
//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();
}
});
}
]);
?>
<?php
register_module([
"name" => "Login",
"version" => "0.5",
"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' id='user' />
<br />
<label for='pass'>Password:</label>
<input type='password' name='pass' id='pass' />
<br />
<input type='submit' value='Login' />
</form>";
exit(page_renderer::render_main($title, $content));
});
/*
* _ _ _ _
* ___| |__ ___ ___| | _| | ___ __ _(_)_ __
* / __| '_ \ / _ \/ __| |/ / |/ _ \ / _` | | '_ \
* | (__| | | | __/ (__| <| | (_) | (_| | | | | |
* \___|_| |_|\___|\___|_|\_\_|\___/ \__, |_|_| |_|
* %checklogin% |___/
*/
add_action("checklogin", function() {
global $settings;
//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();
}
});
}
]);
?>

View file

@ -1,24 +1,24 @@
<?php
register_module([
"name" => "Logout",
"version" => "0.5",
"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(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>"));
});
}
]);
?>
<?php
register_module([
"name" => "Logout",
"version" => "0.5",
"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(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>"));
});
}
]);
?>

View file

@ -1,64 +1,64 @@
<?php
register_module([
"name" => "Page mover",
"version" => "0.5",
"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(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><a href='index.php?page=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>"));
}
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>
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
}
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
exit(page_renderer::render_main("Moving $page", "<h2>Moving $page</h2>
<form method='get' action='index.php'>
<input type='hidden' name='action' value='move' />
<label for='old_name'>Old Name:</label>
<input type='text' name='page' value='$page' readonly />
<br />
<label for='new_name'>New Name:</label>
<input type='text' name='new_name' />
<br />
<input type='submit' value='Move Page' />
</form>"));
$new_name = makepathsafe($_GET["new_name"]);
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>
<p>Nothing has been changed.</p>"));
if($page == $new_name)
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
<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>"));
//move the page in the page index
$pageindex->$new_name = new stdClass();
foreach($pageindex->$page as $key => $value)
{
$pageindex->$new_name->$key = $value;
}
unset($pageindex->$page);
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
//move the page on the disk
rename("$page.md", "$new_name.md");
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>"));
});
}
]);
?>
<?php
register_module([
"name" => "Page mover",
"version" => "0.5",
"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(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><a href='index.php?page=$page'>Go back to $page</a>.</p>
<p>Nothing has been changed.</p>"));
}
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>
<p>You should try <a href='index.php?action=login'>logging in</a> as an admin.</p>"));
}
if(!isset($_GET["new_name"]) or strlen($_GET["new_name"]) == 0)
exit(page_renderer::render_main("Moving $page", "<h2>Moving $page</h2>
<form method='get' action='index.php'>
<input type='hidden' name='action' value='move' />
<label for='old_name'>Old Name:</label>
<input type='text' name='page' value='$page' readonly />
<br />
<label for='new_name'>New Name:</label>
<input type='text' name='new_name' />
<br />
<input type='submit' value='Move Page' />
</form>"));
$new_name = makepathsafe($_GET["new_name"]);
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>
<p>Nothing has been changed.</p>"));
if($page == $new_name)
exit(page_renderer::render_main("Moving $page - Error", "<p>You tried to move $page, but the new name you gave is the same as it's current name.</p>
<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>"));
//move the page in the page index
$pageindex->$new_name = new stdClass();
foreach($pageindex->$page as $key => $value)
{
$pageindex->$new_name->$key = $value;
}
unset($pageindex->$page);
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
//move the page on the disk
rename("$page.md", "$new_name.md");
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
register_module([
"name" => "Update",
"version" => "0.6",
"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;
if(!$isadmin)
{
http_response_code(401);
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")
{
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>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>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=''>
<input type='hidden' name='action' value='update' />
<input type='hidden' name='do' value='true' />
<label for='secret'>$settings->sitename's secret code</label>
<input type='text' name='secret' value='' />
<input type='submit' value='Update' />
</form>"));
}
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>"));
}
$settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////";
$log = "Beginning update...\n";
$log .= "I am <code>" . __FILE__ . "</code>.\n";
$oldcode = file_get_contents(__FILE__);
$log .= "Fetching new code...";
$newcode = file_get_contents($settings->updateurl);
$log .= "done.\n";
$log .= "Rewriting <code>" . __FILE__ . "</code>...";
$settings = substr($oldcode, 0, strpos($oldcode, $settings_separator));
$code = substr($newcode, strpos($newcode, $settings_separator));
$result = $settings . $code;
$log .= "done.\n";
$log .= "Saving...";
file_put_contents(__FILE__, $result);
$log .= "done.\n";
$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.";
exit(page_renderer::render_main("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>"));
});
}
]);
?>
<?php
register_module([
"name" => "Update",
"version" => "0.6",
"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;
if(!$isadmin)
{
http_response_code(401);
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")
{
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>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>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=''>
<input type='hidden' name='action' value='update' />
<input type='hidden' name='do' value='true' />
<label for='secret'>$settings->sitename's secret code</label>
<input type='text' name='secret' value='' />
<input type='submit' value='Update' />
</form>"));
}
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>"));
}
$settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////";
$log = "Beginning update...\n";
$log .= "I am <code>" . __FILE__ . "</code>.\n";
$oldcode = file_get_contents(__FILE__);
$log .= "Fetching new code...";
$newcode = file_get_contents($settings->updateurl);
$log .= "done.\n";
$log .= "Rewriting <code>" . __FILE__ . "</code>...";
$settings = substr($oldcode, 0, strpos($oldcode, $settings_separator));
$code = substr($newcode, strpos($newcode, $settings_separator));
$result = $settings . $code;
$log .= "done.\n";
$log .= "Saving...";
file_put_contents(__FILE__, $result);
$log .= "done.\n";
$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.";
exit(page_renderer::render_main("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>"));
});
}
]);
?>

View file

@ -1,67 +1,67 @@
<?php
register_module([
"name" => "Page viewer",
"version" => "0.8",
"author" => "Starbeamrainbowlabs",
"description" => "Allows you to view pages. You should include this one.",
"id" => "page-view",
"code" => function() {
add_action("view", function() {
global $pageindex, $settings, $page, $parse_page_source;
// Check to make sure that the page exists
if(!isset($pageindex->$page))
{
// todo make this intelligent so we only redirect if the user is acutally able to create the page
if($settings->editing)
{
// Editing is enabled, redirect to the editing page
http_response_code(307); // Temporary redirect
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($page));
exit();
}
else
{
// Editing is disabled, show an error message
http_response_code(404);
exit(page_renderer::render_main("$page - 404 - $settings->sitename", "<p>$page does not exist.</p><p>Since editing is currently disabled on this wiki, you may not create this page. If you feel that this page should exist, try contacting this wiki's Administrator.</p>"));
}
}
$title = "$page - $settings->sitename";
$content = "<h1>$page</h1>";
$parsing_start = microtime(true);
$content .= $parse_page_source(file_get_contents("$page.md"));
if($settings->show_subpages)
{
$subpages = get_object_vars(get_subpages($pageindex, $page));
if(count($subpages) > 0)
{
$content .= "<hr />";
$content .= "Subpages: ";
foreach($subpages as $subpage => $times_removed)
{
if($times_removed <= $settings->subpages_display_depth)
{
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
}
}
// Remove the last comma from the content
$content = substr($content, 0, -2);
}
}
$content .= "\n\t\t<!-- Took " . (microtime(true) - $parsing_start) . " seconds to parse page source -->\n";
if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
exit(page_renderer::render_minimal($title, $content));
else
exit(page_renderer::render_main($title, $content));
});
}
]);
?>
<?php
register_module([
"name" => "Page viewer",
"version" => "0.8",
"author" => "Starbeamrainbowlabs",
"description" => "Allows you to view pages. You should include this one.",
"id" => "page-view",
"code" => function() {
add_action("view", function() {
global $pageindex, $settings, $page, $parse_page_source;
// Check to make sure that the page exists
if(!isset($pageindex->$page))
{
// todo make this intelligent so we only redirect if the user is acutally able to create the page
if($settings->editing)
{
// Editing is enabled, redirect to the editing page
http_response_code(307); // Temporary redirect
header("location: index.php?action=edit&newpage=yes&page=" . rawurlencode($page));
exit();
}
else
{
// Editing is disabled, show an error message
http_response_code(404);
exit(page_renderer::render_main("$page - 404 - $settings->sitename", "<p>$page does not exist.</p><p>Since editing is currently disabled on this wiki, you may not create this page. If you feel that this page should exist, try contacting this wiki's Administrator.</p>"));
}
}
$title = "$page - $settings->sitename";
$content = "<h1>$page</h1>";
$parsing_start = microtime(true);
$content .= $parse_page_source(file_get_contents("$page.md"));
if($settings->show_subpages)
{
$subpages = get_object_vars(get_subpages($pageindex, $page));
if(count($subpages) > 0)
{
$content .= "<hr />";
$content .= "Subpages: ";
foreach($subpages as $subpage => $times_removed)
{
if($times_removed <= $settings->subpages_display_depth)
{
$content .= "<a href='?action=view&page=" . rawurlencode($subpage) . "'>$subpage</a>, ";
}
}
// Remove the last comma from the content
$content = substr($content, 0, -2);
}
}
$content .= "\n\t\t<!-- Took " . (microtime(true) - $parsing_start) . " seconds to parse page source -->\n";
if(isset($_GET["printable"]) and $_GET["printable"] === "yes")
exit(page_renderer::render_minimal($title, $content));
else
exit(page_renderer::render_main($title, $content));
});
}
]);
?>

View file

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

View file

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

View file

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