[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [FIX] Tiki switch lang: fix language switch for SEF slugs
"Domeshow Emmanuel \(@Domeshow\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a831971e1a86_3818bde89872f@gitlab-sidekiq-low-urgency-cpu-bound-v2-8694b5698b-r2qqp.mail> |
Domeshow Emmanuel pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki Commits: a487051f by Domeshow Emmanuel at 2026-08-17T17:23:43+03:00 [FIX] Tiki switch lang: fix language switch for SEF slugs --- * [FIX] Tiki switch lang: resolve SEF slug before switching * [FIX] Tiki switch lang: fix language switch for SEF slugs See merge request tikiwiki/tiki!10846 (cherry picked from commit c88bcfae8ee00ceeef5d3fa4a97a6b3f61f46401) 01747aff [FIX] Tiki switch lang: fix language switch for SEF slugs e601fd43 [FIX] Tiki switch lang: resolve SEF slug before switching Co-authored-by: Domeshow Emmanuel <[email protected]> - - - - - 1 changed file: - tiki-switch_lang.php Changes: ===================================== tiki-switch_lang.php ===================================== @@ -45,6 +45,14 @@ if ($item_path == '/') { $orig_url = $prefs['tikiIndex']; } +function getWikiPageParamFromSefurl($slug) +{ + $wikiLib = TikiLib::lib('wiki'); + $page = $wikiLib->get_page_by_slug(rawurldecode($slug)); + + return rawurlencode($wikiLib->get_slug_by_page($page)); +} + if ($prefs['feature_sefurl'] == 'y' && ! str_contains($orig_url, '.php')) { if (preg_match('/cat[0-9]+-?/', $orig_url)) { include_once('tiki-sefurl.php'); @@ -53,13 +61,31 @@ if ($prefs['feature_sefurl'] == 'y' && ! str_contains($orig_url, '.php')) { $orig_url = preg_replace('#\/article([0-9]+)(.*)#', '/tiki-read_article.php?articleId=$1', $orig_url); } else { if (str_contains($orig_url, '?')) { - $orig_url = preg_replace('#\/([^\/\?]+)\?(.*)?$#', '/tiki-index.php?page=$1&$2', $orig_url); + $orig_url = preg_replace_callback( + '#\/([^\/\?]+)\?(.*)?$#', + function ($matches) { + return '/tiki-index.php?page=' . getWikiPageParamFromSefurl($matches[1]) . '&' . ($matches[2] ?? ''); + }, + $orig_url + ); } else { - $orig_url = preg_replace('#\/([^\/\?]+)$#', '/tiki-index.php?page=$1', $orig_url); + $orig_url = preg_replace_callback( + '#\/([^\/\?]+)$#', + function ($matches) { + return '/tiki-index.php?page=' . getWikiPageParamFromSefurl($matches[1]); + }, + $orig_url + ); } } } elseif (! str_contains($orig_url, '.php')) { - $orig_url = preg_replace('#\/([^\/\?]+)(\?.*)?$#', '/tiki-index.php?page=$1', $orig_url); + $orig_url = preg_replace_callback( + '#\/([^\/\?]+)(\?.*)?$#', + function ($matches) { + return '/tiki-index.php?page=' . getWikiPageParamFromSefurl($matches[1]); + }, + $orig_url + ); $params = parse_url($orig_url); if (empty($params['query'])) { $orig_url = $prefs['tikiIndex']; @@ -68,7 +94,6 @@ if ($prefs['feature_sefurl'] == 'y' && ! str_contains($orig_url, '.php')) { if (str_contains($orig_url, 'tiki-index.php') || str_contains($orig_url, 'tiki-read_article.php')) { $multilinguallib = TikiLib::lib('multilingual'); - $orig_url = urldecode($orig_url); if (! ($txt = strstr($orig_url, '?'))) { $txt = ''; } else { @@ -102,8 +127,8 @@ if (str_contains($orig_url, 'tiki-index.php') || str_contains($orig_url, 'tiki-r } else { $newPage = $tikilib->get_page_name_from_id($bestLangPageId); $newPage = TikiLib::lib('wiki')->get_slug_by_page($newPage); - $newPage = urlencode($newPage); - $orig_url = preg_replace('/(.*[&?]page=)' . preg_quote($page) . '(.*)/', '${1}' . $newPage . '$2', $orig_url); + $newPage = rawurlencode($newPage); + $orig_url = preg_replace('/([&?]page=)[^&]*/', '${1}' . $newPage, $orig_url); $orig_url = preg_replace('/(.*)(tiki-index.php)$/', "$1$2?page=$newPage", $orig_url); } } View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a487051fe94972c2c3fb053a8bc0f72537926776 -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a487051fe94972c2c3fb053a8bc0f72537926776 You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help _______________________________________________ TikiWiki-cvs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs