[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [BP][FIX] WantedPages: also match toPage against pageSlug to avoid false wanted page reports

"luci \(@luciash\) via TikiWiki-cvs" <[email protected]> Fri, 03 Jul 2026 09:57:35 +0000
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a47878f4272b_3819a6f4358ad@gitlab-sidekiq-low-urgency-cpu-bound-v2-69d694bf94-s686h.mail>

luci pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki


Commits:
a79db828 by Landry Bitege at 2026-07-03T09:49:13+00:00
[BP][FIX] WantedPages: also match toPage against pageSlug to avoid false wanted page reports
---
* [FIX] WantedPages: also match toPage against pageSlug to avoid false wanted page reports
---
* [FIX] WantedPages: also match toPage against pageSlug to avoid false wanted page reports

See merge request tikiwiki/tiki!10474

(cherry picked from commit f24398a435a40cee94d03f39350f44cd3d78e3f7)

See merge request tikiwiki/tiki!10633

- - - - -


2 changed files:

- + lib/test/wiki-plugins/WikiPluginWantedPagesTest.php
- lib/wiki-plugins/wikiplugin_wantedpages.php


Changes:

=====================================
lib/test/wiki-plugins/WikiPluginWantedPagesTest.php
=====================================
@@ -0,0 +1,129 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// 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.
+
+namespace Tiki\Lib\Test\WikiPlugins;
+
+use TikiTestCase;
+use TikiLib;
+
+require_once(__DIR__ . '/../../wiki-plugins/wikiplugin_wantedpages.php');
+require_once(__DIR__ . '/../../test/TestHelpers.php');
+
+class WikiPluginWantedPagesTest extends TikiTestCase
+{
+    private $orig_user;
+    private array $testPages = [];
+
+    // Unique fromPage used in all test link inserts so tearDown can clean precisely
+    private string $testFromPage = 'WantedPagesTest_FromPage';
+
+    protected function setUp(): void
+    {
+        global $user, $prefs;
+        $this->orig_user = $user;
+
+        $_SERVER['HTTP_HOST'] = 'localhost';
+        $_SERVER['REQUEST_URI'] = 'phpunit';
+        $user = 'admin';
+
+        $prefs['wikiplugin_wantedpages'] = 'y';
+        $prefs['feature_wikiwords'] = 'y';
+        $prefs['feature_wikiwords_usedash'] = 'y';
+        $prefs['namespace_enabled'] = 'n';
+
+        $this->setPageRegex();
+
+        TikiLib::lib('tiki')->clear_links($this->testFromPage);
+    }
+
+    protected function tearDown(): void
+    {
+        global $user;
+
+        foreach ($this->testPages as $page) {
+            (new \TestHelpers())->removeAllVersions($page);
+        }
+        $this->testPages = [];
+
+        TikiLib::lib('tiki')->clear_links($this->testFromPage);
+
+        unset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
+        $user = $this->orig_user;
+    }
+
+    private function createTestPage(string $name): void
+    {
+        (new \TestHelpers())->createPage($name, 0, 'Test content');
+        $this->testPages[] = $name;
+    }
+
+    private function insertLink(string $toPage): void
+    {
+        TikiLib::lib('tiki')->replace_link($this->testFromPage, $toPage);
+    }
+
+    private function runPlugin(): string
+    {
+        return TikiLib::lib('parser')->invokePlugin('wantedpages', '', []);
+    }
+
+    /**
+     * Positive control: a link whose toPage exactly matches pageName must not be listed.
+     */
+    public function testExactPageNameNotListedAsWanted(): void
+    {
+        $this->createTestPage('WantedPagesTest ExactMatch');
+        $this->insertLink('WantedPagesTest ExactMatch');
+
+        $output = $this->runPlugin();
+
+        $this->assertStringNotContainsString('WantedPagesTest ExactMatch', $output);
+    }
+
+    /**
+     * Regression: a link using the page slug (hyphens) must not be listed when the page
+     * exists under its space-separated name.
+     *
+     * Before the fix, the SQL JOIN only matched toPage against pageName, so slug-form
+     * links always appeared as wanted pages even when the target page existed.
+     */
+    public function testSlugFormLinkNotListedAsWanted(): void
+    {
+        $pageName = 'WantedPagesTest SlugMatch';
+        $this->createTestPage($pageName);
+
+        $pageInfo = TikiLib::lib('tiki')->get_page_info($pageName);
+        $pageSlug = $pageInfo['pageSlug'];
+        $this->assertNotEmpty($pageSlug, 'Tiki should generate a pageSlug for the created page.');
+
+        $this->insertLink($pageSlug);
+
+        $output = $this->runPlugin();
+
+        $this->assertStringNotContainsString(
+            $pageSlug,
+            $output,
+            'A link to an existing page via its slug should not appear in the wanted pages list.'
+        );
+    }
+
+    /**
+     * Negative control: a link to a genuinely missing page must appear in the list.
+     */
+    public function testTrulyMissingPageListedAsWanted(): void
+    {
+        $this->insertLink('WantedPagesTest TrulyMissingPage');
+
+        $output = $this->runPlugin();
+
+        $this->assertStringContainsString(
+            'WantedPagesTest TrulyMissingPage',
+            $output,
+            'A link to a non-existent page should appear in the wanted pages list.'
+        );
+    }
+}


=====================================
lib/wiki-plugins/wikiplugin_wantedpages.php
=====================================
@@ -223,7 +223,7 @@ class WikiPluginWantedPages extends PluginsLib
                 'ELSE tpf.`data` ' .
             'END AS fromPageContent ' .
             'FROM `tiki_links` tl ' .
-            'LEFT JOIN `tiki_pages` tp ON (tl.`toPage` = tp.`pageName`) ' .
+            'LEFT JOIN `tiki_pages` tp ON (tl.`toPage` = tp.`pageName` OR tl.`toPage` = tp.`pageSlug`) ' .
             'LEFT JOIN `tiki_pages` tpf ON (tl.`fromPage` = tpf.`pageName`) ' .
             'LEFT JOIN `tiki_tracker_item_fields` ttif ON (' .
                 'SUBSTRING_INDEX(SUBSTRING_INDEX(tl.`fromPage`, \':\', 3), \':\', -1) = ttif.`itemId` ' .



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

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