mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Enhance utf8 support in id index & search system, but there's more work to be done.
This commit is contained in:
parent
20e7c9f0fb
commit
24efac3c5e
5 changed files with 31 additions and 22 deletions
|
@ -71,8 +71,13 @@ A live demo of the latest stable version can be found over at [my website](//sta
|
||||||
### Requirements
|
### Requirements
|
||||||
- PHP-enabled webserver (must be PHP 7+)
|
- PHP-enabled webserver (must be PHP 7+)
|
||||||
- PHP session support (for logging in, see [here](https://php.net/manual/en/session.installation.php) for more information)
|
- PHP session support (for logging in, see [here](https://php.net/manual/en/session.installation.php) for more information)
|
||||||
- The following PHP extensions: mbstring, imagick (for preview generation), fileinfo (for proper mime type checking of uploaded files), and zip (for compress exports)
|
- The following PHP extensions:
|
||||||
- Write access to own folder (only for editing)
|
- `mbstring`
|
||||||
|
- `imagick` (for preview generation)
|
||||||
|
- `fileinfo` (for proper mime type checking of uploaded files)
|
||||||
|
- `zip` (for compressing exports)
|
||||||
|
- `intl` (for Unicode text normalization when searching and in the id index)
|
||||||
|
- Write access to Pepperminty Wiki's own folder (only for editing)
|
||||||
|
|
||||||
### Getting your own copy
|
### Getting your own copy
|
||||||
Setting up your own copy of Pepperminty Wiki is easy. Since Pepperminty Wiki works on a module based system, all you need to do is choose the modules you want installed, and then configure your new installation so that it fits your needs. There are several ways to do this:
|
Setting up your own copy of Pepperminty Wiki is easy. Since Pepperminty Wiki works on a module based system, all you need to do is choose the modules you want installed, and then configure your new installation so that it fits your needs. There are several ways to do this:
|
||||||
|
|
|
@ -1286,7 +1286,7 @@ class ids
|
||||||
|
|
||||||
foreach ($idindex as $id => $entry)
|
foreach ($idindex as $id => $entry)
|
||||||
{
|
{
|
||||||
if($entry == $pagename)
|
if(Normalizer::normalize($entry, Normalizer::FORM_C) == Normalizer::normalize($pagename, Normalizer::FORM_C))
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1318,14 +1318,14 @@ class ids
|
||||||
* that the destination name doesn't already exist.
|
* that the destination name doesn't already exist.
|
||||||
* @package core
|
* @package core
|
||||||
* @param string $oldpagename The old page name to move.
|
* @param string $oldpagename The old page name to move.
|
||||||
* @param string $newpagename The new pagee name to move the old page name to.
|
* @param string $newpagename The new page name to move the old page name to.
|
||||||
*/
|
*/
|
||||||
public static function movepagename($oldpagename, $newpagename)
|
public static function movepagename($oldpagename, $newpagename)
|
||||||
{
|
{
|
||||||
global $idindex, $paths;
|
global $idindex, $paths;
|
||||||
|
|
||||||
$pageid = self::getid($oldpagename);
|
$pageid = self::getid(Normalizer::normalize($oldpagename, Normalizer::FORM_C));
|
||||||
$idindex->$pageid = $newpagename;
|
$idindex->$pageid = Normalizer::normalize($newpagename, Normalizer::FORM_C);
|
||||||
|
|
||||||
file_put_contents($paths->idindex, json_encode($idindex));
|
file_put_contents($paths->idindex, json_encode($idindex));
|
||||||
}
|
}
|
||||||
|
@ -1380,6 +1380,8 @@ class ids
|
||||||
{
|
{
|
||||||
global $idindex, $paths;
|
global $idindex, $paths;
|
||||||
|
|
||||||
|
$pagename = Normalizer::normalize($pagename, Normalizer::FORM_C);
|
||||||
|
|
||||||
$nextid = count(array_keys(get_object_vars($idindex)));
|
$nextid = count(array_keys(get_object_vars($idindex)));
|
||||||
// Increment the generated id until it's unique
|
// Increment the generated id until it's unique
|
||||||
while(isset($idindex->nextid))
|
while(isset($idindex->nextid))
|
||||||
|
@ -3682,7 +3684,7 @@ register_module([
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} ?action=idindex-show Show the id index
|
* @api {get} ?action=idindex-show Show the id index
|
||||||
* @apiDescription Outputs the id index. Useful if you need to verify that it's working as expected.
|
* @apiDescription Outputs the id index. Useful if you need to verify that it's working as expected. Output is a json object.
|
||||||
* @apiName SearchShowIdIndex
|
* @apiName SearchShowIdIndex
|
||||||
* @apiGroup Search
|
* @apiGroup Search
|
||||||
* @apiPermission Anonymous
|
* @apiPermission Anonymous
|
||||||
|
@ -4142,7 +4144,7 @@ class search
|
||||||
public static function tokenize($source)
|
public static function tokenize($source)
|
||||||
{
|
{
|
||||||
$source = strtolower($source);
|
$source = strtolower($source);
|
||||||
$source = str_replace([ '[', ']', '|', '{', '}', '/' ], " ", $source);
|
$source = preg_replace('/[\[\]\|\{\}\/]/u', " ", $source);
|
||||||
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
|
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4154,7 +4156,7 @@ class search
|
||||||
*/
|
*/
|
||||||
public static function strip_markup($source)
|
public static function strip_markup($source)
|
||||||
{
|
{
|
||||||
return str_replace([ "[", "]", "\"", "*", "_", " - ", "`" ], "", $source);
|
return preg_replace('/([\"*_\[\]]| - |`)/u', "", $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4181,7 +4183,7 @@ class search
|
||||||
{
|
{
|
||||||
$page_filename = $env->storage_prefix . $pagedetails->filename;
|
$page_filename = $env->storage_prefix . $pagedetails->filename;
|
||||||
if(!file_exists($page_filename)) {
|
if(!file_exists($page_filename)) {
|
||||||
echo("data: [" . ($i + 1) . " / $max] Error: Can't find $page_filename");
|
echo("data: [" . ($i + 1) . " / $max] Error: Can't find $page_filename\n");
|
||||||
flush();
|
flush();
|
||||||
$missing_files++;
|
$missing_files++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -4497,7 +4499,7 @@ class search
|
||||||
return ($a[1] > $b[1]) ? +1 : -1;
|
return ($a[1] > $b[1]) ? +1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
$sourceLength = strlen($source);
|
$sourceLength = mb_strlen($source);
|
||||||
|
|
||||||
$contexts = [];
|
$contexts = [];
|
||||||
$basepos = 0;
|
$basepos = 0;
|
||||||
|
@ -4569,7 +4571,7 @@ class search
|
||||||
if(in_array($qterm, static::$stop_words))
|
if(in_array($qterm, static::$stop_words))
|
||||||
continue;
|
continue;
|
||||||
// From http://stackoverflow.com/a/2483859/1460422
|
// From http://stackoverflow.com/a/2483859/1460422
|
||||||
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/i", "<strong class='search-term-highlight'>$0</strong>", $context);
|
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
|
|
10
core.php
10
core.php
|
@ -910,7 +910,7 @@ class ids
|
||||||
|
|
||||||
foreach ($idindex as $id => $entry)
|
foreach ($idindex as $id => $entry)
|
||||||
{
|
{
|
||||||
if($entry == $pagename)
|
if(Normalizer::normalize($entry, Normalizer::FORM_C) == Normalizer::normalize($pagename, Normalizer::FORM_C))
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,14 +942,14 @@ class ids
|
||||||
* that the destination name doesn't already exist.
|
* that the destination name doesn't already exist.
|
||||||
* @package core
|
* @package core
|
||||||
* @param string $oldpagename The old page name to move.
|
* @param string $oldpagename The old page name to move.
|
||||||
* @param string $newpagename The new pagee name to move the old page name to.
|
* @param string $newpagename The new page name to move the old page name to.
|
||||||
*/
|
*/
|
||||||
public static function movepagename($oldpagename, $newpagename)
|
public static function movepagename($oldpagename, $newpagename)
|
||||||
{
|
{
|
||||||
global $idindex, $paths;
|
global $idindex, $paths;
|
||||||
|
|
||||||
$pageid = self::getid($oldpagename);
|
$pageid = self::getid(Normalizer::normalize($oldpagename, Normalizer::FORM_C));
|
||||||
$idindex->$pageid = $newpagename;
|
$idindex->$pageid = Normalizer::normalize($newpagename, Normalizer::FORM_C);
|
||||||
|
|
||||||
file_put_contents($paths->idindex, json_encode($idindex));
|
file_put_contents($paths->idindex, json_encode($idindex));
|
||||||
}
|
}
|
||||||
|
@ -1004,6 +1004,8 @@ class ids
|
||||||
{
|
{
|
||||||
global $idindex, $paths;
|
global $idindex, $paths;
|
||||||
|
|
||||||
|
$pagename = Normalizer::normalize($pagename, Normalizer::FORM_C);
|
||||||
|
|
||||||
$nextid = count(array_keys(get_object_vars($idindex)));
|
$nextid = count(array_keys(get_object_vars($idindex)));
|
||||||
// Increment the generated id until it's unique
|
// Increment the generated id until it's unique
|
||||||
while(isset($idindex->nextid))
|
while(isset($idindex->nextid))
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
||||||
"id": "feature-search",
|
"id": "feature-search",
|
||||||
"lastupdate": 1518649628,
|
"lastupdate": 1521389882,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -544,7 +544,7 @@ class search
|
||||||
public static function tokenize($source)
|
public static function tokenize($source)
|
||||||
{
|
{
|
||||||
$source = strtolower($source);
|
$source = strtolower($source);
|
||||||
$source = str_replace([ '[', ']', '|', '{', '}', '/' ], " ", $source);
|
$source = preg_replace('/[\[\]\|\{\}\/]/u', " ", $source);
|
||||||
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
|
return preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|(\p{P}+$))|\|/u", $source, -1, PREG_SPLIT_NO_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ class search
|
||||||
*/
|
*/
|
||||||
public static function strip_markup($source)
|
public static function strip_markup($source)
|
||||||
{
|
{
|
||||||
return str_replace([ "[", "]", "\"", "*", "_", " - ", "`" ], "", $source);
|
return preg_replace('/([\"*_\[\]]| - |`)/u', "", $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -583,7 +583,7 @@ class search
|
||||||
{
|
{
|
||||||
$page_filename = $env->storage_prefix . $pagedetails->filename;
|
$page_filename = $env->storage_prefix . $pagedetails->filename;
|
||||||
if(!file_exists($page_filename)) {
|
if(!file_exists($page_filename)) {
|
||||||
echo("data: [" . ($i + 1) . " / $max] Error: Can't find $page_filename");
|
echo("data: [" . ($i + 1) . " / $max] Error: Can't find $page_filename\n");
|
||||||
flush();
|
flush();
|
||||||
$missing_files++;
|
$missing_files++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -899,7 +899,7 @@ class search
|
||||||
return ($a[1] > $b[1]) ? +1 : -1;
|
return ($a[1] > $b[1]) ? +1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
$sourceLength = strlen($source);
|
$sourceLength = mb_strlen($source);
|
||||||
|
|
||||||
$contexts = [];
|
$contexts = [];
|
||||||
$basepos = 0;
|
$basepos = 0;
|
||||||
|
@ -971,7 +971,7 @@ class search
|
||||||
if(in_array($qterm, static::$stop_words))
|
if(in_array($qterm, static::$stop_words))
|
||||||
continue;
|
continue;
|
||||||
// From http://stackoverflow.com/a/2483859/1460422
|
// From http://stackoverflow.com/a/2483859/1460422
|
||||||
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/i", "<strong class='search-term-highlight'>$0</strong>", $context);
|
$context = preg_replace("/" . str_replace("/", "\/", preg_quote($qterm)) . "/iu", "<strong class='search-term-highlight'>$0</strong>", $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
|
|
Loading…
Reference in a new issue