From 62fd4645c24a56e70c5fa953d8092231167ee3a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= <ae@php.net>
Date: Mon, 2 Dec 2024 09:34:12 -0300
Subject: [PATCH 1/2] Recursive XInclude and some automatix fixups for
 translations

---
 configure.php | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/configure.php b/configure.php
index 35b34eba4..cf2f50cbc 100755
--- a/configure.php
+++ b/configure.php
@@ -799,6 +799,38 @@ function getFileModificationHistory(): array {
     }
 }
 
+{   # Automatic xi:include / xi:fallback fixups
+
+    $xpath = new DOMXPath( $dom );
+    $nodes = $xpath->query( "//*[local-name()='include']" );
+    foreach( $nodes as $node )
+    {
+        $fixup = null;
+        $parent = $node->parentNode;
+        $tagName = $parent->nodeName;
+        switch( $tagName )
+        {
+            case "refentry":
+                $fixup = "";
+                break;
+            case "refsect1":
+                $fixup = "<title></title>";
+                break;
+            default:
+                echo "Unknown parent element, validation may fail: $tagName\n";
+                continue;
+        }
+        if ( $fixup != "" )
+        {
+            $other = new DOMDocument( '1.0' , 'utf8' );
+            $other->loadXML( $fixup );
+            $insert = $dom->importNode( $other->documentElement , true );
+            $node->parentNode->insertBefore( $insert , $node );
+        }
+        $node->parentNode->removeChild( $node );
+    }
+}
+
 echo "Validating {$ac["INPUT_FILENAME"]}... ";
 flush();
 if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{

From ec5b19d8f2a34dad83a3585b66f7082780c6d1b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= <ae@php.net>
Date: Mon, 2 Dec 2024 10:45:02 -0300
Subject: [PATCH 2/2] Recursive XInclude and some automatix fixups for
 translations

---
 configure.php | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/configure.php b/configure.php
index cf2f50cbc..fa26ad285 100755
--- a/configure.php
+++ b/configure.php
@@ -775,13 +775,28 @@ function getFileModificationHistory(): array {
 echo "done.\n";
 
 echo "Running XInclude/XPointer... ";
-$status = $dom->xinclude();
-if ($status === -1) {
+$total = 0;
+$maxrun = 10; //LIBXML_VERSION >= 21100 ? 1 : 10;
+for( $run = 0 ; $run < $maxrun ; $run++ )
+{
+    if ( $run > 0 )
+        echo "$run ";
+    libxml_clear_errors();
+    $status = (int) $dom->xinclude();
+    if ( $status <= 0 )
+        break;
+    $total += $status;
+    if ( $maxrun > 1 && $run + 1 >= $maxrun )
+    {
+        echo "Recursive XInclude is too deep.\n";
+        errors_are_bad(-1);
+    }
+}
+
+if ($total == 0) {
     echo "failed.\n";
 } else {
-    /* For some dumb reason when no substitution are made it returns false instead of 0... */
-    $status = (int) $status;
-    echo "done. Performed $status XIncludes\n";
+    echo "done. Performed $total XIncludes.\n";
 }
 flush();
 
@@ -818,7 +833,7 @@ function getFileModificationHistory(): array {
                 break;
             default:
                 echo "Unknown parent element, validation may fail: $tagName\n";
-                continue;
+                continue 2;
         }
         if ( $fixup != "" )
         {