1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Add better errors by phperror.nnet

This commit is contained in:
Starbeamrainbowlabs 2015-11-09 07:08:37 +00:00
parent 5e28a9e98e
commit 0f18dcdc82
4 changed files with 4911 additions and 63 deletions

View file

@ -1,6 +1,14 @@
<?php <?php
$start_time = time(true); $start_time = time(true);
// For debugging purposes. Remove or comment out for live sites.
// This will always be commented out for a release.
if(file_exists("php_error.php"))
{
require("php_error.php");
\php_error\reportErrors([ "error_reporting_on" => E_ALL | E_STRICT ]);
}
/* /*
* Pepperminty Wiki * Pepperminty Wiki
@ -46,10 +54,10 @@ $settings->sitesecret = "ed420502615bac9037f8f12abd4c9f02";
// The directory in which to store all files, except this main index.php. // The directory in which to store all files, except this main index.php.
// A single dot ('.') denotes the current directory. // A single dot ('.') denotes the current directory.
// Remember to leave the trailing slash from the directory name, as it is added // Remember to omit the trailing slash from the directory name, as it is added
// automatically by Pepperminty Wiki. // automatically by Pepperminty Wiki.
// Note that this setting is currently experimental. // Note that this setting is currently experimental.
$settings->data_storage_dir = "."; $settings->data_storage_dir = "../data_test";
// Determined whether edit is enabled. Set to false to disable disting for all // Determined whether edit is enabled. Set to false to disable disting for all
// users (anonymous or otherwise). // users (anonymous or otherwise).
@ -1155,7 +1163,7 @@ register_module([
register_module([ register_module([
"name" => "Page protection", "name" => "Page protection",
"version" => "0.1", "version" => "0.2",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.", "description" => "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.",
"id" => "action-protect", "id" => "action-protect",
@ -1189,7 +1197,7 @@ register_module([
} }
// Save the pageindex // Save the pageindex
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
$state = ($pageindex->$page->protect ? "enabled" : "disabled"); $state = ($pageindex->$page->protect ? "enabled" : "disabled");
$title = "Page protection $state."; $title = "Page protection $state.";
@ -1208,7 +1216,7 @@ register_module([
register_module([ register_module([
"name" => "Raw page source", "name" => "Raw page source",
"version" => "0.3", "version" => "0.4",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds a 'raw' action that shows you the raw source of a page.", "description" => "Adds a 'raw' action that shows you the raw source of a page.",
"id" => "action-raw", "id" => "action-raw",
@ -1219,7 +1227,7 @@ register_module([
http_response_code(307); http_response_code(307);
header("x-filename: " . rawurlencode($env->page) . ".md"); header("x-filename: " . rawurlencode($env->page) . ".md");
header("content-type: text/markdown"); header("content-type: text/markdown");
exit(file_get_contents("$env->page.md")); exit(file_get_contents("$env->storage_prefix$env->page.md"));
exit(); exit();
}); });
} }
@ -1372,7 +1380,7 @@ register_module([
register_module([ register_module([
"name" => "Search", "name" => "Search",
"version" => "0.1", "version" => "0.2",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.", "description" => "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
"id" => "feature-search", "id" => "feature-search",
@ -1384,7 +1392,7 @@ register_module([
header("content-type: text/plain"); header("content-type: text/plain");
$source = file_get_contents("$env->page.md"); $source = file_get_contents("$env->storage_prefix$env->page.md");
$index = search::index($source); $index = search::index($source);
@ -1406,7 +1414,7 @@ register_module([
$search_start = microtime(true); $search_start = microtime(true);
$invindex = search::load_invindex("invindex.json"); $invindex = search::load_invindex($paths->searchindex);
$results = search::query_invindex($_GET["query"], $invindex); $results = search::query_invindex($_GET["query"], $invindex);
$search_end = microtime(true) - $search_start; $search_end = microtime(true) - $search_start;
@ -1436,7 +1444,7 @@ register_module([
foreach($results as $result) foreach($results as $result)
{ {
$link = "?page=" . rawurlencode($result["pagename"]); $link = "?page=" . rawurlencode($result["pagename"]);
$pagesource = file_get_contents($result["pagename"] . ".md"); $pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
$context = search::extract_context($_GET["query"], $pagesource); $context = search::extract_context($_GET["query"], $pagesource);
$context = search::highlight_context($_GET["query"], $context); $context = search::highlight_context($_GET["query"], $context);
/*if(strlen($context) == 0) /*if(strlen($context) == 0)
@ -1563,7 +1571,7 @@ class search
$invindex = []; $invindex = [];
foreach($pageindex as $pagename => $pagedetails) foreach($pageindex as $pagename => $pagedetails)
{ {
$pagesource = file_get_contents("$pagename.md"); $pagesource = file_get_contents("$env->storage_prefix$pagename.md");
$index = self::index($pagesource); $index = self::index($pagesource);
self::merge_into_invindex($invindex, ids::getid($pagename), $index); self::merge_into_invindex($invindex, ids::getid($pagename), $index);
@ -1836,7 +1844,7 @@ class search
register_module([ register_module([
"name" => "Uploader", "name" => "Uploader",
"version" => "0.1", "version" => "0.2",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.", "description" => "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
"id" => "feature-upload", "id" => "feature-upload",
@ -1927,7 +1935,7 @@ register_module([
$file_extension = system_mime_type_extension($mime_type); $file_extension = system_mime_type_extension($mime_type);
$new_filename = "Files/$target_name.$file_extension"; $new_filename = "$paths->upload_file_prefix$target_name.$file_extension";
$new_description_filename = "$new_filename.md"; $new_description_filename = "$new_filename.md";
if(isset($pageindex->$new_filename)) if(isset($pageindex->$new_filename))
@ -1936,20 +1944,19 @@ register_module([
if(!file_exists("Files")) if(!file_exists("Files"))
mkdir("Files", 0664); mkdir("Files", 0664);
if(!move_uploaded_file($temp_filename, $new_filename)) if(!move_uploaded_file($temp_filename, $env->storage_prefix . $new_filename))
{ {
http_response_code(409); http_response_code(409);
exit(page_renderer::render("Upload Error - $settings->sitename", "<p>The file you uploaded was valid, but $settings->sitename couldn't verify that it was tampered with during the upload process. This probably means that $settings->sitename has been attacked. Please contact " . $settings->admindetails . ", your $settings->sitename Administrator.</p>")); exit(page_renderer::render("Upload Error - $settings->sitename", "<p>The file you uploaded was valid, but $settings->sitename couldn't verify that it was tampered with during the upload process. This probably means that $settings->sitename has been attacked. Please contact " . $settings->admindetails . ", your $settings->sitename Administrator.</p>"));
} }
file_put_contents($new_description_filename, $_POST["description"]);
$description = $_POST["description"]; $description = $_POST["description"];
// Escape the raw html in the provided description if the setting is enabled
if($settings->clean_raw_html) if($settings->clean_raw_html)
$description = htmlentities($description, ENT_QUOTES); $description = htmlentities($description, ENT_QUOTES);
file_put_contents($new_description_filename, $description); file_put_contents($env->storage_prefix . $new_description_filename, $description);
// Construct a new entry for the pageindex // Construct a new entry for the pageindex
$entry = new stdClass(); $entry = new stdClass();
@ -1968,7 +1975,7 @@ register_module([
$pageindex->$new_filename = $entry; $pageindex->$new_filename = $entry;
// Save the pageindex // Save the pageindex
file_put_contents("pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
header("location: ?action=view&page=$new_filename&upload=success"); header("location: ?action=view&page=$new_filename&upload=success");
@ -1978,9 +1985,25 @@ register_module([
add_action("preview", function() { add_action("preview", function() {
global $settings, $env, $pageindex; global $settings, $env, $pageindex;
$filepath = $pageindex->{$env->page}->uploadedfilepath; $filepath = $env->storage_prefix . $pageindex->{$env->page}->uploadedfilepath;
$mime_type = $pageindex->{$env->page}->uploadedfilemime; $mime_type = $pageindex->{$env->page}->uploadedfilemime;
if(isset($_GET["size"]) and $_GET["size"] == "original")
{
// Get the file size
$filesize = filesize($filepath);
// Send some headers
header("content-length: $filesize");
header("content-type: $mime_type");
// Open the file and send it to the user
$handle = fopen($filepath, "rb");
fpassthru($handle);
fclose($handle);
exit();
}
// Determine the target size of the image // Determine the target size of the image
$target_size = 512; $target_size = 512;
if(isset($_GET["size"])) if(isset($_GET["size"]))
@ -2055,6 +2078,8 @@ register_module([
$filepath = $pageindex->{$env->page}->uploadedfilepath; $filepath = $pageindex->{$env->page}->uploadedfilepath;
$mime_type = $pageindex->{$env->page}->uploadedfilemime; $mime_type = $pageindex->{$env->page}->uploadedfilemime;
$image_link = "//" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . $filepath; $image_link = "//" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . $filepath;
if($env->storage_prefix !== "./")
$image_link = "?action=preview&size=original&page=" . rawurlencode($env->page);
$preview_sizes = [ 256, 512, 768, 1024, 1536 ]; $preview_sizes = [ 256, 512, 768, 1024, 1536 ];
$preview_html = "<figure class='preview'> $preview_html = "<figure class='preview'>
@ -2241,7 +2266,7 @@ register_module([
register_module([ register_module([
"name" => "Page deleter", "name" => "Page deleter",
"version" => "0.7", "version" => "0.8",
"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",
@ -2270,11 +2295,11 @@ register_module([
// Delete the associated file if it exists // Delete the associated file if it exists
if(!empty($pageindex->$page->uploadedfile)) if(!empty($pageindex->$page->uploadedfile))
{ {
unlink($pageindex->$page->uploadedfilepath); unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
} }
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($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); //save the new page index
unlink("./$env->page.md"); //delete the page from the disk unlink("$env->storage_prefix$env->page.md"); //delete the page from the disk
exit(page_renderer::render_main("Deleting $env->page - $settings->sitename", "<p>$env->page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>")); exit(page_renderer::render_main("Deleting $env->page - $settings->sitename", "<p>$env->page has been deleted. <a href='index.php'>Go back to the main page</a>.</p>"));
}); });
@ -2286,7 +2311,7 @@ register_module([
register_module([ register_module([
"name" => "Page editor", "name" => "Page editor",
"version" => "0.11", "version" => "0.12",
"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",
@ -2304,7 +2329,7 @@ register_module([
add_action("edit", function() { add_action("edit", function() {
global $pageindex, $settings, $env; global $pageindex, $settings, $env;
$filename = "$env->page.md"; $filename = "$env->storage_prefix$env->page.md";
$page = $env->page; $page = $env->page;
$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)
@ -2389,7 +2414,7 @@ register_module([
{ {
http_response_code(403); http_response_code(403);
header("refresh: 5; url=index.php?page=$env->page"); header("refresh: 5; url=index.php?page=$env->page");
exit("$env->page is protected, and you aren't logged in as an administrastor or moderator. Your edit was not saved. Redirecting in 5 seconds..."); exit("$env->page is protected, and you aren't logged in as an administrator or moderator. Your edit was not saved. Redirecting in 5 seconds...");
} }
if(!isset($_POST["content"])) if(!isset($_POST["content"]))
{ {
@ -2399,10 +2424,10 @@ register_module([
} }
// 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("$env->page.md"))) if(!is_dir(dirname("$env->storage_prefix$env->page.md")))
{ {
// Recursively create the directory if needed // Recursively create the directory if needed
mkdir(dirname("$env->page.md"), null, true); mkdir(dirname("$env->storage_prefix$env->page.md"), null, true);
} }
// Read in the new page content // Read in the new page content
@ -2440,7 +2465,7 @@ register_module([
if(file_put_contents("$env->page.md", $pagedata) !== false) if(file_put_contents("$env->storage_prefix$env->page.md", $pagedata) !== false)
{ {
$page = $env->page; $page = $env->page;
// Make sure that this page's parents exist // Make sure that this page's parents exist
@ -2472,10 +2497,10 @@ register_module([
} }
if($pagedata !== $pagedata_orig) if($pagedata !== $pagedata_orig)
file_put_contents("$env->page.md", $pagedata); file_put_contents("$env->storage_prefix$env->page.md", $pagedata);
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
if(isset($_GET["newpage"])) if(isset($_GET["newpage"]))
http_response_code(201); http_response_code(201);
@ -2501,7 +2526,7 @@ register_module([
register_module([ register_module([
"name" => "Export", "name" => "Export",
"version" => "0.2", "version" => "0.3",
"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",
@ -2527,7 +2552,7 @@ register_module([
foreach($pageindex as $entry) foreach($pageindex as $entry)
{ {
$zip->addFile("./$entry->filename", $entry->filename); $zip->addFile("$env->storage_prefix$entry->filename", $entry->filename);
} }
if($zip->close() !== true) if($zip->close() !== true)
@ -2888,12 +2913,12 @@ register_module([
// Move the file in the pageindex // Move the file in the pageindex
$pageindex->$new_name->uploadedfilepath = $new_name; $pageindex->$new_name->uploadedfilepath = $new_name;
// Move the file on disk // Move the file on disk
rename($env->page, $new_name); rename($env->storage_prefix . $env->page, $env->storage_prefix . $new_name);
} }
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("$env->page.md", "$new_name.md"); rename("$env->storage_prefix$env->page.md", "$env->storage_prefix$new_name.md");
exit(page_renderer::render_main("Moving $env->page", "<p><a href='index.php?page=$env->page'>$env->page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>")); exit(page_renderer::render_main("Moving $env->page", "<p><a href='index.php?page=$env->page'>$env->page</a> has been moved to <a href='index.php?page=$new_name'>$new_name</a> successfully.</p>"));
}); });
@ -3028,9 +3053,8 @@ register_module([
$parsing_start = microtime(true); $parsing_start = microtime(true);
$content .= parse_page_source(file_get_contents("$env->page.md")); $content .= parse_page_source(file_get_contents("$env->storage_prefix$env->page.md"));
// todo display tags here
if(!empty($pageindex->$page->tags)) if(!empty($pageindex->$page->tags))
{ {
$content .= "<ul class='page-tags-display'>\n"; $content .= "<ul class='page-tags-display'>\n";

View file

@ -1,6 +1,14 @@
<?php <?php
$start_time = time(true); $start_time = time(true);
// For debugging purposes. Remove or comment out for live sites.
// This will always be commented out for a release.
if(file_exists("php_error.php"))
{
require("php_error.php");
\php_error\reportErrors([ "error_reporting_on" => E_ALL | E_STRICT ]);
}
{settings} {settings}
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -10,20 +10,20 @@
}, },
{ {
"name": "Page protection", "name": "Page protection",
"version": "0.1", "version": "0.2",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.", "description": "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.",
"id": "action-protect", "id": "action-protect",
"lastupdate": 1445170746, "lastupdate": 1446975126,
"optional": false "optional": false
}, },
{ {
"name": "Raw page source", "name": "Raw page source",
"version": "0.3", "version": "0.4",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds a 'raw' action that shows you the raw source of a page.", "description": "Adds a 'raw' action that shows you the raw source of a page.",
"id": "action-raw", "id": "action-raw",
"lastupdate": 1445170746, "lastupdate": 1446975142,
"optional": false "optional": false
}, },
{ {
@ -46,20 +46,20 @@
}, },
{ {
"name": "Search", "name": "Search",
"version": "0.1", "version": "0.2",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.", "description": "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
"id": "feature-search", "id": "feature-search",
"lastupdate": 1446717614, "lastupdate": 1446975588,
"optional": false "optional": false
}, },
{ {
"name": "Uploader", "name": "Uploader",
"version": "0.1", "version": "0.2",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.", "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
"id": "feature-upload", "id": "feature-upload",
"lastupdate": 1445716955, "lastupdate": 1447002760,
"optional": false "optional": false
}, },
{ {
@ -73,29 +73,29 @@
}, },
{ {
"name": "Page deleter", "name": "Page deleter",
"version": "0.7", "version": "0.8",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to delete pages.", "description": "Adds an action to allow administrators to delete pages.",
"id": "page-delete", "id": "page-delete",
"lastupdate": 1445771075, "lastupdate": 1447002847,
"optional": false "optional": false
}, },
{ {
"name": "Page editor", "name": "Page editor",
"version": "0.11", "version": "0.12",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit", "id": "page-edit",
"lastupdate": 1446388267, "lastupdate": 1447002999,
"optional": false "optional": false
}, },
{ {
"name": "Export", "name": "Export",
"version": "0.2", "version": "0.3",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds a page that you can use to export your wiki as a .zip file. Uses $settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.", "description": "Adds a page that you can use to export your wiki as a .zip file. Uses $settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.",
"id": "page-export", "id": "page-export",
"lastupdate": 1445170746, "lastupdate": 1447003197,
"optional": false "optional": false
}, },
{ {
@ -140,7 +140,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to move pages.", "description": "Adds an action to allow administrators to move pages.",
"id": "page-move", "id": "page-move",
"lastupdate": 1445771483, "lastupdate": 1447017276,
"optional": false "optional": false
}, },
{ {
@ -158,7 +158,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You reallyshould include this one.", "description": "Allows you to view pages. You reallyshould include this one.",
"id": "page-view", "id": "page-view",
"lastupdate": 1445789184, "lastupdate": 1447052018,
"optional": false "optional": false
}, },
{ {

4816
php_error.php Normal file

File diff suppressed because one or more lines are too long