[protected with javascript]";
}
+
/**
* Checks to see if $haystack starts with $needle.
* @package core
@@ -303,10 +327,22 @@ function hide_email($str)
* of $haystack.
* @return bool Whether $needle can be found at the beginning of $haystack.
*/
-function starts_with($haystack, $needle) {
+function starts_with(string $haystack, string $needle) : bool {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
+/**
+ * Checks to see if $hackstack ends with $needle.
+ * The matching bookend to starts_with.
+ * @package core
+ * @param string $haystack The haystack to search..
+ * @param string $needle The needle to look for.
+ * @return bool
+ */
+function ends_with(string $haystack, string $needle) : bool {
+ $length = strlen($needle);
+ return (substr($haystack, -$length) === $needle);
+}
/**
* Case-insensitively finds all occurrences of $needle in $haystack. Handles
diff --git a/core/20-pageindex-loader.php b/core/20-pageindex-loader.php
index a973f67..984fea6 100644
--- a/core/20-pageindex-loader.php
+++ b/core/20-pageindex-loader.php
@@ -22,25 +22,21 @@ if(!file_exists($paths->pageindex))
// Create a new entry
$newentry = new stdClass();
- $newentry->filename = substr( // Store the filename, whilst trimming the storage prefix
+ $newentry->filename = mb_substr( // Store the filename, whilst trimming the storage prefix
$pagefilename,
mb_strlen(preg_replace("/^\.\//iu", "", $env->storage_prefix)) // glob_recursive trim the ./ from returned filenames , so we need to as well
);
// Remove the `./` from the beginning if it's still hanging around
- if(substr($newentry->filename, 0, 2) == "./")
- $newentry->filename = substr($newentry->filename, 2);
+ if(mb_substr($newentry->filename, 0, 2) == "./")
+ $newentry->filename = mb_substr($newentry->filename, 2);
$newentry->size = filesize($pagefilename); // Store the page size
$newentry->lastmodified = filemtime($pagefilename); // Store the date last modified
// Todo find a way to keep the last editor independent of the page index
$newentry->lasteditor = "unknown"; // Set the editor to "unknown"
-
-
- // POTENTIAL BUG: If $env->storage_prefix is not ., then this we need to be more intelligent here
-
-
// Extract the name of the (sub)page without the ".md"
- $pagekey = mb_substr($newentry->filename, 0, -3);
+ $pagekey = filepath_to_pagename($newentry->filename);
+ error_log("pagename '$newentry->filename' → filepath '$pagekey'");
if(file_exists($env->storage_prefix . $pagekey) && // If it exists...
!is_dir($env->storage_prefix . $pagekey)) // ...and isn't a directory
@@ -84,6 +80,7 @@ if(!file_exists($paths->pageindex))
}
}
+ // If the initial revision doesn't exist on disk, create it (if it does, then we handle that later)
if(function_exists("history_add_revision") && !file_exists("{$pagefilename}.r0")) { // Can't use module_exists - too early
copy($pagefilename, "{$pagefilename}.r0");
$newentry->history = [ (object) [
@@ -103,16 +100,46 @@ if(!file_exists($paths->pageindex))
if(function_exists("history_add_revision")) {
$history_revs = glob_recursive($env->storage_prefix . "*.r*");
+ // It's very important that we read the history revisions in the right order and that we don't skip any
+ usort($history_revs, function($a, $b) {
+ preg_match("/[0-9]+$/", $a, $revid_a);
+ $revid_a = intval($revid_a[0]);
+ preg_match("/[0-9]+$/", $b, $revid_b);
+ $revid_b = intval($revid_b[0]);
+ return $revid_a - $revid_b;
+ });
+ // We can guarantee that the direcotry separator is present on the end - it's added explicitly earlier
+ $strlen_storageprefix = strlen($env->storage_prefix);
foreach($history_revs as $filename) {
- preg_match("/[0-9]+$/", "Main Page.md.r0", $revid);
+ preg_match("/[0-9]+$/", $filename, $revid);
+ error_log("raw revid | ".var_export($revid, true));
if(count($revid) === 0) continue;
$revid = intval($revid[0]);
- // TODO: Extract the pagename here (maybe a function is worth implementing if we haven't already?)
+ $pagename = filepath_to_pagename($filename);
+ $filepath_stripped = substr($filename, $strlen_storageprefix);
- if($revid == 0 && ) {
-
+ if(!isset($pageindex->$pagename->history))
+ $pageindex->$pagename->history = [];
+
+ if(isset($pageindex->$pagename->history[$revid]))
+ continue;
+
+ error_log("pagename: $pagename, revid: $revid, pageindex entry: ".var_export($pageindex->$pagename, true));
+ $newsize = filesize($filename);
+ $prevsize = 0;
+ if($revid > 0 && isset($pageindex->$pagename->history[$revid - 1])) {
+ $prevsize = filesize(end($pageindex->$pagename->history)->filename);
}
+ $pageindex->$pagename->history[$revid] = (object) [
+ "type" => "edit",
+ "rid" => $revid,
+ "timestamp" => filemtime($filename),
+ "filename" => $filepath_stripped,
+ "newsize" => $newsize,
+ "sizediff" => $newsize - $prevsize,
+ "editor" => "unknown"
+ ];
}
}
diff --git a/core/40-page-renderer.php b/core/40-page-renderer.php
index 78710cd..76c4075 100644
--- a/core/40-page-renderer.php
+++ b/core/40-page-renderer.php
@@ -44,7 +44,7 @@ class page_renderer
{footer-message}
Powered by Pepperminty Wiki {version}, which was built by Starbeamrainbowlabs. Send bugs to 'bugs at starbeamrainbowlabs dot com' or open an issue.
Your local friendly moderators are {admins-name-list}.
- This wiki is managed by {admin-details-name}.
+ This wiki is managed by {admin-details}.
{navigation-bar-bottom}
{all-pages-datalist}";
@@ -128,8 +128,7 @@ class page_renderer
if(!is_callable($function))
{
http_response_code(500);
- $admin_email = hide_email($settings->admindetails_email);
- exit(page_renderer::render("$settings->sitename - Module Error", "$settings->sitename has got a misbehaving module installed that tried to register an invalid HTML handler with the page renderer. Please contact $settings->sitename's administrator {$settings->admindetails_name} at $admin_email."));
+ exit(page_renderer::render("$settings->sitename - Module Error", "
$settings->sitename has got a misbehaving module installed that tried to register an invalid HTML handler with the page renderer. Please contact $settings->sitename's administrator {$settings->admindetails_name} at ".hide_email($settings->admindetails_email)."."));
}
self::$part_processors[] = $function;
@@ -187,8 +186,8 @@ class page_renderer
"{navigation-bar}" => self::render_navigation_bar($settings->nav_links, $settings->nav_links_extra, "top"),
"{navigation-bar-bottom}" => self::render_navigation_bar($settings->nav_links_bottom, [], "bottom"),
+ "{admin-details}" => hide_email($settings->admindetails_email, $settings->admindetails_name),
"{admin-details-name}" => $settings->admindetails_name,
- "{admin-details-email}" => $settings->admindetails_email,
"{admins-name-list}" => implode(", ", array_map(function($username) { return page_renderer::render_username($username); }, $settings->admins)),
diff --git a/core/70-parser-engine.php b/core/70-parser-engine.php
index 9d003cb..293f867 100644
--- a/core/70-parser-engine.php
+++ b/core/70-parser-engine.php
@@ -45,7 +45,7 @@ function parse_page_source($source, $untrusted = false, $use_cache = true) {
if(!$settings->parser_cache || strlen($source) < $settings->parser_cache_min_size) $use_cache = false;
if(!isset($parsers[$settings->parser]))
- exit(page_renderer::render_main("Parsing error - $settings->sitename", "
Parsing some page source data failed. This is most likely because $settings->sitename has the parser setting set incorrectly. Please contact " . $settings->admindetails_name . ", your $settings->sitename Administrator."));
+ exit(page_renderer::render_main("Parsing error - $settings->sitename", "
Parsing some page source data failed. This is most likely because $settings->sitename has the parser setting set incorrectly. Please contact " . hide_email($settings->admindetails_email, $settings->admindetails_name) . ", $settings->sitename's Administrator."));
/* Not needed atm because escaping happens when saving, not when rendering *
if($settings->clean_raw_html)
diff --git a/modules/feature-comments.php b/modules/feature-comments.php
index d89af84..4640848 100644
--- a/modules/feature-comments.php
+++ b/modules/feature-comments.php
@@ -1,7 +1,7 @@
"Page Comments",
- "version" => "0.3.2",
+ "version" => "0.3.3",
"author" => "Starbeamrainbowlabs",
"description" => "Adds threaded comments to the bottom of every page.",
"id" => "feature-comments",
@@ -67,7 +67,7 @@ register_module([
if(!file_exists($comment_filename)) {
if(file_put_contents($comment_filename, "[]\n") === false) {
http_response_code(503);
- exit(page_renderer::renderer_main("Error posting comment - $settings->sitename", "
$settings->sitename ran into a problem whilst creating a file to save your comment to! Please contact $settings->admindetails_name, $settings->sitename's administrator and tell them about this problem.
"));
+ exit(page_renderer::renderer_main("Error posting comment - $settings->sitename", "$settings->sitename ran into a problem whilst creating a file to save your comment to! Please contact " . hide_email($settings->admindetails_email, $settings->admindetails_name) . ", $settings->sitename's administrator and tell them about this problem.
"));
}
}
@@ -120,7 +120,7 @@ register_module([
// Save the comments back to disk
if(file_put_contents($comment_filename, json_encode($comment_data, JSON_PRETTY_PRINT)) === false) {
http_response_code(503);
- exit(page_renderer::renderer_main("Error posting comment - $settings->sitename", "$settings->sitename ran into a problem whilst saving your comment to disk! Please contact $settings->admindetails_name, $settings->sitename's administrator and tell them about this problem.
"));
+ exit(page_renderer::renderer_main("Error posting comment - $settings->sitename", "$settings->sitename ran into a problem whilst saving your comment to disk! Please contact " . hide_email($settings->admindetails_email, $settings->admindetails_name) . ", $settings->sitename's administrator and tell them about this problem.
"));
}
// Add a recent change if the recent changes module is installed
@@ -198,7 +198,7 @@ register_module([
if(!file_put_contents($comment_filename, json_encode($comments))) {
http_response_code(503);
- exit(page_renderer::render_main("Server Error - Deleting Comment - $settings->sitename", "While $settings->sitename was able to delete the comment with the id " . htmlentities($target_id) . "
on the page $env->page, it couldn't save the changes back to disk. Please contact $settings->admindetails_name, $settings->sitename's local friendly administrator about this issue.
"));
+ exit(page_renderer::render_main("Server Error - Deleting Comment - $settings->sitename", "While $settings->sitename was able to delete the comment with the id " . htmlentities($target_id) . "
on the page $env->page, it couldn't save the changes back to disk. Please contact " . hide_email($settings->admindetails_email, $settings->admindetails_name) . ", $settings->sitename's local friendly administrator about this issue.
"));
}
exit(page_renderer::render_main("Comment Deleted - $settings->sitename", "The comment with the id " . htmlentities($target_id) . "
on the page $env->page has been deleted successfully. Go back to " . htmlentities($env->page) . ".
"));
diff --git a/modules/feature-readingtime.php b/modules/feature-readingtime.php
index da23c87..bb01b7b 100644
--- a/modules/feature-readingtime.php
+++ b/modules/feature-readingtime.php
@@ -1,7 +1,7 @@
"Reading time estimator",
- "version" => "0.1",
+ "version" => "0.2",
"author" => "Starbeamrainbowlabs",
"description" => "Displays the approximate reading time for a page beneath it's title.",
"id" => "feature-readingtime",
@@ -44,7 +44,10 @@ register_module([
* @return array An array in the form [ low_time, high_time ] in minutes
*/
function estimate_reading_time(string $text, string $lang = "en") : array {
- $chars_count = mb_strlen($text);
+ $chars_count = mb_strlen(preg_replace("/\s+?/", "", strtr($text, [
+ "[" => "", "]" => "", "(" => "", ")" => "",
+ "|" => "", "#" => "", "*" => ""
+ ])));
$langs = [
"en" => (object) [ "cpm" => 987, "variance" => 118 ],
"ar" => (object) [ "cpm" => 612, "variance" => 88 ],
diff --git a/modules/feature-recent-changes.php b/modules/feature-recent-changes.php
index 817c699..4c66a64 100644
--- a/modules/feature-recent-changes.php
+++ b/modules/feature-recent-changes.php
@@ -305,7 +305,7 @@ function render_recent_change($rchange)
if($rchange_type === "revert")
$resultClasses[] = "reversion";
- $result .= "