Author: Tim Düsterhus (TimWolla)
Committer: Derick Rethans (derickr)
Date: 2026-03-09T16:14:57-04:00
Commit: Fix handling of missing parent messages in `ThreadTree` · php/web-news@65aa289 · GitHub
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>";
}
}