From 157c6dabdda7e0ee3aa6ace766c31c72d1eae719 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 3 Sep 2019 18:16:01 +0100 Subject: [PATCH] If it's a list of strings, then it should be sorted correctly. --- Changelog.md | 2 +- core/40-page-renderer.php | 5 ++++- module_index.json | 22 +++++++++++----------- modules/extra-sidebar.php | 8 ++++++-- modules/feature-search.php | 11 ++++++++--- modules/feature-stats.php | 2 +- modules/feature-theme-gallery.php | 7 ++++--- modules/page-list.php | 7 +++++-- modules/parser-parsedown.php | 3 ++- 9 files changed, 42 insertions(+), 25 deletions(-) diff --git a/Changelog.md b/Changelog.md index 94384a7..1bc70aa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -19,7 +19,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t - Added aria label to user preferences button - Hide site logo from screen readers - Lists of pages that have a specific tag will now be sorted alphabetically (unicode characters should be handled correctly too) - - Support Unicode characters when sorting the list of all tags + - Support Unicode characters when sorting. If it's a list of something, then it's now sorted correctly (e.g. includes pages, tags, etc). ### Changed - Made `build.sh` build script more robust, especially when generating the documentation. diff --git a/core/40-page-renderer.php b/core/40-page-renderer.php index c91137d..d92b0c3 100644 --- a/core/40-page-renderer.php +++ b/core/40-page-renderer.php @@ -521,7 +521,10 @@ class page_renderer public static function generate_all_pages_datalist() { global $settings, $pageindex; $arrayPageIndex = get_object_vars($pageindex); - ksort($arrayPageIndex); + $sorter = new Collator(""); + uksort($arrayPageIndex, function($a, $b) use($sorter) : int { + return $sorter->compare($a, $b); + }); $result = "\n"; // If dynamic page sugggestions are enabled, then we should send a loading message instead. diff --git a/module_index.json b/module_index.json index d2f32c9..fdc32f4 100755 --- a/module_index.json +++ b/module_index.json @@ -52,10 +52,10 @@ { "id": "extra-sidebar", "name": "Sidebar", - "version": "0.3.1", + "version": "0.3.2", "author": "Starbeamrainbowlabs", "description": "Adds a sidebar to the left hand side of every page. Add '$settings->sidebar_show = true;' to your configuration, or append '&sidebar=yes' to the url to enable. Adding to the url sets a cookie to remember your setting.", - "lastupdate": 1505768813, + "lastupdate": 1567528758, "optional": false, "extra_data": [] }, @@ -132,30 +132,30 @@ { "id": "feature-search", "name": "Search", - "version": "0.10", + "version": "0.10.1", "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.", - "lastupdate": 1567107944, + "lastupdate": 1567528763, "optional": false, "extra_data": [] }, { "id": "feature-stats", "name": "Statistics", - "version": "0.2.1", + "version": "0.2.2", "author": "Starbeamrainbowlabs", "description": "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.", - "lastupdate": 1567107944, + "lastupdate": 1567528768, "optional": false, "extra_data": [] }, { "id": "feature-theme-gallery", "name": "Theme Gallery", - "version": "0.1", + "version": "0.3", "author": "Starbeamrainbowlabs", "description": "Adds a theme gallery page and optional automatic theme updates. Contacts a remote server, where IP addresses are stored in automatic server logs for security and attack mitigation purposes.", - "lastupdate": 1567369192, + "lastupdate": 1567528753, "optional": false, "extra_data": [] }, @@ -254,10 +254,10 @@ { "id": "page-list", "name": "Page list", - "version": "0.11.2", + "version": "0.11.3", "author": "Starbeamrainbowlabs", "description": "Adds a page that lists all the pages in the index along with their metadata.", - "lastupdate": 1567513003, + "lastupdate": 1567530955, "optional": false, "extra_data": [] }, @@ -337,7 +337,7 @@ "version": "0.10", "author": "Emanuil Rusev & Starbeamrainbowlabs", "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation.", - "lastupdate": 1567168168, + "lastupdate": 1567530862, "optional": false, "extra_data": { "Parsedown.php": "https:\/\/raw.githubusercontent.com\/erusev\/parsedown\/fe7a50eceb4a3c867cc9fa9c0aa906b1067d1955\/Parsedown.php", diff --git a/modules/extra-sidebar.php b/modules/extra-sidebar.php index 4ec5b14..00244d0 100644 --- a/modules/extra-sidebar.php +++ b/modules/extra-sidebar.php @@ -1,7 +1,7 @@ "Sidebar", - "version" => "0.3.1", + "version" => "0.3.2", "author" => "Starbeamrainbowlabs", "description" => "Adds a sidebar to the left hand side of every page. Add '\$settings->sidebar_show = true;' to your configuration, or append '&sidebar=yes' to the url to enable. Adding to the url sets a cookie to remember your setting.", "id" => "extra-sidebar", @@ -51,7 +51,11 @@ register_module([ // Sort the pageindex $sorted_pageindex = get_object_vars($pageindex); - ksort($sorted_pageindex, SORT_NATURAL); + + $sorter = new Collator(""); + uksort($sorted_pageindex, function($a, $b) use($sorter) : int { + return $sorter->compare($a, $b); + }); $sidebar_contents = ""; $sidebar_contents .= render_sidebar($sorted_pageindex); diff --git a/modules/feature-search.php b/modules/feature-search.php index 3b3bf06..fed6df6 100644 --- a/modules/feature-search.php +++ b/modules/feature-search.php @@ -1,7 +1,7 @@ "Search", - "version" => "0.10", + "version" => "0.10.1", "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.", "id" => "feature-search", @@ -891,12 +891,17 @@ class search } /** - * Sorts an index alphabetically. Will also sort an inverted index. + * Sorts an index alphabetically. * This allows us to do a binary search instead of a regular * sequential search. * @param array $index The index to sort. */ - public static function index_sort(&$index) { ksort($index, SORT_NATURAL); } + public static function index_sort(&$index) { + $sorter = new Collator(""); + uksort($index, function($a, $b) use($sorter) : int { + return $sorter->compare($a, $b); + }); + } /** * Compares two *regular* indexes to find the differences between them. diff --git a/modules/feature-stats.php b/modules/feature-stats.php index 7657174..a168ecf 100644 --- a/modules/feature-stats.php +++ b/modules/feature-stats.php @@ -1,7 +1,7 @@ "Statistics", - "version" => "0.2.1", + "version" => "0.2.2", "author" => "Starbeamrainbowlabs", "description" => "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.", "id" => "feature-stats", diff --git a/modules/feature-theme-gallery.php b/modules/feature-theme-gallery.php index 83ab8a4..96c6ae3 100644 --- a/modules/feature-theme-gallery.php +++ b/modules/feature-theme-gallery.php @@ -1,7 +1,7 @@ "Theme Gallery", - "version" => "0.1", + "version" => "0.3", "author" => "Starbeamrainbowlabs", "description" => "Adds a theme gallery page and optional automatic theme updates. Contacts a remote server, where IP addresses are stored in automatic server logs for security and attack mitigation purposes.", "id" => "feature-theme-gallery", @@ -46,8 +46,9 @@ register_module([ } } - usort($themes_available, function($a, $b) { - return strcmp($a->name, $b->name); + $sorter = new Collator(""); + usort($themes_available, function($a, $b) use ($sorter) : int { + return $sorter->compare($a->name, $b->name); }); $content = "

