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

Debug the pageindex regenerator. Fixes #41.

This commit is contained in:
Starbeamrainbowlabs 2015-11-14 21:24:57 +00:00
parent 0e3a7f345a
commit b139f204b4
5 changed files with 55 additions and 47 deletions

View file

@ -113,7 +113,7 @@ $settings->require_login_view = false;
// Remember to omit 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 = ".";
// Whether to use the new sha3 hashing algorithm that was standardised on the // Whether to use the new sha3 hashing algorithm that was standardised on the
// 8th August 2015. Only works if you have strawbrary's sha3 extension // 8th August 2015. Only works if you have strawbrary's sha3 extension
@ -689,7 +689,11 @@ function system_mime_type_extension($type) {
*/ */
if(!file_exists($paths->pageindex)) if(!file_exists($paths->pageindex))
{ {
$existingpages = glob_recursive($env->storage_prefix . "*.md"); $glob_str = $env->storage_prefix . "*.md";
$existingpages = glob_recursive($glob_str);
var_dump($env->storage_prefix);
var_dump($glob_str);
var_dump($existingpages);
$pageindex = new stdClass(); $pageindex = new stdClass();
// We use a for loop here because foreach doesn't loop over new values inserted // We use a for loop here because foreach doesn't loop over new values inserted
// while we were looping // while we were looping
@ -699,41 +703,40 @@ if(!file_exists($paths->pageindex))
// Create a new entry // Create a new entry
$newentry = new stdClass(); $newentry = new stdClass();
$newentry->filename = utf8_encode(substr($pagefilename, strlen($env->storage_prefix))); // Store the filename $newentry->filename = utf8_encode(substr( // Store the filename, whilst trimming the storage prefix
$pagefilename,
strlen(preg_replace("/^\.\//i", "", $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);
$newentry->size = filesize($pagefilename); // Store the page size $newentry->size = filesize($pagefilename); // Store the page size
$newentry->lastmodified = filemtime($pagefilename); // Store the date last modified $newentry->lastmodified = filemtime($pagefilename); // Store the date last modified
// Todo find a way to keep the last editor independent of the page index // Todo find a way to keep the last editor independent of the page index
$newentry->lasteditor = utf8_encode("unknown"); // Set the editor to "unknown" $newentry->lasteditor = utf8_encode("unknown"); // Set the editor to "unknown"
// Extract the name of the (sub)page without the ".md" or the storage dir // Extract the name of the (sub)page without the ".md"
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3)); $pagekey = utf8_encode(substr($newentry->filename, 0, -3));
// Calculate the position of the last dot in the file name if(file_exists($env->storage_prefix . $pagekey))
$last_dot_pos = strrpos($newentry->filename, ".");
// Keep everything up to the last dot
$uploaded_file_path = substr($newentry->filename, 0, $last_dot_pos);
// Work out the location of the next last dot
$next_dot_pos = strrpos($uploaded_file_path, ".");
if(
// There is another dot in the uploaded file path
$next_dot_pos !== false &&
// This other dot is after the last slash
$next_dot_pos >= strrpos($uploaded_file_path, "/") &&
// The file actually exists
file_exists($env->storage_prefix . $uploaded_file_path))
{ {
// This page (potentially) has an associated file! // This page (potentially) has an associated file!
// Let's investigate. // Let's investigate.
// Blindly add the file to the pageindex for now. // Blindly add the file to the pageindex for now.
// Future We might want to do a security check on the file later on. File a bug if you think this is a good idea. // Future We might want to do a security check on the file later on.
// File a bug if you think we should do this.
$newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it $newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it
$newentry->uploadedfilepath = $uploaded_file_path; // It's stored here $newentry->uploadedfilepath = $pagekey; // It's stored here
// Work out what kind of file it really is // Work out what kind of file it really is
$mimechecker = finfo_open(FILEINFO_MIME_TYPE); $mimechecker = finfo_open(FILEINFO_MIME_TYPE);
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $uploaded_file_path); $newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $pagekey);
} }
echo("pagekey: ");
var_dump($pagekey);
echo("newentry: ");
var_dump($newentry);
// Subpage parent checker // Subpage parent checker
if(strpos($pagekey, "/") !== false) if(strpos($pagekey, "/") !== false)
@ -1957,7 +1960,7 @@ class search
foreach($qterms as $qterm) foreach($qterms as $qterm)
{ {
// From http://stackoverflow.com/a/2483859/1460422 // From http://stackoverflow.com/a/2483859/1460422
$context = preg_replace("/" . preg_quote(str_replace("/", "\/", $qterm)) . "/i", "<strong>$0</strong>", $context); $context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/i", "<strong>$0</strong>", $context);
} }
return $context; return $context;

View file

