[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Tiki switch lang: fix language switch for SEF slugs
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a7b3ee29bcb4_3837cb0489209c@gitlab-sidekiq-low-urgency-cpu-bound-v2-84dcc76b6c-65cm2.mail> |
Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
c88bcfae by Domeshow Emmanuel at 2026-08-11T15:00:47+00: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
- - - - -
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/c88bcfae8ee00ceeef5d3fa4a97a6b3f61f46401
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/c88bcfae8ee00ceeef5d3fa4a97a6b3f61f46401
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