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

"Baraka Kinywa \(@bkinywa24\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <690f638e9514f_2ce362060497@gitlab-sidekiq-low-urgency-cpu-bound-v2-7d6b66dd6f-ggbrn.mail>

Baraka Kinywa pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
9e1af0e9 by Baraka Kinywa at 2025-11-08T17:30:16+02: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))...
---
* [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


(cherry picked from commit a19298412c4d33e699d9ef404cdb48628f577756)

03e7fb04 [FIX] Plugin Wanted Pages: Exclude links that are written like ((Page 1))...

Co-authored-by: Baraka Kinywa <[email protected]>

See merge request tikiwiki/tiki!8985

- - - - -


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;
@@ -202,7 +221,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;
@@ -222,8 +241,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`)';
         }
@@ -240,11 +260,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'];
                     }
@@ -257,7 +291,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'];
                     }
@@ -312,7 +346,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
@@ -390,6 +424,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;
     }
 }
@@ -478,7 +513,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/9e1af0e997243416b17305192c5c16c5c942d274

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