mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Finish bugfixing #35 - search has been implemented at last!
This commit is contained in:
parent
29399a379c
commit
71131f973f
4 changed files with 252 additions and 212 deletions
|
@ -691,9 +691,10 @@ if(!file_exists($paths->pageindex))
|
||||||
{
|
{
|
||||||
$glob_str = $env->storage_prefix . "*.md";
|
$glob_str = $env->storage_prefix . "*.md";
|
||||||
$existingpages = glob_recursive($glob_str);
|
$existingpages = glob_recursive($glob_str);
|
||||||
var_dump($env->storage_prefix);
|
// Debug statements. Uncomment when debugging the pageindex regenerator.
|
||||||
var_dump($glob_str);
|
// var_dump($env->storage_prefix);
|
||||||
var_dump($existingpages);
|
// 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
|
||||||
|
@ -717,7 +718,8 @@ if(!file_exists($paths->pageindex))
|
||||||
// Extract the name of the (sub)page without the ".md"
|
// Extract the name of the (sub)page without the ".md"
|
||||||
$pagekey = utf8_encode(substr($newentry->filename, 0, -3));
|
$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!
|
// This page (potentially) has an associated file!
|
||||||
// Let's investigate.
|
// Let's investigate.
|
||||||
|
@ -733,10 +735,11 @@ if(!file_exists($paths->pageindex))
|
||||||
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $pagekey);
|
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $pagekey);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo("pagekey: ");
|
// Debug statements. Uncomment when debugging the pageindex regenerator.
|
||||||
var_dump($pagekey);
|
// echo("pagekey: ");
|
||||||
echo("newentry: ");
|
// var_dump($pagekey);
|
||||||
var_dump($newentry);
|
// echo("newentry: ");
|
||||||
|
// var_dump($newentry);
|
||||||
|
|
||||||
// Subpage parent checker
|
// Subpage parent checker
|
||||||
if(strpos($pagekey, "/") !== false)
|
if(strpos($pagekey, "/") !== false)
|
||||||
|
@ -1194,6 +1197,21 @@ function register_module($moduledata)
|
||||||
//var_dump($moduledata);
|
//var_dump($moduledata);
|
||||||
$modules[] = $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
|
// Function to register an action handler
|
||||||
$actions = new stdClass();
|
$actions = new stdClass();
|
||||||
|
@ -1518,6 +1536,11 @@ register_module([
|
||||||
add_action("search", function() {
|
add_action("search", function() {
|
||||||
global $settings, $env, $pageindex, $paths;
|
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"]))
|
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>"));
|
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);
|
ids::deletepagename($env->page);
|
||||||
|
|
||||||
// Delete the page from the search index, if that module is installed
|
// 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);
|
$pageid = ids::getid($env->page);
|
||||||
$invindex = search::load_invindex($paths->searchindex);
|
$invindex = search::load_invindex($paths->searchindex);
|
||||||
|
@ -2508,7 +2531,7 @@ register_module([
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
http_response_code(404);
|
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
|
// Update the inverted search index
|
||||||
|
|
||||||
// Construct an index for the old and new page content
|
// 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"));
|
$oldindex = search::index(file_get_contents("$env->page.md"));
|
||||||
$newindex = search::index($pagedata);
|
$newindex = search::index($pagedata);
|
||||||
|
|
||||||
|
|
15
core.php
15
core.php
|
@ -853,6 +853,21 @@ function register_module($moduledata)
|
||||||
//var_dump($moduledata);
|
//var_dump($moduledata);
|
||||||
$modules[] = $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
|
// Function to register an action handler
|
||||||
$actions = new stdClass();
|
$actions = new stdClass();
|
||||||
|
|
|
@ -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": 1447521069,
|
"lastupdate": 1449335838,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
"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": 1447520092,
|
"lastupdate": 1449341692,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
"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": 1447053850,
|
"lastupdate": 1449337027,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ register_module([
|
||||||
ids::deletepagename($env->page);
|
ids::deletepagename($env->page);
|
||||||
|
|
||||||
// Delete the page from the search index, if that module is installed
|
// 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);
|
$pageid = ids::getid($env->page);
|
||||||
$invindex = search::load_invindex($paths->searchindex);
|
$invindex = search::load_invindex($paths->searchindex);
|
||||||
|
|
Loading…
Reference in a new issue