@ -345,7 +345,12 @@ function system_mime_type_extension($type) {
*/ */
if(!file_exists($paths->pageindex)) if(!file_exists($paths->pageindex))
{ {
$existingpages = glob_recursive($env->storage_prefix . "*.md"); $glob_str = $env->storage_prefix . "*.md";
$existingpages = glob_recursive($glob_str);
// Debug statements. Uncomment when debugging the pageindex regenerator.
// var_dump($env->storage_prefix);
// var_dump($glob_str);
// var_dump($existingpages);
$pageindex = new stdClass(); $pageindex = new stdClass();
// We use a for loop here because foreach doesn't loop over new values inserted // We use a for loop here because foreach doesn't loop over new values inserted
// while we were looping // while we were looping
@ -355,41 +360,41 @@ if(!file_exists($paths->pageindex))
// Create a new entry // Create a new entry
$newentry = new stdClass(); $newentry = new stdClass();
$newentry->filename = utf8_encode(substr($pagefilename, strlen($env->storage_prefix))); // Store the filename $newentry->filename = utf8_encode(substr( // Store the filename, whilst trimming the storage prefix
$pagefilename,
strlen(preg_replace("/^\.\//i", "", $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);
$newentry->size = filesize($pagefilename); // Store the page size $newentry->size = filesize($pagefilename); // Store the page size
$newentry->lastmodified = filemtime($pagefilename); // Store the date last modified $newentry->lastmodified = filemtime($pagefilename); // Store the date last modified
// Todo find a way to keep the last editor independent of the page index // Todo find a way to keep the last editor independent of the page index
$newentry->lasteditor = utf8_encode("unknown"); // Set the editor to "unknown" $newentry->lasteditor = utf8_encode("unknown"); // Set the editor to "unknown"
// Extract the name of the (sub)page without the ".md" or the storage dir // Extract the name of the (sub)page without the ".md"
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3)); $pagekey = utf8_encode(substr($newentry->filename, 0, -3));
// Calculate the position of the last dot in the file name if(file_exists($env->storage_prefix . $pagekey))
$last_dot_pos = strrpos($newentry->filename, ".");
// Keep everything up to the last dot
$uploaded_file_path = substr($newentry->filename, 0, $last_dot_pos);
// Work out the location of the next last dot
$next_dot_pos = strrpos($uploaded_file_path, ".");
if(
// There is another dot in the uploaded file path
$next_dot_pos !== false &&
// This other dot is after the last slash
$next_dot_pos >= strrpos($uploaded_file_path, "/") &&
// The file actually exists
file_exists($env->storage_prefix . $uploaded_file_path))
{ {
// This page (potentially) has an associated file! // This page (potentially) has an associated file!
// Let's investigate. // Let's investigate.
// Blindly add the file to the pageindex for now. // Blindly add the file to the pageindex for now.
// Future We might want to do a security check on the file later on. File a bug if you think this is a good idea. // Future We might want to do a security check on the file later on.
// File a bug if you think we should do this.
$newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it $newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it
$newentry->uploadedfilepath = $uploaded_file_path; // It's stored here $newentry->uploadedfilepath = $pagekey; // It's stored here
// Work out what kind of file it really is // Work out what kind of file it really is
$mimechecker = finfo_open(FILEINFO_MIME_TYPE); $mimechecker = finfo_open(FILEINFO_MIME_TYPE);
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $uploaded_file_path); $newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $pagekey);
} }
// Debug statements. Uncomment when debugging the pageindex regenerator.
// echo("pagekey: ");
// var_dump($pagekey);
// echo("newentry: ");
// var_dump($newentry);
// Subpage parent checker // Subpage parent checker
if(strpos($pagekey, "/") !== false) if(strpos($pagekey, "/") !== false)

View file

@ -50,7 +50,7 @@
"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": 1447520515, "lastupdate": 1447521069,
"optional": false "optional": false
}, },
{ {

View file

@ -472,7 +472,7 @@ class search
foreach($qterms as $qterm) foreach($qterms as $qterm)
{ {
// From http://stackoverflow.com/a/2483859/1460422 // From http://stackoverflow.com/a/2483859/1460422
$context = preg_replace("/" . preg_quote(str_replace("/", "\/", $qterm)) . "/i", "<strong>$0</strong>", $context); $context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/i", "<strong>$0</strong>", $context);
} }
return $context; return $context;

View file

@ -102,7 +102,7 @@ $settings->require_login_view = false;
// Remember to omit 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 = ".";
// Whether to use the new sha3 hashing algorithm that was standardised on the // Whether to use the new sha3 hashing algorithm that was standardised on the
// 8th August 2015. Only works if you have strawbrary's sha3 extension // 8th August 2015. Only works if you have strawbrary's sha3 extension