mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Also delete from searchindex when deleting a page. Speculative fix for #35, but it seems #41 needs fixing first.
This commit is contained in:
parent
e191887bcb
commit
b539cb4107
4 changed files with 62 additions and 4 deletions
|
@ -1763,6 +1763,25 @@ class search
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given pageid from the given pageindex.
|
||||
* @param inverted_index &$invindex The inverted index.
|
||||
* @param number $pageid The pageid to remove.
|
||||
*/
|
||||
public static function delete_entry(&$invindex, $pageid)
|
||||
{
|
||||
$str_pageid = (string)$pageid;
|
||||
foreach($invindex as $nterm => &$entry)
|
||||
{
|
||||
if(isset($entry[$pageid]))
|
||||
unset($entry[$pageid]);
|
||||
if(isset($entry[$str_pageid]))
|
||||
unset($entry[$str_pageid]);
|
||||
if(count($entry) === 0)
|
||||
unset($invindex[$nterm]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function save_invindex($filename, &$invindex)
|
||||
{
|
||||
file_put_contents($filename, json_encode($invindex));
|
||||
|
@ -2375,7 +2394,7 @@ register_module([
|
|||
"id" => "page-delete",
|
||||
"code" => function() {
|
||||
add_action("delete", function() {
|
||||
global $pageindex, $settings, $env, $paths;
|
||||
global $pageindex, $settings, $env, $paths, $modules;
|
||||
if(!$settings->editing)
|
||||
{
|
||||
exit(page_renderer::render_main("Deleting $env->page - error", "<p>You tried to delete $env->page, but editing is disabled on this wiki.</p>
|
||||
|
@ -2400,6 +2419,7 @@ register_module([
|
|||
{
|
||||
unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
|
||||
}
|
||||
|
||||
// Delete the page from the page index
|
||||
unset($pageindex->$page);
|
||||
|
||||
|
@ -2409,6 +2429,15 @@ register_module([
|
|||
// Remove the page's name from the id index
|
||||
ids::deletepagename($env->page);
|
||||
|
||||
// Delete the page from the search index, if that module is installed
|
||||
if(isset($modules["feature-search"]))
|
||||
{
|
||||
$pageid = ids::getid($env->page);
|
||||
$invindex = search::load_invindex($paths->searchindex);
|
||||
search::delete_entry($invindex, $pageid);
|
||||
search::save_invindex($paths->searchindex, $invindex);
|
||||
}
|
||||
|
||||
// Delete the page from the disk
|
||||
unlink("$env->storage_prefix$env->page.md");
|
||||
|
||||
|
|
|
@ -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": 1447267196,
|
||||
"lastupdate": 1447520172,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
@ -77,7 +77,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds an action to allow administrators to delete pages.",
|
||||
"id": "page-delete",
|
||||
"lastupdate": 1447269891,
|
||||
"lastupdate": 1447520092,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -278,6 +278,25 @@ class search
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given pageid from the given pageindex.
|
||||
* @param inverted_index &$invindex The inverted index.
|
||||
* @param number $pageid The pageid to remove.
|
||||
*/
|
||||
public static function delete_entry(&$invindex, $pageid)
|
||||
{
|
||||
$str_pageid = (string)$pageid;
|
||||
foreach($invindex as $nterm => &$entry)
|
||||
{
|
||||
if(isset($entry[$pageid]))
|
||||
unset($entry[$pageid]);
|
||||
if(isset($entry[$str_pageid]))
|
||||
unset($entry[$str_pageid]);
|
||||
if(count($entry) === 0)
|
||||
unset($invindex[$nterm]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function save_invindex($filename, &$invindex)
|
||||
{
|
||||
file_put_contents($filename, json_encode($invindex));
|
||||
|
|
|
@ -7,7 +7,7 @@ register_module([
|
|||
"id" => "page-delete",
|
||||
"code" => function() {
|
||||
add_action("delete", function() {
|
||||
global $pageindex, $settings, $env, $paths;
|
||||
global $pageindex, $settings, $env, $paths, $modules;
|
||||
if(!$settings->editing)
|
||||
{
|
||||
exit(page_renderer::render_main("Deleting $env->page - error", "<p>You tried to delete $env->page, but editing is disabled on this wiki.</p>
|
||||
|
@ -32,6 +32,7 @@ register_module([
|
|||
{
|
||||
unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
|
||||
}
|
||||
|
||||
// Delete the page from the page index
|
||||
unset($pageindex->$page);
|
||||
|
||||
|
@ -41,6 +42,15 @@ register_module([
|
|||
// Remove the page's name from the id index
|
||||
ids::deletepagename($env->page);
|
||||
|
||||
// Delete the page from the search index, if that module is installed
|
||||
if(isset($modules["feature-search"]))
|
||||
{
|
||||
$pageid = ids::getid($env->page);
|
||||
$invindex = search::load_invindex($paths->searchindex);
|
||||
search::delete_entry($invindex, $pageid);
|
||||
search::save_invindex($paths->searchindex, $invindex);
|
||||
}
|
||||
|
||||
// Delete the page from the disk
|
||||
unlink("$env->storage_prefix$env->page.md");
|
||||
|
||||
|
|
Loading…
Reference in a new issue