From ea3af527e1f9db5bafed2f6dfd58df6c6cb93596 Mon Sep 17 00:00:00 2001 From: Jordi Kroon Date: Mon, 23 Nov 2026 21:33:44 +0100 Subject: [PATCH] support manual attribute for cross-manual redirects --- phpdotnet/phd/Redirects.php | 21 ++++++++++++-- tests/redirects/data/parse_004_extensions.xml | 14 ++++++++++ .../redirects/data/parse_004_manual_serve.xml | 6 ++++ .../redirects/data/parse_004_manual_value.xml | 6 ++++ tests/redirects/parse_004.phpt | 28 +++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/redirects/data/parse_004_extensions.xml create mode 100644 tests/redirects/data/parse_004_manual_serve.xml create mode 100644 tests/redirects/data/parse_004_manual_value.xml create mode 100644 tests/redirects/parse_004.phpt diff --git a/phpdotnet/phd/Redirects.php b/phpdotnet/phd/Redirects.php index 0ccf0233..fee1b7b8 100644 --- a/phpdotnet/phd/Redirects.php +++ b/phpdotnet/phd/Redirects.php @@ -11,7 +11,9 @@ * * Every `to=` value is validated against xml:ids collected from the * language root and the docbook root (typically doc-base); a missing - * target aborts the build. + * target aborts the build. A redirect with a manual= attribute leads to + * another manual (e.g. manual="extensions" for doc-extensions), which is + * built on its own: its target is not validated. */ final class Redirects { @@ -93,6 +95,9 @@ public static function renderTo(string $outputDir, string $xmlRoot, OutputHandle * redirect: its entries go to `in_place` so that the page is served at * the requested URL instead of answering a 301. * + * The target of a redirect with a manual= attribute is a page of that + * manual, served from /manual/{manual}/: it is emitted as `{manual}/{to}`. + * * @return array{shortcut: array, in_manual: array, both: array, in_place: array} */ public static function parse(string $path): array @@ -144,6 +149,14 @@ public static function parse(string $path): array if ($from === '' || $to === '') { throw new \Error(sprintf('Empty from/to in %s (scope=%s)', $path, $scope)); } + $manual = (string)$r['manual']; + if ($manual !== '' && !preg_match('/^[a-z][a-z0-9_-]*$/', $manual)) { + throw new \Error(sprintf('Invalid manual in %s: %s', $path, $manual)); + } + // Only a page of this manual can be served at the requested URL. + if ($manual !== '' && $key === 'in_place') { + throw new \Error(sprintf('Cannot serve a page of another manual in place in %s: %s -> %s', $path, $from, $to)); + } // A bare URI is either redirected or served in place, never both. $duplicate = $key === 'shortcut' || $key === 'in_place' ? isset($maps['shortcut'][$from]) || isset($maps['in_place'][$from]) @@ -155,7 +168,7 @@ public static function parse(string $path): array if ($key === 'in_place' && str_contains($to, '#')) { throw new \Error(sprintf('Cannot serve an anchor in place in %s: %s -> %s', $path, $from, $to)); } - $maps[$key][$from] = $to; + $maps[$key][$from] = $manual === '' ? $to : "$manual/$to"; } } @@ -206,6 +219,10 @@ public static function findBrokenTargets(array $maps, array $ids, array $prefixe $broken = []; foreach ($maps as $scope => $entries) { foreach ($entries as $from => $to) { + // A page of another manual (`{manual}/{to}`) cannot be checked here. + if (str_contains($to, '/')) { + continue; + } $base = explode('#', $to, 2)[0]; foreach ($prefixes as $p) { $key = $p . $base; diff --git a/tests/redirects/data/parse_004_extensions.xml b/tests/redirects/data/parse_004_extensions.xml new file mode 100644 index 00000000..5f064151 --- /dev/null +++ b/tests/redirects/data/parse_004_extensions.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/tests/redirects/data/parse_004_manual_serve.xml b/tests/redirects/data/parse_004_manual_serve.xml new file mode 100644 index 00000000..ceb3f862 --- /dev/null +++ b/tests/redirects/data/parse_004_manual_serve.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/redirects/data/parse_004_manual_value.xml b/tests/redirects/data/parse_004_manual_value.xml new file mode 100644 index 00000000..b91ae139 --- /dev/null +++ b/tests/redirects/data/parse_004_manual_value.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/redirects/parse_004.phpt b/tests/redirects/parse_004.phpt new file mode 100644 index 00000000..9543d9d0 --- /dev/null +++ b/tests/redirects/parse_004.phpt @@ -0,0 +1,28 @@ +--TEST-- +Redirects parse 004 - A redirect with a manual attribute targets that manual and is not validated +--FILE-- +getMessage() . PHP_EOL; + } +} +?> +--EXPECTF-- +{"shortcut":{"tut.php":"install","mysql.trace-mode":"extensions/mysql.configuration#ini.mysql.trace-mode"},"in_manual":{"pool.submitto":"extensions/pool.submitTo","only.french":"fr/seulement"},"both":{"set.mongodb":"extensions/book.mongodb"},"in_place":[]} +Broken targets: 0 +Invalid manual in %sparse_004_manual_value.xml: ../pecl +Cannot serve a page of another manual in place in %sparse_004_manual_serve.xml: apcu -> book.apcu