[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] tracker URL field: restore wiki-link label rendering in URL-as-link mode

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69b1cb59d8e42_3b189ebc96120@gitlab-sidekiq-low-urgency-cpu-bound-v2-6d4b95ff96-pnp4r.mail>

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


Commits:
94f46ed3 by Sammy Ndabo at 2026-03-11T19:59:01+00:00
[FIX] tracker URL field: restore wiki-link label rendering in URL-as-link mode
---
* [FIX] Url.php: preserve wiki link labels in URL field output

* [DOC] Url.php: clarify normalization behavior for wiki link rendering

* [FIX] tracker URL field: restore wiki-link label rendering in URL-as-link mode

See merge request tikiwiki/tiki!9662

- - - - -


1 changed file:

- lib/core/Tracker/Field/Url.php


Changes:

=====================================
lib/core/Tracker/Field/Url.php
=====================================
@@ -73,8 +73,10 @@ class Tracker_Field_Url extends \Tracker\Field\AbstractItemField implements \Tra
     public function renderOutput($context = [])
     {
         $smarty = TikiLib::lib('smarty');
+        $rawValue = (string) $this->getConfiguration('value');
+        $parsedWikiLink = self::extractParsedWikiLinkData(trim($rawValue));
 
-        $url = self::normalizeStoredValueToUrl((string) $this->getConfiguration('value'));
+        $url = self::normalizeStoredValueToUrl($rawValue);
 
         if ($url === '' || ($context['list_mode'] ?? '') === 'csv' || $this->getOption('linkToURL') == 1) {
             return $url;
@@ -91,7 +93,7 @@ class Tracker_Field_Url extends \Tracker\Field\AbstractItemField implements \Tra
                 [
                     'type' => 'external',
                     'id' => $url,
-                    'title' => $url,
+                    'title' => $parsedWikiLink['label'] ?? $url,
                 ],
                 $smarty->getEmptyInternalTemplate()
             );
@@ -134,7 +136,7 @@ class Tracker_Field_Url extends \Tracker\Field\AbstractItemField implements \Tra
         }
 
         if (self::isWikiSyntaxLink($trimmed)) {
-            $resolvedHref = self::extractFirstHrefFromParsedWikiLink($trimmed);
+            $resolvedHref = self::extractParsedWikiLinkData($trimmed)['href'] ?? null;
             if ($resolvedHref === null) {
                 return tr('Invalid wiki syntax. The link target could not be resolved.');
             }
@@ -210,19 +212,26 @@ class Tracker_Field_Url extends \Tracker\Field\AbstractItemField implements \Tra
             return $value;
         }
 
-        $resolvedHref = self::extractFirstHrefFromParsedWikiLink($trimmed);
+        $resolvedHref = self::extractParsedWikiLinkData($trimmed)['href'] ?? null;
+        // Normalization keeps only the resolved target URL.
+        // The optional wiki-link label is extracted separately for rendering.
         return $resolvedHref ?? $value;
     }
 
-    protected static function extractFirstHrefFromParsedWikiLink(string $value): ?string
+    protected static function extractParsedWikiLinkData(string $value): ?array
     {
         $parsed = TikiLib::lib('parser')->parse_data_simple($value);
 
-        if (! preg_match('/<a\b[^>]*\bhref=(["\'])(.*?)\1/i', $parsed, $matches)) {
+        if (! preg_match('/<a\b[^>]*\bhref=(["\'])(.*?)\1[^>]*>(.*?)<\/a>/is', $parsed, $matches)) {
             return null;
         }
 
-        return html_entity_decode($matches[2], ENT_QUOTES, 'UTF-8');
+        $label = trim(html_entity_decode(strip_tags($matches[3]), ENT_QUOTES, 'UTF-8'));
+
+        return [
+            'href' => html_entity_decode($matches[2], ENT_QUOTES, 'UTF-8'),
+            'label' => $label !== '' ? $label : null,
+        ];
     }
 
     protected static function isSyntacticallyValidUrl(string $url): bool



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

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