[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Load current object under onsectionChange in lib setup

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]> Sat, 18 Jul 2026 16:08:16 +0000
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a5ba4f068453_3819cf5832498@gitlab-sidekiq-low-urgency-cpu-bound-v2-76655d7f68-mqvnq.mail>

ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
dac0812c by Camile at 2026-07-18T15:51:31+00:00
[FIX] Load current object under onsectionChange in lib setup
---
* [FIX] Load current object under onsectionChange in lib setup

See merge request tikiwiki/tiki!10520

- - - - -


3 changed files:

- lib/setup/events.php
- lib/setup/javascript.php
- tiki-setup.php


Changes:

=====================================
lib/setup/events.php
=====================================
@@ -5,6 +5,8 @@
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 
+use Tiki\Sections;
+
 tiki_setup_events();
 
 register_shutdown_function(function () {
@@ -256,9 +258,11 @@ function tiki_setup_events()
 
     // If the parameter is supplied by the web server, Tiki will expose the object type and id as a response header
     if (! empty($_SERVER['TIKI_HEADER_REPORT_OBJECT']) && strtolower($_SERVER['TIKI_HEADER_REPORT_OBJECT']) != 'off') {
-        if (function_exists('current_object') && $object = current_object()) {
-            header("X-Current-Object: {$object['type']}:{$object['object']}");
-        }
+        Sections::onSectionChange(function ($section) {
+            if (function_exists('current_object') && $object = current_object()) {
+                header("X-Current-Object: {$object['type']}:{$object['object']}");
+            }
+        });
     }
 
     // If the parameter is supplied by the web server, Tiki will expose events as a response header


=====================================
lib/setup/javascript.php
=====================================
@@ -270,13 +270,14 @@ if (! timezone) {
     $jqueryTiki['securityTimeout'] = ! empty($prefs['site_security_timeout']) ? $prefs['site_security_timeout']
         : TikiLib::lib('access')->getDefaultTimeout();
 
-    if (empty($object)) {
-        $object = current_object();
-    }
-    if (empty($object)) {
-        $object = ['type' => '', 'object' => ''];
-    }
-    $jqueryTiki['current_object'] = $object;
+    $jqueryTiki['current_object'] = ['type' => '', 'object' => ''];
+
+    Sections::onSectionChange(function ($section) use (&$jqueryTiki) {
+        if (empty($object)) {
+            $object = current_object();
+        }
+        $jqueryTiki['current_object'] = $object;
+    });
 
     $username_pattern = " / ^ ['\-_a-zA-Z0-9\.]*$/";
     if (is_string($prefs['username_pattern'])) {


=====================================
tiki-setup.php
=====================================
@@ -442,31 +442,32 @@ if ($prefs['pwa_feature'] == 'y') { //pwa test propose, pages to cache
     $smarty->assign('pagespwa', json_encode($pages));
 }
 
-$customRobots = null;
-if ($prefs['metatag_robotscustom'] == 'y') {
-    if (empty($object)) {
+
+Sections::onSectionChange(function ($section) use ($prefs, $headerlib, $smarty) {
+    $customRobots = null;
+    if ($prefs['metatag_robotscustom'] == 'y') {
         $object = current_object();
-    }
-    if ($object && $object['type'] == 'wiki page') {
-        $wikilib = TikiLib::lib('wiki');
-        $customRobots = $wikilib->getPageMetatagRobotscustom($object['object']);
-        if (! empty($customRobots)) {
-            $smarty->assign('metatag_robotscustom', $customRobots);
-            $headerlib->setXRobotsTag($customRobots);
+        if ($object && $object['type'] == 'wiki page') {
+            $wikilib = TikiLib::lib('wiki');
+            $customRobots = $wikilib->getPageMetatagRobotscustom($object['object']);
+            if (! empty($customRobots)) {
+                $smarty->assign('metatag_robotscustom', $customRobots);
+                $headerlib->setXRobotsTag($customRobots);
+            }
         }
     }
-}
 
-// Apply robots directives from robots.txt as meta tags and X-Robots-Tag header.
-if (($prefs['metatag_robots_txt_apply_directives'] ?? 'n') === 'y') {
-    $robotsFromTxt = $headerlib->getRobots();
-    if (! empty($robotsFromTxt)) {
-        $smarty->assign('metatag_robots', $robotsFromTxt);
-        if (empty($customRobots)) {
-            $headerlib->setXRobotsTag($robotsFromTxt);
+    // Apply robots directives from robots.txt as meta tags and X-Robots-Tag header.
+    if (($prefs['metatag_robots_txt_apply_directives'] ?? 'n') === 'y') {
+        $robotsFromTxt = $headerlib->getRobots();
+        if (! empty($robotsFromTxt)) {
+            $smarty->assign('metatag_robots', $robotsFromTxt);
+            if (empty($customRobots)) {
+                $headerlib->setXRobotsTag($robotsFromTxt);
+            }
         }
     }
-}
+});
 
 if ($prefs['feature_antibot'] == 'y' && empty($user)) {
     $captchaType = CaptchaTypeResolver::getConfiguredType($prefs);
@@ -918,27 +919,29 @@ if ($prefs['feature_tasks'] == 'y') {
     $headerlib->add_jsfile('lib/jquery_tiki/tiki-tasks.js');
 }
 
-if ($prefs['feature_inline_comments'] === 'y' && $prefs['comments_inline_annotator'] === 'y') {
-    if (empty($object)) {
-        $object = current_object();
-    }
-    $commentController = new Services_Comment_Controller();
+Sections::onSectionChange(function ($section) {
+    global $headerlib, $prefs, $user;
+    if ($prefs['feature_inline_comments'] === 'y' && $prefs['comments_inline_annotator'] === 'y') {
+        if (empty($object)) {
+            $object = current_object();
+        }
+        $commentController = new Services_Comment_Controller();
 
-    if (
-        $object &&
-        $commentController->isEnabled($object['type'], $object['object']) &&
-        $commentController->canView($object['type'], $object['object'])
-    ) {
-        $canPost = $commentController->canPost($object['type'], $object['object']);
-        // spoof a URI from type and id
-        $objectIdentifier = urlencode($object['type']) . ':' . urlencode($object['object']);
-
-        $headerlib
-            ->add_js_module('import moment from "moment"; window.moment = moment;')
-            ->add_jsfile('vendor_bundled/vendor/openannotation/annotator/annotator-full.min.js')
-            ->add_cssfile('vendor_bundled/vendor/openannotation/annotator/annotator.min.css')
-            // language=JavaScript
-            ->add_jq_onready('
+        if (
+            $object &&
+            $commentController->isEnabled($object['type'], $object['object']) &&
+            $commentController->canView($object['type'], $object['object'])
+        ) {
+            $canPost = $commentController->canPost($object['type'], $object['object']);
+            // spoof a URI from type and id
+            $objectIdentifier = urlencode($object['type']) . ':' . urlencode($object['object']);
+
+            $headerlib
+                ->add_js_module('import moment from "moment"; window.moment = moment;')
+                ->add_jsfile('vendor_bundled/vendor/openannotation/annotator/annotator-full.min.js')
+                ->add_cssfile('vendor_bundled/vendor/openannotation/annotator/annotator.min.css')
+                // language=JavaScript
+                ->add_jq_onready('
 var annotatorContent = $("#top").annotator({readOnly: ' . ($canPost ? 'false' : 'true') . '});
 annotatorContent.annotator("addPlugin", "Store", {
     prefix: "tiki-ajax_services.php?controller=annotation&action=",
@@ -971,10 +974,10 @@ annotatorContent.annotator("addPlugin", "Permissions", {
         return annotation.permissions[action];
     }
 });');
-        // handling for extra info
-        if ($prefs['comments_inline_annotator_with_info'] === 'y') {
-            $headerlib->add_jq_onready(
-                '// a little glue to show the author name and date
+            // handling for extra info
+            if ($prefs['comments_inline_annotator_with_info'] === 'y') {
+                $headerlib->add_jq_onready(
+                    '// a little glue to show the author name and date
 $(".annotator-outer.annotator-viewer").on("load", function (event, annotations) {
     $(this).find(".annotator-user").text(annotations[0].realName + " - " + annotations[0].commentDate);
 });
@@ -985,10 +988,11 @@ $("#top").on("annotationCreated", function (e, annotation) {
         momentDate.format(jqueryTiki.shortTimeFormat);
     annotation.realName = jqueryTiki.userRealName || jqueryTiki.username;
 });'
-            );
+                );
+            }
         }
     }
-}
+});
 
 $headerlib->add_jsfile('lib/jquery_tiki/pluginedit.js');
 



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/dac0812cc3a1af7580a5bdb6a7f0f654998791e3

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/dac0812cc3a1af7580a5bdb6a7f0f654998791e3
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