[TikiWiki-commits] [Git][tikiwiki/tiki][24.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 <6a86e0d738b2b_38a4c0cc5392d@gitlab-sidekiq-low-urgency-cpu-bound-v2-599d57f945-s9ntt.mail>

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


Commits:
c1e52b7b by Alfred Syatsukwa at 2026-08-20T11:05:21+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!11008

(cherry picked from commit 6b91a4d02c80eba6c7c3fab2574f84e1faf924e5)

See merge request tikiwiki/tiki!11009

- - - - -


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
=====================================
@@ -68,7 +68,8 @@ class Services_Wiki_Controller
     public function action_get_page($input)
     {
         $page = $input->page->text();
-        $info = TikiLib::lib('wiki')->get_page_info($page);
+        $skipCache = (bool) $input->nocache->int();
+        $info = TikiLib::lib('wiki')->get_page_info($page, true, $skipCache);
         if (! $info) {
             throw new Services_Exception_NotFound(tr('Page "%0" not found', $page));
         }
@@ -79,7 +80,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);
         return ['data' => $data];
     }
 


=====================================
lib/test/wiki/WikiLibTest.php
=====================================
@@ -18,7 +18,6 @@ use TikiLib;
 
 class WikiLibTest extends TestCase
 {
-
     private $pageName = 'WikiLib Test Page';
 
     protected function setUp(): void
@@ -108,4 +107,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
=====================================
@@ -746,7 +746,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');
@@ -776,7 +776,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



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

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