Theme Gallery

diff --git a/modules/page-list.php b/modules/page-list.php index 9a68f2a..31b7496 100644 --- a/modules/page-list.php +++ b/modules/page-list.php @@ -1,7 +1,7 @@ "Page list", - "version" => "0.11.2", + "version" => "0.11.3", "author" => "Starbeamrainbowlabs", "description" => "Adds a page that lists all the pages in the index along with their metadata.", "id" => "page-list", @@ -32,7 +32,10 @@ register_module([ $format = $_GET["format"] ?? "html"; $sorted_pageindex = get_object_vars($pageindex); - ksort($sorted_pageindex, SORT_NATURAL); + $sorter = new Collator(""); + uksort($sorted_pageindex, function($a, $b) use($sorter) : int { + return $sorter->compare($a, $b); + }); switch($format) { case "html": diff --git a/modules/parser-parsedown.php b/modules/parser-parsedown.php index 74ab3b3..ce1903f 100644 --- a/modules/parser-parsedown.php +++ b/modules/parser-parsedown.php @@ -132,7 +132,8 @@ register_module([ $orphaned_pages[] = $pagename; } - sort($orphaned_pages); + $sorter = new Collator(""); + $sorter->sort($orphaned_pages); $result->value = $orphaned_pages; $result->completed = true;