[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Use onSectionChange() callbacks for section-dependent code in lib/setup
"Jonny Bradley \(@jonnybradley\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a350e59eb60f_38196e0033735@gitlab-sidekiq-low-urgency-cpu-bound-v2-5d76f55d69-sxc7r.mail> |
Jonny Bradley pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
7b802768 by Camile at 2026-06-19T09:22:30+00:00
[FIX] Use onSectionChange() callbacks for section-dependent code in lib/setup
---
* Move language switching logic to setSectionLanguage()
Remove the onSectionChange callback from user_prefs.php that was handling
admin language override. This logic is now consolidated in setSectionLanguage()
which provides proper language cascade handling with locale validation.
Also document the freetags callback to clarify which globals are used and when
they are accessed during section changes.
* [DOC] Add documentation to freetags code depending on Section
* [FIX] use null objectType fallback in onSectionChange for sections without objectType
* [FIX] Use onSectionChange() callbacks for section-dependent code in lib/setup
See merge request tikiwiki/tiki!10170
- - - - -
6 changed files:
- lib/setup/absolute_urls.php
- lib/setup/freetags.php
- lib/setup/prefs.php
- lib/setup/sections.php
- lib/setup/stats.php
- lib/setup/user_prefs.php
Changes:
=====================================
lib/setup/absolute_urls.php
=====================================
@@ -153,18 +153,19 @@ if (str_contains($base_uri, $tikiroot . 'route.php') && ! empty($inclusion)) {
$base_uri .= '?' . http_build_query($_GET, '', '&');
}
global $sections;
- $section = Sections::getCurrentSection();
- include_once('tiki-sefurl.php');
- if (isset($sections[$section]['objectType'])) {
- $objectType = $sections[$section]['objectType'];
- } else {
- $objectType = $section;
- }
- if ($objectType === Sections::SECTION_WIKI_PAGE) {
- $objectType = Sections::SECTION_WIKI;
- }
- $base_uri = TikiLib::tikiUrlOpt(filter_out_sefurl($base_uri, $objectType));
+ Sections::onSectionChange(function ($section) use ($sections, &$base_uri) {
+ if (isset($sections[$section]['objectType'])) {
+ $objectType = $sections[$section]['objectType'];
+ } else {
+ $objectType = null;
+ }
+ if ($objectType === Sections::SECTION_WIKI_PAGE) {
+ $objectType = Sections::SECTION_WIKI;
+ }
+ include_once('tiki-sefurl.php');
+ $base_uri = TikiLib::tikiUrlOpt(filter_out_sefurl($base_uri, $objectType));
+ });
}
// SSL options
=====================================
lib/setup/freetags.php
=====================================
@@ -8,44 +8,63 @@ if (basename($_SERVER['SCRIPT_NAME']) === basename(__FILE__)) {
die('This script may only be included.');
}
-if (isset($section) and isset($sections[$section])) {
- $freetaglib = TikiLib::lib('freetag');
- $freetaglib->handleCurrentObjectTagRequest();
-
- $tags = [];
- if ($object = current_object()) {
- $objectTags = $freetaglib->get_tags_on_object($object['object'], $object['type']);
- if ($objectTags) {
- $tags = $objectTags['data'];
+use Tiki\Sections;
+
+/**
+ * Register callback for section changes
+ *
+ * When the application section changes, this callback processes freetag operations.
+ * The global declarations ensure the callback accesses the current/updated values
+ * of the required variables.
+ *
+ * Used in this callback:
+ * - $sections: check if section exists
+ * - $freetaglib: tag/untag objects, retrieve tags
+ * - $tiki_p_freetags_tag, $tiki_p_admin, $tiki_p_unassign_freetags: permission checks
+ * - $prefs: check antibot and multilingual settings
+ * - $smarty: assign tags and error messages to template
+ */
+Sections::onSectionChange(function ($section) {
+ global $sections, $freetaglib, $tiki_p_freetags_tag, $prefs, $smarty;
+ if (isset($sections[$section])) {
+ $freetaglib = TikiLib::lib('freetag');
+ $freetaglib->handleCurrentObjectTagRequest();
+
+ $tags = [];
+ if ($object = current_object()) {
+ $objectTags = $freetaglib->get_tags_on_object($object['object'], $object['type']);
+ if ($objectTags) {
+ $tags = $objectTags['data'];
+ }
}
- }
- $smarty->assign('tags', $tags);
+ $smarty->assign('tags', $tags);
- if ($tiki_p_freetags_tag == 'y' && $prefs['freetags_multilingual'] == 'y') {
- $ft_lang = null;
- $ft_multi = false;
- if (! empty($tags['data'])) {
- foreach ($tags['data'] as $row) {
- $l = $row['lang'];
+ if ($tiki_p_freetags_tag == 'y' && $prefs['freetags_multilingual'] == 'y') {
+ $ft_lang = null;
+ $ft_multi = false;
+ if (! empty($tags['data'])) {
+ foreach ($tags['data'] as $row) {
+ $l = $row['lang'];
- if (! $l) {
- continue;
- }
+ if (! $l) {
+ continue;
+ }
- if (! $ft_lang) {
- $ft_lang = $l;
- } elseif ($ft_lang != $l) {
- $ft_multi = true;
- break;
+ if (! $ft_lang) {
+ $ft_lang = $l;
+ } elseif ($ft_lang != $l) {
+ $ft_multi = true;
+ break;
+ }
}
}
- }
- if ($ft_multi && $object = current_object()) {
- $smarty->assign(
- 'freetags_mixed_lang',
- 'tiki-freetag_translate.php?objType=' . urlencode($object['type']) . '&objId=' . urlencode($object['object'])
- );
+ if ($ft_multi && $object = current_object()) {
+ $smarty->assign(
+ 'freetags_mixed_lang',
+ 'tiki-freetag_translate.php?objType=' . urlencode($object['type']) . '&objId=' . urlencode($object['object'])
+ );
+ }
}
}
-}
+});
=====================================
lib/setup/prefs.php
=====================================
@@ -248,7 +248,7 @@ function get_default_prefs()
function initialize_prefs($force = false)
{
- global $prefs, $user_overrider_prefs, $in_installer, $section, $systemConfiguration;
+ global $prefs, $user_overrider_prefs, $in_installer, $systemConfiguration;
if (! $force && (defined('TIKI_IN_INSTALLER') || defined('TIKI_IN_TEST'))) {
=====================================
lib/setup/sections.php
=====================================
@@ -14,10 +14,6 @@ use Tiki\Sections;
$sections = Sections::getSections();
-if (! isset($section)) {
- $section = '';
-}
-
$sections_enabled = [];
foreach ($sections as $sec => $dat) {
@@ -29,16 +25,14 @@ foreach ($sections as $sec => $dat) {
ksort($sections_enabled);
$smarty->assign_by_ref('sections_enabled', $sections_enabled);
-if (! empty($section)) {
- $smarty->assign('section', $section);
-}
-if (! empty($section_class)) {
- $smarty->assign('section_class', $section_class);
-} elseif (! empty($section)) {
- $section_class = 'tiki_' . str_replace(' ', '_', $section);
- $smarty->assign('section_class', $section_class);
-}
+Sections::onSectionChange(function ($section) use ($smarty) {
+ if (! empty($section)) {
+ $smarty->assign('section', $section);
+ $section_class = 'tiki_' . str_replace(' ', '_', $section);
+ $smarty->assign('section_class', $section_class);
+ }
+});
function current_object()
{
=====================================
lib/setup/stats.php
=====================================
@@ -11,8 +11,6 @@ if (basename($_SERVER['SCRIPT_NAME']) === basename(__FILE__)) {
die('This script may only be included.');
}
-$section = Sections::getCurrentSection();
-
if ($prefs['feature_referer_stats'] == 'y') {
if (isset($_SERVER['HTTP_REFERER'])) {
$pref = parse_url($_SERVER['HTTP_REFERER']);
@@ -22,9 +20,15 @@ if ($prefs['feature_referer_stats'] == 'y') {
}
}
-if (StatsLib::is_stats_hit()) {
- if (! isset($section) or ( ! Sections::isCurrentSection(Sections::SECTION_CHAT) and ! Sections::isCurrentSection(Sections::SECTION_LIVESUPPORT) )) {
- $statslib = TikiLib::lib('stats');
- $statslib->add_pageview();
+// Track whether we've already recorded the pageview to prevent double-counting
+$pageview_recorded = false;
+
+Sections::onSectionChange(function ($section) use (&$pageview_recorded) {
+ if (! $pageview_recorded && StatsLib::is_stats_hit()) {
+ if ($section !== Sections::SECTION_CHAT && $section !== Sections::SECTION_LIVESUPPORT) {
+ $statslib = TikiLib::lib('stats');
+ $statslib->add_pageview();
+ $pageview_recorded = true;
+ }
}
-}
+});
=====================================
lib/setup/user_prefs.php
=====================================
@@ -38,7 +38,6 @@ $prefs['user_tracker_watch_editor'] = 'n';
$prefs['user_comment_watch_editor'] = 'n';
$prefs['user_category_watch_editor'] = 'n';
$prefs['user_plugin_approval_watch_editor'] = 'n';
-$section = Sections::getCurrentSection();
if ($user) {
$default_group = $group = $_SESSION['u_info']['group'];
@@ -79,12 +78,6 @@ $smarty->assign('IP', $tikilib->get_ip_address());
$tikilib->set_display_timezone($user);
-if (! empty($section) && (Sections::isCurrentSection(Sections::SECTION_ADMIN) || Sections::isCurrentSection(Sections::SECTION_ADMIN_LAYOUT)) && ! empty($prefs['language_admin'])) {
- $prefs['language'] = $prefs['language_admin'];
-}
-
-$smarty->refreshLanguage();
-
if ($prefs['language'] != $prefs['site_language']) {
$prefslib = TikiLib::lib('prefs');
$translatablePreferences = $prefslib->getTranslatablePreferences();
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7b8027683ad4eb800c0fb287283602d32f8fe33e
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7b8027683ad4eb800c0fb287283602d32f8fe33e
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