Skip to content

Support alternative separator for the “nodes” parameter (avoid hard-coded comma) #33

@marclajoie123

Description

@marclajoie123

Environment
MediaWiki 1.43.3
Semantic MediaWiki 6.0.1
KnowledgeGraph: 3.0.0-beta (37872ef)
PHP 8.1.33 (fpm-fcgi)
MySQL 8.0.37
Elasticsearch 7.10.2
Pygments 2.14.0
LUA 5.1.5

Summary

The “nodes=” parameter of the #knowledgegraph parser function currently uses a comma as a hard-coded separator. This creates problems when page titles themselves contain commas, especially in legal, academic, and bibliographic contexts where commas are common. As a result, KnowledgeGraph incorrectly splits such titles into multiple nodes.

Current Behavior in KnowledgeGraph.php

In applyDefaultParams(), parameters of type “array” are parsed using this regex:
preg_split(’/\s*,\s*/’, $val, -1, PREG_SPLIT_NO_EMPTY); (line 436)

Since the “nodes” parameter is declared as:
‘nodes’ => [ ‘’, ‘array’ ],

any page title containing a comma will be split, preventing KnowledgeGraph from resolving the correct Title object and causing missing or broken nodes.

Why this is a problem

Many wikis rely on page titles that legitimately contain commas, such as:
• legal citations
• court decision titles
• bibliographic entries
• company name, institution, etc

In my use case, it is caselaw. For example I have a page for a Canada Supreme Court Decision : 2747-3174 Québec Inc. v. Quebec (Régie des permis d'alcool), 1996 CanLII 153 (SCC), [1996] 3 SCR 919

These pages cannot be used as nodes in KnowledgeGraph because the comma forces a split.

Requested Feature
Please consider allowing an alternative separator for the “nodes” parameter, such as:
; (semicolon)

or a configurable option in LocalSettings.php or KnowledgeGraphOptions.js.

Example:
{{#knowledgegraph:
nodes=Page A; Page B; Page C
|properties=HasRelation
}}

This would preserve commas inside page titles.

Possible Implementation

A minimal backward-compatible approach could be:
• Only modify the separator for “nodes”, not for other parameters
• Allow both commas and semicolons, for example:
if ( $key === ‘nodes’ ) {
$val = preg_split(’/\s*[;,]\s*/’, $val);
} else {
$val = preg_split(’/\s*,\s*/’, $val);
}

Benefits

• Full support for page titles containing commas
• Better interoperability when titles follow standard citation formats
• Increased usability of KnowledgeGraph for legal, academic, and bibliographic data
• Minimal impact on existing functionality

Thank you for considering this enhancement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions