Skip to content

Commit 27b74be

Browse files
authored
Render XInclide failures, small changes on configure.php and translation qaxml sync tools (#277)
* New fix-up on configure.php. * Help links for some warnings. * Speeling, comments, renames on internal files of QA tools.
1 parent 9be9fbb commit 27b74be

14 files changed

Lines changed: 129 additions & 98 deletions

configure.php

Lines changed: 99 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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 |
@@ -16,7 +15,7 @@
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

@@ -27,16 +26,27 @@
2726

2827
echo "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

4151
const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
4252
const 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 );
557567
echo "\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

599610
globbetyglob("{$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+
846873
MSG;
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

884920
function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList
@@ -1130,5 +1166,4 @@ function phd_version()
11301166
11311167
CAT;
11321168

1133-
individual_xml_broken_check();
11341169
exit(0); // Finished successfully.

scripts/translation/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ for inconsistencies. These tools check for structural differences
66
that may cause translation build failures or non-validating DocBook XML
77
results, and fixing these issues will help avoid build failures.
88

9-
Some checks are less structural, and as not all translations are identical,
9+
Some checks are not strictly structural, and as not all translations are identical,
1010
or use the same conventions, they may not be entirely applicable in all
1111
languages. Even two translators working on one language may have different
1212
opinions on how much synchronization is wanted, so not all scripts will be of
1313
use for all translations.
1414

15-
Because of the above, it's possible to silence each alert indempendly. These
15+
Because of the above, it's possible to silence each output indempendly. These
1616
scripts will output `--add-ignore` commands that, if executed, will omit the
1717
specific alerts in future executions.
1818

@@ -25,8 +25,8 @@ or if XML contents are not
2525

2626
Unbalanced XML contents are invalid XML and will result in a broken build.
2727
BOM and CR marks may not result in broken builds, but *will* cause several
28-
tools below to misbehave, as `libxml` behaviour changes if XML text contains
29-
these bytes.
28+
tools below to misbehave, as *behaviour* of `libxml` itself changes if XML
29+
text contains these bytes.
3030

3131
## qaxml-attributes.php
3232

@@ -77,7 +77,7 @@ mismatched tag, to facilitate the work on big files.
7777

7878
This script also accepts an `--content=` option, that will check the
7979
*contents* of tags, to inspect tags where the contents are expected *not* to
80-
be translated. Example below.
80+
be translated. See example below.
8181

8282
## qaxml-ws.php
8383

@@ -95,13 +95,13 @@ locally generated `revcheck.php` status pages.
9595

9696
## Suggested execution
9797

98-
The first execution of these scripts may generate an inordinate amount of
99-
alerts. It's advised to initially run each command separately, and work the
98+
The first execution of these scripts may generate an inordinate amount of
99+
alerts. It's advised to initially run each command separately, and work the
100100
alerts on a case by case basis. After all interesting cases are fixed,
101101
it's possible to rerun the command and `grep` the output for `--add-ignore`
102102
lines, run these commands, and by so, mass ignore the residual alerts.
103103

104-
Structural checks:
104+
Strict structural checks:
105105

106106
```
107107
php doc-base/scripts/broken.php
@@ -114,7 +114,7 @@ php doc-base/scripts/translation/qaxml-tags.php --detail
114114
php doc-base/scripts/translation/qaxml-ws.php
115115
```
116116

117-
Tags where is expected no translations:
117+
Tags where is expected **no** translations:
118118

119119
```
120120
php doc-base/scripts/translation/qaxml-tags.php --content=acronym

scripts/translation/libqa/ArgvParser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
1616
# Description
1717
18-
This class coordinates and centrailzes control for $argv command line
19-
parameters, used between vairous classes. */
18+
Analysis and consumption of command-line parameters ($argv) */
2019

2120
class ArgvParser
2221
{

scripts/translation/libqa/OutputBuffer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
1616
# Description
1717
18-
This class caches formatted output, and calculates if this output is not
19-
previously marked as ignored, before printing it. */
18+
This class caches the formatted output and calculates whether that
19+
output has not been previously marked as ignored before printing it. */
2020

2121
class OutputBuffer
2222
{

scripts/translation/libqa/OutputIgnore.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
1616
# Description
1717
18-
This class process commands for ignoring outputs, and complement non
19-
ignored outputs with these commands. */
18+
This class processes commands and tests for omitted local outputs. */
2019

2120
class OutputIgnore
2221
{

scripts/translation/libqa/SyncFileItem.php renamed to scripts/translation/libqa/QaxmlPairItem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
1616
# Description
1717
18-
Holds file related data for synq XML tools. */
18+
Contains the file path pairs used in all QAXML tools. */
1919

2020
require_once __DIR__ . '/all.php';
2121

22-
class SyncFileItem
22+
class QaxmlPairItem
2323
{
2424
public string $sourceDir;
2525
public string $targetDir;

0 commit comments

Comments
 (0)