From 44fde43f3c79dd68dd0d3581501b1ac13f19de83 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Mon, 19 Aug 2024 16:07:39 -0700 Subject: [PATCH 1/7] Fix element map so changelog rows are handled correctly --- phpdotnet/phd/Index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index 0deefdf2..f9c6741c 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -63,9 +63,9 @@ class Index extends Format 'titleabbrev' => 'format_short_desc', 'example' => 'format_example', 'refsect1' => 'format_refsect1', - 'tbody' => array( + 'row' => array( /* DEFAULT */ null, - 'row' => 'format_row', + 'tbody' => 'format_row', ), 'entry' => array( /* DEFAULT */ null, From 1e8e8d81a5b42671f368455ca06e58973c5aead7 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Wed, 21 Aug 2024 17:56:26 -0700 Subject: [PATCH 2/7] Fix format_row() to not interfere with other processing --- phpdotnet/phd/Index.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index f9c6741c..50e310cd 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -419,17 +419,19 @@ public function format_entry($open, $name, $attrs, $props) { $this->currentChangelog[] = htmlentities(trim($this->currentChangeLogString), ENT_COMPAT, "UTF-8"); } } + public function format_row($open, $name, $attrs, $props) { - if ($open) { - if ($this->inChangelog) { - end($this->ids); prev($this->ids); - $this->currentChangelog = array($this->currentMembership, current($this->ids)); - } - return; - } if ($this->inChangelog) { - $this->changelog[$this->currentid][] = $this->currentChangelog; + if ($open) { + $parent_id = $this->ids[count($this->ids) - 2]; + $this->currentChangelog = array($this->currentMembership, $parent_id); + } else { + $this->changelog[$this->currentid][] = $this->currentChangelog; + } } + + /* Fall back to regular handling so contents get processed */ + return $this->UNDEF($open, $name, $attrs, $props); } public function processFilename() { From a9bc5f139e2bda0dd56a1b59f46f7411b3cda694 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Wed, 21 Aug 2024 18:02:15 -0700 Subject: [PATCH 3/7] Use version_compare() for comparing version numbers --- phpdotnet/phd/PI/PHPDOCHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpdotnet/phd/PI/PHPDOCHandler.php b/phpdotnet/phd/PI/PHPDOCHandler.php index b7d06312..ff5f8ac1 100644 --- a/phpdotnet/phd/PI/PHPDOCHandler.php +++ b/phpdotnet/phd/PI/PHPDOCHandler.php @@ -118,7 +118,7 @@ public function parse($target, $data) { // usort() callback function used in generate-changelog-for, higest (newest) version first // 1.2.11 comes before 1.2.2, then function name (actually its id.. but close enough :)) protected static function _sortByVersion($a, $b) { - $retval = -1 * strnatcasecmp($a["version"], $b["version"]); + $retval = -1 * version_compare($a["version"], $b["version"]); if ($retval === 0) { return strnatcasecmp($a["docbook_id"], $b["docbook_id"]); From fd9d985b91ef7100fd15f470b696330d04ef21d7 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 22 Aug 2024 09:52:22 -0700 Subject: [PATCH 4/7] Split changelog entries by version This means the changelog page goes from 317K to 329K (as chunked-XHTML) due to the duplication it creates but I think that the changelog shown by version is more useful this way. --- phpdotnet/phd/IndexRepository.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/phpdotnet/phd/IndexRepository.php b/phpdotnet/phd/IndexRepository.php index b0729f6b..cd947699 100644 --- a/phpdotnet/phd/IndexRepository.php +++ b/phpdotnet/phd/IndexRepository.php @@ -103,14 +103,16 @@ private function saveChangelogs(array $changelog): void { $log = ""; foreach($changelog as $id => $arr) { foreach($arr as $entry) { - $log .= sprintf( - "INSERT INTO changelogs (membership, docbook_id, parent_id, version, description) VALUES('%s', '%s', '%s', '%s', '%s');\n", - $this->db->escapeString($entry[0] ?? ''), - $this->db->escapeString($id), - $this->db->escapeString($entry[1]), - $this->db->escapeString($entry[2]), - $this->db->escapeString($entry[3]) - ); + foreach(preg_split('/,\s+/', $entry[2]) as $version) { + $log .= sprintf( + "INSERT INTO changelogs (membership, docbook_id, parent_id, version, description) VALUES('%s', '%s', '%s', '%s', '%s');\n", + $this->db->escapeString($entry[0] ?? ''), + $this->db->escapeString($id), + $this->db->escapeString($entry[1]), + $this->db->escapeString($version), + $this->db->escapeString($entry[3]) + ); + } } } $this->db->exec('BEGIN TRANSACTION; ' . $log. ' COMMIT'); From 4a5bb1f7f881e3fe8ff3cdf9fca8d12527388f5a Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Thu, 22 Aug 2024 10:23:24 -0700 Subject: [PATCH 5/7] Use `version_compare()` when comparing versions --- phpdotnet/phd/PI/PHPDOCHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpdotnet/phd/PI/PHPDOCHandler.php b/phpdotnet/phd/PI/PHPDOCHandler.php index ff5f8ac1..99191520 100644 --- a/phpdotnet/phd/PI/PHPDOCHandler.php +++ b/phpdotnet/phd/PI/PHPDOCHandler.php @@ -138,7 +138,7 @@ protected function generateChangelogMarkup($changelogs) { $version = ""; foreach($changelogs as $entry) { - if (!$this->_changelogSince || strnatcasecmp($entry["version"], $this->_changelogSince) >= 0) { + if (!$this->_changelogSince || version_compare($entry["version"], $this->_changelogSince) >= 0) { $link = $this->format->createLink($entry["docbook_id"], $desc); if ($version == $entry["version"]) { $v = " "; From 5ef8cd7eb811db81114313197123cf584218484d Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Wed, 28 Aug 2024 15:17:34 -0700 Subject: [PATCH 6/7] Add check of changelog to indexing test --- phpdotnet/phd/Index.php | 2 +- phpdotnet/phd/TestIndex.php | 4 ++++ tests/index/data/indexing_001.xml | 25 ++++++++++++++++++++++--- tests/index/indexing_001.phpt | 11 +++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index 50e310cd..3a82ea9b 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -98,7 +98,7 @@ class Index extends Format private $inChangelog = false; private $currentChangelog = array(); private string $currentChangeLogString = ""; - private $changelog = array(); + protected $changelog = array(); private $currentMembership = null; private $commit = array(); private $POST_REPLACEMENT_INDEXES = array(); diff --git a/phpdotnet/phd/TestIndex.php b/phpdotnet/phd/TestIndex.php index d5586d19..076ddbaa 100644 --- a/phpdotnet/phd/TestIndex.php +++ b/phpdotnet/phd/TestIndex.php @@ -5,4 +5,8 @@ class TestIndex extends Index { public function getNfo(): array { return $this->nfo; } + + public function getChangelog(): array { + return $this->changelog; + } } diff --git a/tests/index/data/indexing_001.xml b/tests/index/data/indexing_001.xml index 2559d690..df3070bf 100644 --- a/tests/index/data/indexing_001.xml +++ b/tests/index/data/indexing_001.xml @@ -108,12 +108,31 @@ The <interfacename>Traversable</interfacename> interface Traversable -
+ Changelog - Changes + + + + + Version + Description + + + + + 7.3.4, 8.0.0 + Something happened. + + + PECL example 3.5.4 + Something happened in PECL. + + + + -
+
diff --git a/tests/index/indexing_001.phpt b/tests/index/indexing_001.phpt index 2f5f6dc6..7c4ac94f 100644 --- a/tests/index/indexing_001.phpt +++ b/tests/index/indexing_001.phpt @@ -24,6 +24,12 @@ $indexes = array_keys($index->getNfo()); echo "Indexes stored:\n"; var_dump($indexes); + +$changelog = array_keys($index->getChangelog()); + +echo "Changelog stored:\n"; + +var_dump($changelog); ?> --EXPECT-- Indexes stored: @@ -59,3 +65,8 @@ array(15) { [14]=> string(17) "class.traversable" } +Changelog stored: +array(1) { + [0]=> + string(17) "class.traversable" +} From 1162cd60d146dd29b8ab1e7f1bcec5497d4f1110 Mon Sep 17 00:00:00 2001 From: Jim Winstead Date: Wed, 28 Aug 2024 16:12:15 -0700 Subject: [PATCH 7/7] Add test for GH-87 --- tests/bug_GH-87.phpt | 65 ++++++++++++++++++++++++++++++++++++++++ tests/data/bug_GH-87.xml | 27 +++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/bug_GH-87.phpt create mode 100644 tests/data/bug_GH-87.xml diff --git a/tests/bug_GH-87.phpt b/tests/bug_GH-87.phpt new file mode 100644 index 00000000..b5f6e1eb --- /dev/null +++ b/tests/bug_GH-87.phpt @@ -0,0 +1,65 @@ +--TEST-- +GH-87 Broken links for constants in table rows +--FILE-- +setForce_index(true); +$config->setXml_file($xml_file); + +$indexRepository = new IndexRepository(new \SQLite3(":memory:")); +$indexRepository->init(); +$config->set_indexcache($indexRepository); + +$index = new TestIndex($indexRepository, $config); + +$render = new TestRender(new Reader, $config, null, $index); + +$render->run(); + +$render = new TestRender(new Reader, $config); + +$format = new TestGenericChunkedXHTML($config); + +$render->attach($format); + +$render->run(); + +?> +--EXPECT-- +Filename: constants.html +Content: +
+
+

Constant within a table (GH-87)

+

+ + + + + + + + + + + + + + + + +
Header
CONSTANT_IS_DEFINED
+ +

+
+ +
diff --git a/tests/data/bug_GH-87.xml b/tests/data/bug_GH-87.xml new file mode 100644 index 00000000..32ce13d7 --- /dev/null +++ b/tests/data/bug_GH-87.xml @@ -0,0 +1,27 @@ + + +
+ Constant within a table (GH-87) + + + + + + Header + + + + + CONSTANT_IS_DEFINED + + + + + +
+
+ + CONSTANT_IS_DEFINED + +
+