[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] Prevent tracker/form data from being cached in wiki page API responses

"Alfred Syatsukwa \(@alfredsyatsukwa\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a86c5717997_3818c9b4-169@gitlab-sidekiq-low-urgency-cpu-bound-v2-6b89b54f9c-9n9n2.mail>

Alfred Syatsukwa pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
57b438be by Alfred Syatsukwa at 2026-08-20T09:07:36+00:00
[FIX] Prevent tracker/form data from being cached in wiki page API responses
---
* [FIX] Prevent tracker/form data from being cached in wiki page API responses
---

See merge request tikiwiki/tiki!11005

(cherry picked from commit a90e02450cf1d36c9684aab8ef3f454eac089b1f)

See merge request tikiwiki/tiki!11006

- - - - -


4 changed files:

- lib/core/Services/Wiki/Controller.php
- lib/test/wiki/WikiLibTest.php
- lib/wiki/wikilib.php
- templates/api/docs/paths/wiki/entity.yaml


Changes:

=====================================
lib/core/Services/Wiki/Controller.php
=====================================
@@ -83,7 +83,7 @@ class Services_Wiki_Controller
         }
 
         $canBeRefreshed = false;
-        $data = TikiLib::lib('wiki')->get_parse($page, $canBeRefreshed);
+        $data = TikiLib::lib('wiki')->get_parse($page, $canBeRefreshed, false, $skipCache);
         $result = array_merge($info, ['data' => $data]);
 
         return $result;


=====================================
lib/test/wiki/WikiLibTest.php
=====================================
@@ -104,4 +104,70 @@ Some more text
         $tags = $headerlib->output_js_files();
         $this->assertStringContainsString($expected, $tags, 'Autotoc off, page set to on');
     }
+
+    public function testGetParseSkipCacheDoesNotReadOrUpdatePageCache(): void
+    {
+        global $prefs, $testhelpers, $user;
+
+        $wikilib = TikiLib::lib('wiki');
+        $originalPrefs = $this->capturePrefs(['wiki_cache', 'feature_wiki_icache']);
+        $originalRequest = $_REQUEST;
+        $originalMethod = $_SERVER['REQUEST_METHOD'] ?? null;
+        $originalUser = $user;
+
+        try {
+            $prefs['wiki_cache'] = 3600;
+            $prefs['feature_wiki_icache'] = 'n';
+            $user = '';
+
+            $testhelpers->createPage($this->pageName, 0, 'Fresh wiki render body');
+            $wikilib->update_cache($this->pageName, 'Stale cached render body');
+
+            $_SERVER['REQUEST_METHOD'] = 'GET';
+            $_REQUEST = [];
+
+            $canBeRefreshed = false;
+            $parsed = $wikilib->get_parse($this->pageName, $canBeRefreshed, false, true);
+
+            $this->assertStringContainsString('Fresh wiki render body', $parsed);
+            $this->assertStringNotContainsString('Stale cached render body', $parsed);
+            $this->assertSame('Stale cached render body', $wikilib->get_cache_info($this->pageName)['cache']);
+        } finally {
+            $this->restorePrefs($originalPrefs, ['wiki_cache', 'feature_wiki_icache']);
+            $_REQUEST = $originalRequest;
+            $user = $originalUser;
+            if ($originalMethod === null) {
+                unset($_SERVER['REQUEST_METHOD']);
+            } else {
+                $_SERVER['REQUEST_METHOD'] = $originalMethod;
+            }
+        }
+    }
+
+    private function capturePrefs(array $names): array
+    {
+        global $prefs;
+
+        $captured = [];
+        foreach ($names as $name) {
+            if (array_key_exists($name, $prefs)) {
+                $captured[$name] = $prefs[$name];
+            }
+        }
+
+        return $captured;
+    }
+
+    private function restorePrefs(array $captured, array $names): void
+    {
+        global $prefs;
+
+        foreach ($names as $name) {
+            if (array_key_exists($name, $captured)) {
+                $prefs[$name] = $captured[$name];
+            } else {
+                unset($prefs[$name]);
+            }
+        }
+    }
 }


=====================================
lib/wiki/wikilib.php
=====================================
@@ -709,7 +709,7 @@ class WikiLib extends TikiLib
         return $res;
     }
 
-    public function get_parse($page, &$canBeRefreshed = false, $suppress_icons = false)
+    public function get_parse($page, &$canBeRefreshed = false, $suppress_icons = false, $skipCache = false)
     {
         global $prefs, $user;
         $tikilib = TikiLib::lib('tiki');
@@ -747,7 +747,7 @@ class WikiLib extends TikiLib
 
         $wiki_cache = ($prefs['feature_wiki_icache'] == 'y' && ! is_null($info['wiki_cache'])) ? $info['wiki_cache'] : $prefs['wiki_cache'];
 
-        if ($wiki_cache > 0 && empty($_REQUEST['offset']) && empty($_REQUEST['itemId']) && (empty($user) || $prefs['wiki_cache'] == 0)) {
+        if (! $skipCache && $wiki_cache > 0 && empty($_REQUEST['offset']) && empty($_REQUEST['itemId']) && (empty($user) || $prefs['wiki_cache'] == 0)) {
             $cache_info = $this->get_cache_info($page);
             if (! empty($cache_info['cache_timestamp']) && $cache_info['cache_timestamp'] + $wiki_cache >= $this->now) {
                 $content = $cache_info['cache'];


=====================================
templates/api/docs/paths/wiki/entity.yaml
=====================================
@@ -8,6 +8,15 @@ get:
       required: true
       schema:
         type: string
+    - name: nocache
+      in: query
+      description: Set to 1 to bypass the cached parsed wiki page content and render the page fresh.
+      required: false
+      schema:
+        type: integer
+        enum:
+          - 0
+          - 1
   responses:
     '200':
       description: page content response



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

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/57b438be664183b3c9f22c1a730252a2f9774764
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.