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

Finish bugfixing #35 - search has been implemented at last!

This commit is contained in:
Starbeamrainbowlabs 2015-12-05 18:59:23 +00:00
parent 29399a379c
commit 71131f973f
4 changed files with 252 additions and 212 deletions

View file

@ -691,9 +691,10 @@ if(!file_exists($paths->pageindex))
{
$glob_str = $env->storage_prefix . "*.md";
$existingpages = glob_recursive($glob_str);
var_dump($env->storage_prefix);
var_dump($glob_str);
var_dump($existingpages);
// Debug statements. Uncomment when debugging the pageindex regenerator.
// var_dump($env->storage_prefix);
// var_dump($glob_str);
// var_dump($existingpages);
$pageindex = new stdClass();
// We use a for loop here because foreach doesn't loop over new values inserted
// while we were looping
@ -717,7 +718,8 @@ if(!file_exists($paths->pageindex))
// Extract the name of the (sub)page without the ".md"
$pagekey = utf8_encode(substr($newentry->filename, 0, -3));
if(file_exists($env->storage_prefix . $pagekey))
if(file_exists($env->storage_prefix . $pagekey) && // If it exists...
!is_dir($env->storage_prefix . $pagekey)) // ...and isn't a directory
{
// This page (potentially) has an associated file!
// Let's investigate.
@ -733,10 +735,11 @@ if(!file_exists($paths->pageindex))
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $pagekey);
}
echo("pagekey: ");
var_dump($pagekey);
echo("newentry: ");
var_dump($newentry);
// Debug statements. Uncomment when debugging the pageindex regenerator.
// echo("pagekey: ");
// var_dump($pagekey);
// echo("newentry: ");
// var_dump($newentry);
// Subpage parent checker
if(strpos($pagekey, "/") !== false)
@ -1194,6 +1197,21 @@ function register_module($moduledata)
//var_dump($moduledata);
$modules[] = $moduledata;
}
/**
* Checks to see whether a module with the given id exists.
* @param string $id The id to search for.
* @return bool Whether a module is currently loaded with the given id.
*/
function module_exists($id)
{
global $modules;
foreach($modules as $module)
{
if($module["id"] == $id)
return true;
}
return false;
}
// Function to register an action handler
$actions = new stdClass();
@ -1518,6 +1536,11 @@ register_module([
add_action("search", function() {
global $settings, $env, $pageindex, $paths;
// Create the inverted index if it doesn't exist.
// todo In the future perhaps a CLI for this would be good?
if(!file_exists($paths->searchindex))
search::rebuild_invindex();
if(!isset($_GET["query"]))
exit(page_renderer::render("No Search Terms - Error - $settings->sitename", "<p>You didn't specify any search terms. Try typing some into the box above.</p>"));
@ -2433,7 +2456,7 @@ register_module([
ids::deletepagename($env->page);
// Delete the page from the search index, if that module is installed
if(isset($modules["feature-search"]))
if(module_exists("feature-search"))
{
$pageid = ids::getid($env->page);
$invindex = search::load_invindex($paths->searchindex);
@ -2508,7 +2531,7 @@ register_module([
else
{
http_response_code(404);
exit(page_renderer::render_main("404 - $env->page", "<p>The page <code>$env->page</code> does not exist, but you do not have permission to create it.</p><p>If you haven't already, perhaps you should try <a href='index.php?action=login'>logging in</a>.</p>"));
exit(page_renderer::render_main("404 - $env->page", "<p>The page <code>$env->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&returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "'>logging in</a>.</p>"));
}
}
@ -2592,6 +2615,8 @@ register_module([
// Update the inverted search index
// Construct an index for the old and new page content
$oldindex = [];
if(file_exists("$env->page.md"))
$oldindex = search::index(file_get_contents("$env->page.md"));
$newindex = search::index($pagedata);

View file

@ -853,6 +853,21 @@ function register_module($moduledata)
//var_dump($moduledata);
$modules[] = $moduledata;
}
/**
* Checks to see whether a module with the given id exists.
* @param string $id The id to search for.
* @return bool Whether a module is currently loaded with the given id.
*/
function module_exists($id)
{
global $modules;
foreach($modules as $module)
{
if($module["id"] == $id)
return true;
}
return false;
}
// Function to register an action handler
$actions = new stdClass();

View file

@ -50,7 +50,7 @@
"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.",
"id": "feature-search",
"lastupdate": 1447521069,
"lastupdate": 1449335838,
"optional": false
},
{
@ -77,7 +77,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds an action to allow administrators to delete pages.",
"id": "page-delete",
"lastupdate": 1447520092,
"lastupdate": 1449341692,
"optional": false
},
{
@ -86,7 +86,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1447053850,
"lastupdate": 1449337027,
"optional": false
},
{

View file

@ -43,7 +43,7 @@ register_module([
ids::deletepagename($env->page);
// Delete the page from the search index, if that module is installed
if(isset($modules["feature-search"]))
if(module_exists("feature-search"))
{
$pageid = ids::getid($env->page);
$invindex = search::load_invindex($paths->searchindex);