You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(api): extract shared trait for the three KnowledgeGraphApiLoad* endpoints
KnowledgeGraphApiLoadNodes, KnowledgeGraphApiLoadProperties, and
KnowledgeGraphApiLoadCategories duplicated the same execute() shape,
which had already produced identical copy-paste bugs (see #92) across
two of the three classes. New KnowledgeGraphApiLoadTrait centralizes
the shared init/loop/response logic; each class now only implements
getTitlesToLoad() and getPropertiesForTitle().
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/) and
13
13
-`$wgKnowledgeGraphListSeparator` config variable (default `,`): the `nodes=`/`properties=` parser-function parameters were always split on a hard-coded comma via `KnowledgeGraph::applyDefaultParams()`, which incorrectly fragmented page titles or property names that themselves contain a comma (e.g. legal citations, bibliographic entries). The separator is now configurable per wiki, analogous to `$wgPageFormsListSeparator` ([#33](https://github.com/SemanticMediaWiki/KnowledgeGraph/issues/33), [#48](https://github.com/SemanticMediaWiki/KnowledgeGraph/issues/48)). Note: PR [#50](https://github.com/SemanticMediaWiki/KnowledgeGraph/pull/50) proposed a different fix for #48 (reassembling comma-split fragments by probing `Title::isKnown()`), which only papers over the symptom for titles that already exist and doesn't address the underlying hard-coded separator raised in #33; this change addresses the root cause instead.
14
14
15
15
### Changed
16
+
- `KnowledgeGraphApiLoadNodes`, `KnowledgeGraphApiLoadProperties`, and `KnowledgeGraphApiLoadCategories` (`includes/api/`) shared the same `execute()` shape (init SMW, resolve each requested title/category-member to semantic data via `KnowledgeGraph::setSemanticDataFromApi()`, `json_encode()` the result, `addValue()`) independently in three places — the same structure that had already produced identical copy-paste bugs across two of the three classes (both referencing the undeclared `self::$data` instead of `\KnowledgeGraph::$data`, see #92 above). Extracted the shared shape into a new `KnowledgeGraphApiLoadTrait` (`isWriteMode()`, `mustBePosted()`, `needsToken()`, `execute()`); each class now implements only two small abstract hooks, `getTitlesToLoad()` (which titles/category members to process) and `getPropertiesForTitle()` (which properties to load for a given title), with `KnowledgeGraphApiLoadCategories` also keeping its per-class `buildPropertiesList()` and its running properties accumulator (now an instance property instead of a value threaded through local variables) needed to carry accumulated properties across category members within one request. Purely structural — no externally observable change to any endpoint's response shape ([#93](https://github.com/SemanticMediaWiki/KnowledgeGraph/issues/93))
16
17
- `KnowledgeGraph::setSemanticDataFromApi()` no longer reads/writes the public static `KnowledgeGraph::$data` or the private static `KnowledgeGraph::$relationsSeen` as an implicit communication channel with its callers; it now takes `$data`/`$relationsSeen` as by-reference parameters (accumulating across its own recursion) and also returns `$data`, so a call's result is explicit rather than something callers had to read back out of shared static state afterwards. `KnowledgeGraphApiLoadNodes`, `KnowledgeGraphApiLoadProperties`, and `KnowledgeGraphApiLoadCategories` (as well as `KnowledgeGraph::parserFunctionKnowledgeGraph()`) now each thread their own local `$data`/`$relationsSeen` through the call instead of relying on `\KnowledgeGraph::$data`/external reset discipline; this also fixes `KnowledgeGraphApiLoadCategories::execute()`'s pre-existing `self::$data` reference (a class with no such declared property, working only because the read is guarded by `isset()`) and removes the class of fatal ("Access to undeclared static property") this pattern had already caused twice before (see #68, #69 above). The now-unused `KnowledgeGraph::resetSeenRelations()` test-support method (and its dedicated test) was removed, since resetting shared state between calls/tests is no longer necessary ([#92](https://github.com/SemanticMediaWiki/KnowledgeGraph/issues/92))
0 commit comments