[TikiWiki-commits] [Git][tikiwiki/tiki][24.x] [BP][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 <69148f9f7b192_2ce3080209ad@gitlab-sidekiq-low-urgency-cpu-bound-v2-578c67684c-79cnj.mail>

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


Commits:
acf3b3d0 by Baraka Kinywa at 2025-11-12T15:40:08+02:00
[BP][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))...
---
* [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

(cherry picked from commit 9e1af0e997243416b17305192c5c16c5c942d274)

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

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

See merge request tikiwiki/tiki!8986

(cherry picked from commit 31ab83d169e64c5397fe07870abb9c99b420abc9)

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

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

See merge request tikiwiki/tiki!8987

(cherry picked from commit 473a9e787667dcc415d2b0b68287332d16f40f0b)

See merge request tikiwiki/tiki!9014

- - - - -


1 changed file:

- lib/wiki-plugins/wikiplugin_wantedpages.php


Changes:

=====================================
lib/wiki-plugins/wikiplugin_wantedpages.php
=====================================
@@ -132,7 +132,6 @@ function wikiplugin_wantedpages_info()
 
 class WikiPluginWantedPages extends PluginsLib
 {
-
     function getDefaultArguments()
     {
         return [    'ignore' => '', // originating pages to be ignored
@@ -162,6 +161,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;
+    }
+
     function run($data, $params)
     {
         global $prefs, $page_regex;
@@ -204,7 +222,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;
@@ -224,8 +242,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`)';
         }
@@ -242,11 +261,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(TikiLib::strtolower($ipage), TikiLib::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'];
                     }
@@ -259,7 +292,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'];
                     }
@@ -314,7 +347,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,8 +423,8 @@ class WikiPluginWantedPages extends PluginsLib
         }
         $sOutput .= $endtable;
         return $sOutput;
-    } // run()
-} // class WikiPluginWantedPages
+    }
+}
 
 function wikiplugin_wantedpages($data, $params)
 {
@@ -448,8 +481,8 @@ if (! function_exists('fnmatch')) {
             return false;
         }
         return preg_match('/' . $npattern . '/i', $string);
-    } // function fnmatch
-} // !exists(fnmatch)
+    }
+}
 
 // A small function to determine whether a string is a [valid] preg expression.
 // From php help "Regular Expression Functions (Perl-Compatible)", http://www.php.net/pcre/
@@ -470,14 +503,14 @@ if (! function_exists('preg_ispreg')) {
             return strcmp($str, $matches[0]) != 0;
         }
         return true;
-    } // function preg_ispreg
-} //!exists(preg_ispreg)
+    }
+}
 
 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/acf3b3d03c3f5b084c0dc67c48b0070797a2c536

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