11#!/usr/bin/env php
22<?php // vim: ts=4 sw=4 et tw=78 fdm=marker
3-
43/*
54 +----------------------------------------------------------------------+
6- | Copyright (c) 1997-2023 The PHP Group |
5+ | Copyright (c) 1997-2026 The PHP Group |
76 +----------------------------------------------------------------------+
87 | This source file is subject to version 3.01 of the PHP license, |
98 | that is bundled with this package in the file LICENSE, and is |
1615 | Authors: Dave Barr <dave@php.net> |
1716 | Hannes Magnusson <bjori@php.net> |
1817 | Gwynne Raskind <gwynne@php.net> |
19- | André L F S Bacci <gwynne @php.net> |
18+ | André L F S Bacci <ae @php.net> |
2019 +----------------------------------------------------------------------+
2120*/
2221
2726
2827echo "configure.php on PHP " . phpversion () . ", libxml " . LIBXML_DOTTED_VERSION . "\n\n" ;
2928
30- // init_argv()
31- // init_checks()
32- // init_clean()
33- // xml_configure()
34- // xml_parse()
35- // xml_xinclude()
36- // xml_validate()
37- // phd_sources()
38- // phd_version()
39- // php_history()
29+ // gereral structure/ordeing for refactoring this code
30+
31+ // init_parse() // todo: argv parsing into a typed static class, remove all global
32+ // init_check() // todo: move all checks in one place
33+ // init_usage()
34+ // git_clean() partial done
35+ // git_status() partial done
36+ // dtd_conf_entities() done
37+ // dtd_file_entities() done
38+ // dom_load/save() done
39+ // xinclude_byid() done
40+ // xinclude_xpointer() done
41+ // xinclude_residua() done
42+ // xml_partial_output
43+ // xml_validation
44+ // phd_acronym() done
45+ // phd_sources() done
46+ // phd_version() done
47+ // php_history() done
48+
49+ // ugly: make_scripts_executable
4050
4151const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook ' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os ' . DIRECTORY_SEPARATOR . 'rng ' . DIRECTORY_SEPARATOR ;
4252const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng ' ;
@@ -556,9 +566,10 @@ function find_xml_files($path) // {{{
556566 $ output = str_replace ( "\n\n" , "\n" , $ output );
557567echo "\n" , trim ( $ output ) . "\n\n" ;
558568
569+ // DTD configuration before first loading
559570
560- xml_configure ();
561- function xml_configure ()
571+ dtd_conf_entities ();
572+ function dtd_conf_entities ()
562573{
563574 global $ ac ;
564575 $ lang = $ ac ["LANG " ];
@@ -598,21 +609,28 @@ function xml_configure()
598609
599610globbetyglob ("{$ ac ['basedir ' ]}/scripts " , 'make_scripts_executable ' );
600611
601-
602- { # file-entities.php
603-
604- $ cmd = array ();
605- $ cmd [] = $ ac ['PHP ' ];
606- $ cmd [] = __DIR__ . "/scripts/file-entities.php " ;
607- if ( $ ac ["LANG " ] != "en " )
608- $ cmd [] = $ ac ["LANG " ];
609- if ( $ ac ['CHMENABLED ' ] == 'yes ' )
610- $ cmd [] = '--chmonly ' ;
611- foreach ( $ cmd as & $ part )
612+ dtd_file_entities ();
613+ function dtd_file_entities ()
614+ {
615+ global $ ac ;
616+ $ lang = $ ac ["LANG " ];
617+ $ withphp = $ ac ['PHP ' ];
618+ $ withchm = $ ac ['CHMENABLED ' ] == 'yes ' ;
619+
620+ $ parts = array ();
621+ $ parts [] = $ withphp ;
622+ $ parts [] = __DIR__ . "/scripts/file-entities.php " ;
623+ if ( $ lang != "en " )
624+ $ parts [] = $ lang ;
625+ if ( $ withchm )
626+ $ parts [] = '--chmonly ' ;
627+
628+ foreach ( $ parts as & $ part )
612629 $ part = escapeshellarg ( $ part );
630+ $ cmd = implode ( ' ' , $ parts );
613631 $ ret = 0 ;
614- $ cmd = implode ( ' ' , $ cmd );
615632 passthru ( $ cmd , $ ret );
633+
616634 if ( $ ret != 0 )
617635 {
618636 echo "doc-base/scripts/file-entities.php FAILED. \n" ;
@@ -702,7 +720,7 @@ function xinclude_run_byid( DOMDocument $dom )
702720 // libxml does not implements the XInclude 1.1 spec,
703721 // so we need to simulate its *recursive* nature here.
704722 $ total = 0 ;
705- $ maxrun = 10 ; //LIBXML_VERSION >= 21100 ? 1 : 10;
723+ $ maxrun = 10 ;
706724 for ( $ run = 0 ; $ run < $ maxrun ; $ run ++ )
707725 {
708726 $ xpath = new DOMXPath ( $ dom );
@@ -744,7 +762,7 @@ function xinclude_run_byid( DOMDocument $dom )
744762 if ( ! $ changed )
745763 return $ total ;
746764 }
747- echo "XInclude nested too deeply (xml:id). \n" ;
765+ echo "XInclude nested too deeply (by xml:id). Update `configure.php` . \n" ;
748766 errors_are_bad ( 1 );
749767}
750768
@@ -767,7 +785,7 @@ function xinclude_run_xpointer( DOMDocument $dom ) : int
767785 if ( $ was === $ now )
768786 return $ total ;
769787 }
770- echo "XInclude nested too deeply (xpointer). \n" ;
788+ echo "XInclude nested too deeply (xpointer). Update `configure.php`. \n" ;
771789 errors_are_bad ( 1 );
772790}
773791
@@ -776,52 +794,54 @@ function xinclude_residual_fixup( DOMDocument $dom )
776794 // XInclude failures are soft errors on translations, so remove
777795 // residual XInclude tags on translations to keep them building.
778796
779- $ debugFile = "temp/xinclude-debug.xml " ;
780- $ debugPath = __DIR__ . "/ {$ debugFile }" ;
781- $ nodes = xinclude_residual_list ( $ dom );
797+ $ debugFile1 = "temp/xinclude-fixup-before.xml " ;
798+ $ debugFile2 = "temp/xinclude-fixup-result.xml " ;
782799
800+ $ nodes = xinclude_residual_list ( $ dom );
783801 if ( count ( $ nodes ) > 0 )
784802 {
785803 unset( $ nodes );
786- dom_saveload ( $ dom , $ debugPath );
787- $ nodes = $ nodes = xinclude_residual_list ( $ dom );
804+ dom_saveload ( $ dom , __DIR__ . " / { $ debugFile1 }" );
805+ $ nodes = xinclude_residual_list ( $ dom );
788806 }
789807
790- $ count = 0 ;
808+ $ fixups = 0 ;
791809 $ explain = false ;
792810
793811 foreach ( $ nodes as $ node )
794812 {
795- if ( $ count === 0 )
796- {
797- echo "\nFailed XIncludes, manual parts will be missing. " ;
798- echo " Inspect {$ debugFile } for context. Failed targets are: \n" ;
799- }
800- echo "- {$ node ->getAttribute ("xpointer " )}\n" ;
801- $ count ++;
802-
803813 $ fixup = null ;
804- $ parent = $ node ->parentNode ;
805- $ tagName = $ parent ->nodeName ;
806- switch ( $ tagName )
814+ $ parent = $ node ->parentNode ->nodeName ;
815+ $ target = $ node ->getAttribute ("xpointer " );
816+ $ alert = "[Failed XInclude ' $ target'] " ;
817+
818+ if ( $ fixups === 0 )
819+ echo "\nFailed XIncludes, manual parts will be missing. Failed XInclude targets: \n" ;
820+ echo "- {$ target }\n" ;
821+ $ fixups ++;
822+
823+ switch ( $ parent )
807824 {
825+ case "listitem " :
826+ $ fixup = "<para> $ alert</para> " ;
808827 case "refentry " :
809828 $ fixup = "" ;
810829 break ;
811830 case "refsect1 " :
812- $ fixup = "<title>_</title><simpara>_ </simpara> " ; // https://github.com/php/phd/issues/181
831+ $ fixup = "<title>_</title><simpara> $ alert </simpara> " ; // https://github.com/php/phd/issues/181
813832 break ;
814833 case "tbody " :
815- $ fixup = "<row><entry></entry></row> " ;
834+ $ fixup = "<row><entry> $ alert </entry></row> " ;
816835 break ;
817836 case "variablelist " :
818- $ fixup = "<varlistentry><term></term><listitem><simpara></simpara></listitem></varlistentry> " ;
837+ $ fixup = "<varlistentry><term></term><listitem><simpara> $ alert </simpara></listitem></varlistentry> " ;
819838 break ;
820839 default :
821- echo "Unknown parent of failed XInclude: $ tagName \n" ;
840+ echo " ( Unknown parent of failed XInclude: $ parent ) \n" ;
822841 $ explain = true ;
823842 continue 2 ;
824843 }
844+
825845 if ( $ fixup !== null )
826846 {
827847 $ other = new DOMDocument ( '1.0 ' , 'utf8 ' );
@@ -837,22 +857,32 @@ function xinclude_residual_fixup( DOMDocument $dom )
837857
838858 if ( $ explain )
839859 {
860+ dom_saveload ( $ dom , __DIR__ . "/ {$ debugFile2 }" );
861+
840862 echo <<<MSG
841- \nIf you are seeing this message on a translation, this means that
842- XInclude/XPointers failures reported above are so many or unknown,
843- that configure.php cannot patch the translated manual into a validating
844- state. Please report any "Unknown parent" messages on the doc-base
845- repository, and focus on fixing XInclude/XPointers failures above. \n\n
863+
864+ If you are seeing this message in a translation, it means that
865+ the XInclude/XPointers failures reported above are so numerous or unknown,
866+ that configure.php cannot fix up the translated manual to a validating state.
867+ Please report any "Unknown parent" messages to the doc-base repository
868+ and focus on fixing all the XInclude/XPointers failures listed above.
869+
870+ Dumped {$ debugFile1 } .
871+ Dumped {$ debugFile2 } .
872+
846873MSG ;
847874 exit ( 1 ); // stop here, do not let more messages further confuse the matter
848875 }
849876
850- if ( $ count > 0 )
877+ if ( $ fixups > 0 )
851878 echo "\n" ;
852879
853- // XInclude by xml:id never duplicates xml:id, horever, also using
854- // XInclude by XPath/XPointer may start causing duplications
855- // (see docs/structure.md). Crude and ugly fixup ahead, beware!
880+ // XInclude by xml:id never duplicates xml:id. Horever, using
881+ // XInclude by XPath/XPointer with a XInclude 1.0 library will cause
882+ // xml:id duplication, as xml:id have no special tratament in this version.
883+ // See docs/structure.md for details.
884+
885+ // Crude and ugly fixup ahead, beware!
856886
857887 $ list = [];
858888 $ see = false ;
@@ -873,12 +903,18 @@ function xinclude_residual_fixup( DOMDocument $dom )
873903 $ list [ $ id ] = $ id ;
874904 }
875905 if ( $ see )
876- echo " See: https://github.com/php/doc-base/blob/master/docs/structure.md#xmlid-structure \n" ;
906+ {
907+ echo "\n See: https://github.com/php/doc-base/blob/master/docs/structure.md#xmlid-structure " ;
908+ echo "\n And: https://github.com/php/doc-base/tree/master/scripts/translation " ;
909+ echo "\n In special, qaxml-attributes.php and qaxml-entities.php, with and without --urgent. " ;
910+ echo "\n\n" ;
911+ }
877912
878- $ fatal = $ GLOBALS [ ' ac ' ][ ' LANG ' ] == ' en ' ;
913+ // Duplicated strucutral xml:ids are fatal on doc-en
879914
915+ $ fatal = $ GLOBALS ['ac ' ]['LANG ' ] == 'en ' ;
880916 if ( $ see && $ fatal )
881- errors_are_bad ( 1 ); // Duplicated strucutral xml:ids are fatal on doc-en
917+ errors_are_bad ( 1 );
882918}
883919
884920function xinclude_residual_list ( DOMDocument $ dom ) : DOMNodeList
@@ -1130,5 +1166,4 @@ function phd_version()
11301166
11311167CAT ;
11321168
1133- individual_xml_broken_check ();
11341169exit (0 ); // Finished successfully.
0 commit comments