[web-news] master: Fix handling of missing parent messages in `ThreadTree`

From: Date: Mon, 09 Mar 2026 20:15:00 +0000
Subject: [web-news] master: Fix handling of missing parent messages in `ThreadTree`
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-33596@lists.php.net to get a copy of this message
Author: Tim Düsterhus (TimWolla) Committer: Derick Rethans (derickr) Date: 2026-03-09T16:14:57-04:00 Commit: https://github.com/php/web-news/commit/65aa28903719172c6fae3957248533b5a8cebff5 Raw diff: https://github.com/php/web-news/commit/65aa28903719172c6fae3957248533b5a8cebff5.diff Fix handling of missing parent messages in ThreadTree The logic to correctly associate messages where the parent message is not in the archives already existed by means of ThreadTree::$extraRootChildren, however the “extra root” threads were not correctly printed, because printThread() required the message at the root of the thread to exist. Fix this by printing a placeholder “Unknown message” for unknown messageIds and then printing the children as usual. Fixes php/web-php#35 Changed paths: M lib/ThreadTree.php Diff: diff --git a/lib/ThreadTree.php b/lib/ThreadTree.php index 06e4434..399cac5 100644 --- a/lib/ThreadTree.php +++ b/lib/ThreadTree.php @@ -133,16 +133,14 @@ public function printThread( return; } - if (array_key_exists($messageId, $this->articleNumbers)) { - $articleNumber = $this->articleNumbers[$messageId]; - # for debugging that we've actually handled all articles - #unset($this->articleNumbers[$messageId]); + # for debugging that we've actually handled all articles + #unset($this->articleNumbers[$messageId]); - $details = $this->articles[$articleNumber]; - - echo '<li>'; + echo '<li>'; + if (array_key_exists($messageId, $this->articleNumbers)) { + $articleNumber = $this->articleNumbers[$messageId]; $details = $this->articles[$articleNumber]; if ($articleNumber != $activeArticleNumber) { @@ -172,23 +170,26 @@ public function printThread( } else { echo "</b>"; } + } else { + echo "<i>Unknown Message</i>"; + $newSubject = $messageId; + } - if (array_key_exists($messageId, $this->tree)) { - echo '<ul>'; - foreach ($this->tree[$messageId] as $childMessageId) { - $this->printThread( - group: $group, - activeArticleNumber: $activeArticleNumber, - messageId: $childMessageId, - subject: $newSubject, - charset: $charset, - depth: $depth + 1, - ); - } - echo '</ul>'; + if (array_key_exists($messageId, $this->tree)) { + echo '<ul>'; + foreach ($this->tree[$messageId] as $childMessageId) { + $this->printThread( + group: $group, + activeArticleNumber: $activeArticleNumber, + messageId: $childMessageId, + subject: $newSubject, + charset: $charset, + depth: $depth + 1, + ); } - - echo "</li>"; + echo '</ul>'; } + + echo "</li>"; } }

« previous php.webmaster (#33596) next »