[phd] master: support manual attribute for cross-manual redirects (#274)

From: Date: Tue, 24 Nov 2026 17:37:21 +0000
Subject: [phd] master: support manual attribute for cross-manual redirects (#274)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-24010@lists.php.net to get a copy of this message
Author: Jordi Kroon (jordikroon) Committer: GitHub (web-flow) Pusher: jordikroon Date: 2026-11-24T18:37:17+01:00 Commit: https://github.com/php/phd/commit/fe7013fdd4571eb739d5e0a9e71d724bad182723 Raw diff: https://github.com/php/phd/commit/fe7013fdd4571eb739d5e0a9e71d724bad182723.diff support manual attribute for cross-manual redirects (#274) Changed paths: A tests/redirects/data/parse_004_extensions.xml A tests/redirects/data/parse_004_manual_serve.xml A tests/redirects/data/parse_004_manual_value.xml A tests/redirects/parse_004.phpt M phpdotnet/phd/Redirects.php Diff: 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<string,string>, in_manual: array<string,string>, both: array<string,string>, in_place: array<string,string>} */ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<redirects> + <group scope="shortcut"> + <redirect from="tut.php" to="install"/> + <redirect from="mysql.trace-mode" to="mysql.configuration#ini.mysql.trace-mode" manual="extensions"/> + </group> + <group scope="in-manual"> + <redirect from="pool.submitto" to="pool.submitTo" manual="extensions"/> + <redirect from="only.french" to="seulement" manual="fr"/> + </group> + <group scope="both"> + <redirect from="set.mongodb" to="book.mongodb" manual="extensions"/> + </group> +</redirects> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<redirects> + <group scope="shortcut" serve="in-place"> + <redirect from="apcu" to="book.apcu" manual="extensions"/> + </group> +</redirects> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<redirects> + <group scope="shortcut"> + <redirect from="apcu" to="book.apcu" manual="../pecl"/> + </group> +</redirects> 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-- +<?php +namespace phpdotnet\phd; + +require_once __DIR__ . '/../setup.php'; + +$maps = Redirects::parse(__DIR__ . '/data/parse_004_extensions.xml'); +echo json_encode($maps, JSON_UNESCAPED_SLASHES) . PHP_EOL; + +$ids = Redirects::collectXmlIds(__DIR__ . '/data/docs'); +echo 'Broken targets: ' . count(Redirects::findBrokenTargets($maps, $ids)) . PHP_EOL; + +foreach (['manual_value', 'manual_serve'] as $name) { + try { + Redirects::parse(__DIR__ . "/data/parse_004_$name.xml"); + echo 'no error' . PHP_EOL; + } catch (\Error $e) { + echo $e->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

« previous php.doc.cvs (#24010) next »