[TikiWiki-commits] [Git][tikiwiki/tiki][27.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 | <690f8b5ab2c2a_2cd4ff274797a6@gitlab-sidekiq-low-urgency-cpu-bound-v2-7d6b66dd6f-sg7v2.mail> |
Baraka Kinywa pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki Commits: 473a9e78 by Baraka Kinywa at 2025-11-08T20:20:19+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))... --- * [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 - - - - - 1 changed file: - lib/wiki-plugins/wikiplugin_wantedpages.php Changes: ===================================== lib/wiki-plugins/wikiplugin_wantedpages.php ===================================== @@ -159,6 +159,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; @@ -201,7 +220,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; @@ -221,8 +240,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`)'; } @@ -239,11 +259,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']; } @@ -256,7 +290,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']; } @@ -311,7 +345,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 @@ -389,6 +423,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; } } @@ -477,7 +512,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/473a9e787667dcc415d2b0b68287332d16f40f0b -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/473a9e787667dcc415d2b0b68287332d16f40f0b 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