[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Plugin Wanted Pages: Exclude links that are written like ((Page 1))...

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <690f5bc277898_2cdc6ac5c4919@gitlab-sidekiq-low-urgency-cpu-bound-v2-7d6b66dd6f-gv4sq.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
a1929841 by Baraka Kinywa at 2025-11-08T14:55:10+00:00
[FIX] Plugin Wanted Pages: Exclude links that are written like ((Page 1))...
---
* [FIX] Plugin Wanted Pages: Exclude links that are written like ((Page 1)) wrapped in np tags from the wanted pages list

See merge request tikiwiki/tiki!8884

- - - - -


1 changed file:

- lib/wiki-plugins/wikiplugin_wantedpages.php


Changes:

=====================================
lib/wiki-plugins/wikiplugin_wantedpages.php
=====================================
@@ -160,6 +160,25 @@ class WikiPluginWantedPages extends PluginsLib
         return preg_replace("/[Revision: $]/", '', "\$Revision: 1.7 $");
     }
 
+    /**
+     * Check if a link is escaped (wrapped in ~np~ tags) in the source page
+     * @param string $fromPageContent The content of the page containing the link
+     * @param string $toPage The target page of the link
+     * @return bool True if the link is escaped, false otherwise
+     */
+    private function isEscapedLink($fromPageContent, $toPage)
+    {
+        if (empty($fromPageContent)) {
+            return false;
+        }
+
+        // Check if link is wrapped in ~np~ tags (exact or partial matches within np blocks)
+        // Pattern: ~np~...((PageName))...~/np~
+        $escapedPattern = '/~np~[^~]*?\(\(' . preg_quote($toPage, '/') . '\)\).*?~\/np~/s';
+
+        return preg_match($escapedPattern, $fromPageContent) === 1;
+    }
+
     public function run($data, $params)
     {
         global $prefs, $page_regex;
@@ -177,7 +196,7 @@ class WikiPluginWantedPages extends PluginsLib
             if (preg_ispreg($data)) { // custom regular expression
                 $level_reg = $data;
             } elseif ($debug == 2) {
-                echo $data . ': ' . tra('non-valid custom regex') . '<br />';
+                echo tr('%0: non-valid custom regex', $data) . '<br />';
             }
         } else { // default
             $level_reg = $page_regex;
@@ -197,8 +216,9 @@ class WikiPluginWantedPages extends PluginsLib
 
         // Currently we only look in wiki pages.
         // Wiki links in articles, blogs, etc are ignored.
-        $query = 'select distinct tl.`toPage`, tl.`fromPage` from `tiki_links` tl';
+        $query = 'select distinct tl.`toPage`, tl.`fromPage`, tpf.`data` as fromPageContent from `tiki_links` tl';
         $query .= ' left join `tiki_pages` tp on (tl.`toPage` = tp.`pageName`)';
+        $query .= ' left join `tiki_pages` tpf on (tl.`fromPage` = tpf.`pageName`)';
         if ($skipalias) {
             $query .= ' left join `tiki_object_relations` tor on (tl.`toPage` = tor.`target_itemId`)';
         }
@@ -215,11 +235,25 @@ class WikiPluginWantedPages extends PluginsLib
         $tmp = [];
 
         while ($row = $result->fetchRow()) {
+            // Skip links that were escaped with ~np~ tags
+            // For object links, we don't have page content to check, so skip the escape check
+            if (
+                ! str_starts_with($row['fromPage'], 'objectlink:') &&
+                $this->isEscapedLink($row['fromPageContent'] ?? '', $row['toPage'])
+            ) {
+                if ($debug == 2) {
+                    echo tr('%0 [from: %1]: escaped with ~np~ tags', $row['toPage'], $row['fromPage']) . '<br />';
+                } elseif ($debug) {
+                    $tmp[] = [$row['toPage'], $row['fromPage'], 'escaped with ~np~ tags'];
+                }
+                continue;
+            }
+
             foreach ($ignorepages as $ipage) {
                 // test whether a substring ignores this page, ignore case
                 if (fnmatch(mb_strtolower($ipage), mb_strtolower($row['fromPage'])) === true) {
                     if ($debug == 2) { // the "hardcore case"
-                        echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('ignored') . '<br />';
+                        echo tr('%0 [from: %1]: ignored', $row['toPage'], $row['fromPage']) . '<br />';
                     } elseif ($debug) { // add this page to the table
                         $tmp[] = [$row['toPage'], $row['fromPage'], 'ignored'];
                     }
@@ -232,7 +266,7 @@ class WikiPluginWantedPages extends PluginsLib
                 $parts = explode(':', $row['toPage']);
                 if (count($parts) == 2) {
                     if ($debug == 2) {
-                        echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('External Wiki') . '<br />';
+                        echo tr('%0 [from: %1]: External Wiki', $row['toPage'], $row['fromPage']) . '<br />';
                     } elseif ($debug) {
                         $tmp[] = [$row['toPage'], $row['fromPage'], 'External Wiki'];
                     }
@@ -287,7 +321,7 @@ class WikiPluginWantedPages extends PluginsLib
         if (is_array($tmp)) {
             foreach ($tmp as $row) { // row[toPage, fromPage, reason]
                 if ($debug) { // modified rejected toPages with reason
-                    $row[0] = '<em>' . tra($row[2]) . '</em>: ' . $row[0];
+                    $row[0] = tr('<em>%0</em>: %1', $row[2], $row[0]);
                 }
                 $row[0] = is_object_link($row[0]) ? parse_object_link($row[0]) : ($linkin . $row[0] . $linkout); // toPages
                 $row[1] = is_object_link($row[1]) ? parse_object_link($row[1]) : '((' . $row[1] . '))'; // fromPages
@@ -365,6 +399,7 @@ class WikiPluginWantedPages extends PluginsLib
         if (TikiLib::lib('parser')->option['is_markdown']) {
             $sOutput = TikiLib::lib('parser')->parse_data($sOutput, ['is_markdown' => false, 'is_html' => true]);
         }
+
         return $sOutput;
     }
 }
@@ -453,7 +488,7 @@ if (! function_exists('debug_print')) {
     function debug_print($row, $debug, $message)
     {
         if ($debug == 2) {
-            echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . $message . '<br />';
+            echo tr('%0 [from: %1]: %2', $row['toPage'], $row['fromPage'], $message) . '<br />';
             return;
         } elseif ($debug) {
             $tmp[] = [$row['toPage'], $row['fromPage'], $message];



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

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/a19298412c4d33e699d9ef404cdb48628f577756
You're receiving this email because of your account on gitlab.com.

_______________________________________________
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.