Jump to content

Extension:SaintapediaGraph

From mediawiki.org
MediaWiki extensions manual
SaintapediaGraph
Release status: stable
Implementation Parser function
Description Turns Cargo query results into interactive Mermaid flowcharts — org charts, funding networks, styled and grouped graphs
Author(s) Tom O'Neill, Saintapedia contributors
Maintainer(s) Tom O'Neill
Latest version 0.2.5 (2026-08-15)
Compatibility policy Main branch maintains backward compatibility.
MediaWiki 1.39+
PHP 8.1+
Database changes No

  • $wgSaintapediaGraphDefaultDirection
  • $wgSaintapediaGraphDefaultLimit
  • $wgSaintapediaGraphMaxLimit
  • $wgSaintapediaGraphClickable
  • $wgSaintapediaGraphDefaultTheme
  • $wgSaintapediaGraphUseStandaloneRenderer
  • $wgSaintapediaGraphWarnCycles
  • $wgSaintapediaGraphBreakCycles
  • $wgSaintapediaGraphStylePalette
Licence GNU General Public License 2.0 or later
Download
README
CHANGELOG
Help Help:Saintapedia Graph
Example Example gallery on Saintapedia

The SaintapediaGraph extension turns Cargo tables into interactive Mermaid flowcharts through the parser function {{#saintapedia_graph:}}. A Cargo query supplies the rows; the extension derives nodes and edges from named columns and renders a clickable diagram whose nodes link back to wiki pages. Three shapes are supported: parent/child hierarchies (org charts), one-row-per-arrow networks, and dual-table graphs where node attributes and edges live in separate Cargo tables.

It does not require Mermaid . Mermaid 10.9.1 is bundled and served from the wiki origin by ResourceLoader, so no CDN is contacted. No database tables are created, so update.php is not needed.

Developed for Saintapedia (diocese and parish org charts, funder → fundee grant networks), and usable on any wiki already running Cargo.

Features

[edit]
  • Three diagram modes from one parser function: hierarchy, edge, and dual-table
  • Nodes link to the wiki pages the rows came from (same-origin local paths only)
  • Colour nodes by any Cargo column (style_by) and group them into subgraphs (subgraph_by)
  • Edge captions from a column (edge_label), and a choice of arrow styles
  • Directed-cycle detection: warn about, or automatically drop, cycle-closing edges
  • Built-in Mermaid themes, allowlisted, with per-diagram override
  • Row caps per Cargo query with a visible warning when a graph is truncated
  • format=raw (aliases source, text) prints the generated Mermaid source for debugging
  • Bundled help page, two wrapper templates, and an optional set of worked examples
  • Mermaid is bundled (MIT) and loaded same-origin — no CDN, and Extension:Mermaid is not required

Not yet supported (0.2.5): N-hop graph expansion, Sankey diagrams, hover tooltips on nodes, and SVG/PNG export.

Installation

[edit]
Warning Warning: Deploy 0.2.5 (or main after it). Do not deploy the v0.2.4, v0.2.3, v0.2.2, or v0.2.1 tags: v0.2.4 is docs-only and still initialises Mermaid with securityLevel: 'loose' rather than the hardened 'antiscript' setting shipped in 0.2.5.


  • Download and move the extracted SaintapediaGraph folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/SaintapediaGraph
    
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Cargo' );
    wfLoadExtension( 'SaintapediaGraph' );
    
  • Requires Cargo . Load Cargo before this extension.
  • The directory must be named SaintapediaGraph — the ResourceLoader remote path depends on it.
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Clone from GitHub:

cd extensions/
git clone https://github.com/Saintapedia/SaintapediaGraph.git SaintapediaGraph

Add to LocalSettings.php after Cargo:

wfLoadExtension( 'Cargo' );
wfLoadExtension( 'SaintapediaGraph' );

No database updates are required. Check Special:Version for Saintapedia Graph 0.2.5.

Help page and templates

[edit]

The bundled help page and the Org chart / Funding network wrapper templates are optional but recommended. Wikis without shell access can use Special:Import with one of the XML dumps below — download the raw file (it must start with <?xml version="1.0"), not the GitHub HTML page:

From the shell:

# MediaWiki 1.40+
php maintenance/run.php SaintapediaGraph:importPages

# MediaWiki 1.39
php extensions/SaintapediaGraph/maintenance/importPages.php

# Preview only:  --dry-run
# Replace pages: --overwrite

# Also import the sample OrgDemo / GrantDemo data and example pages:
php maintenance/run.php SaintapediaGraph:importPages --examples
php extensions/Cargo/maintenance/cargoRecreateData.php --table OrgDemo
php extensions/Cargo/maintenance/cargoRecreateData.php --table GrantDemo

The sample tables are deliberately named OrgDemo and GrantDemo so they cannot collide with a wiki's own Organization or Grant templates, and the sample pages are a fictional archdiocese, its dioceses, and its parishes. The old title Saintapedia Graph demo now redirects to Help:Saintapedia Graph/Examples.

Without shell access: importing the examples XML creates the sample pages and a Cargo template for each demo table (using #cargo_declare/#cargo_store), but the Cargo data tables themselves are not populated automatically. After the import, null-edit the imported Template:OrgDemo and Template:GrantDemo pages (open for editing and save with no changes) so Cargo registers the declarations, then use Special:CargoTables → Create data table for each. See Help:Saintapedia Graph/Create tables for the walkthrough; this replaces cargoRecreateData.php for wikis that can't run maintenance scripts.

Usage

[edit]

The parser function is {{#saintapedia_graph: … }}, with {{#cargo_mermaid: … }} kept as an alias. Parameter names are case-insensitive, and spaces or hyphens are read as underscores (join on = join_on).

Pick one mode per diagram. Mixing parent_field with source_field/target_field is an error.

Mode Required parameters One row is Cargo queries
Hierarchy (org chart) tables= + parent_field= a child node 1
Edge (network) tables= + source_field= + target_field= one arrow 1
Dual-table nodes_table= + edges_table= + source/target fields a node, then an arrow 2

Dual mode runs two Cargo queries and counts as two expensive parser functions against $wgExpensiveParserFunctionLimit.

Org chart

[edit]

Each row is a child; an empty parent_field makes it a root. Parents that have no row of their own are still drawn, and can inherit a subgraph grouping from their first child if they have no group of their own.

{{#saintapedia_graph:
tables=Organizations
|fields=_pageName=Name,ParentOrg,Type,Country
|parent_field=ParentOrg
|node_id=Name
|style_by=Type
|subgraph_by=Country
|direction=TD
}}

Edge (network)

[edit]

Each row is one arrow from source_field to target_field. style_by and subgraph_by are read from the same row and are applied to the source node only.

{{#saintapedia_graph:
tables=Patronage
|fields=Saint,Place,Feast
|source_field=Saint
|target_field=Place
|edge_label=Feast
|direction=LR
}}

Dual-table funding network

[edit]

The first query supplies node labels, links, colours, and groups; the second supplies the arrows. Endpoints missing from the node query are still drawn, unstyled, and edge rows never overwrite node styling. The edge query always runs with offset 0.

{{#saintapedia_graph:
nodes_table=Organizations
|nodes_fields=_pageName=Name,Type,Country
|edges_table=Grants
|edges_fields=Funder,Recipient,Amount
|edges_where=Year>=2023
|node_id=_pageName
|node_label=Name
|source_field=Funder
|target_field=Recipient
|edge_label=Amount
|style_by=Type
|subgraph_by=Country
|direction=LR
|theme=forest
}}

In dual mode the edge endpoints are usually page titles, so prefer node_id=_pageName with node_label=Name. If node_id=Name is used instead, that column has to equal the page title or the arrows will not meet their nodes.

Wrapper templates

[edit]

importPages installs two templates that cover the common cases without spelling out every parameter:

{{Org chart|table=Parishes|parent=Diocese|id=_pageName|style=Type}}
{{Funding network|nodes=Organizations|edges=Grants|style=Type|edges_where=Year>=2023}}

Other uses

[edit]

The same three modes cover most page types; only the table and column names change.

Diagram Mode Approach
Archdiocese → diocese → parish Hierarchy parent_field=Diocese (or ParentOrg)
One diocese's parishes Hierarchy add where=Diocese="…"
Deanery or family of parishes Hierarchy parish parent is the deanery page
Religious province → houses Hierarchy parent_field=Province
Schools under their parishes Hierarchy parent is the parish; style_by=Level
Episcopal consecration lineage Hierarchy parent_field=Consecrator
Foundation → parish grants Dual-table nodes are places, edges are grant rows
One funder's portfolio Edge where=Funder="…"
Twin or clustered parishes Edge link_style=<-->
Patron saint of a place Edge saint → place
Suppressed see → successor Edge target_field=SucceededBy

After importPages --examples, each of those is its own Help:Saintapedia Graph/… page carrying the snippet and the live graph together; the index is Help:Saintapedia Graph/Examples.

Diagram parameters

[edit]
Parameter Default Role
tables / table — Cargo table(s). join on is required with more than one.
fields, where, group by, having, order by, limit — Passed to Cargo. Fields the diagram needs are appended automatically.
offset 0 Skip rows. Single-query modes only — dual mode's edge query always uses offset 0.
nodes_* / edges_* — Per-query equivalents for dual mode (nodes_fields, edges_where, …)
direction site TD TD/TB, LR, BT, RL
node_id _pageName Stable node identity
node_label node_id Visible node text
page_field _pageName for hierarchy/dual; the endpoint value itself for edge mode Page the node links to
edge_label — Arrow caption, truncated at about 64 characters
style_by / subgraph_by — Real Cargo column names: colour by, and group by. In edge mode these apply to the source node.
link_style --> -->, -.->, ==>, ---, <-->
clickable site yes yes/no (also accepts true/false, 1/0, on/off)
theme site default default, base, dark, forest, neutral
warn_cycles / break_cycles yes / no Report, or drop, cycle-closing edges
format mermaid raw (aliases source, text) prints the Mermaid source instead of rendering

Anything outside the allowlists (an unknown theme, a limit over the maximum or below 1) still renders the graph and adds a warning underneath it rather than failing the page. The full reference is on Help:Saintapedia Graph.

Configuration

[edit]
$wgSaintapediaGraphDefaultDirection
Flowchart direction when direction= is omitted: TD, LR, BT, or RL (TB is read as TD). Default: TD.
$wgSaintapediaGraphDefaultLimit
Rows fetched per Cargo query when limit= is omitted. Default: 500.
$wgSaintapediaGraphMaxLimit
Hard cap on rows per Cargo query. A requested limit= is clamped into [1, max] and the diagram warns that rows may be missing. Dual mode applies the cap to each of its two queries, so one page can fetch up to twice this many rows. Default: 1000.
$wgSaintapediaGraphClickable
Whether nodes link to their wiki pages by default. Default: true.
$wgSaintapediaGraphDefaultTheme
Mermaid theme when theme= is omitted: default, base, dark, forest, or neutral. Default: default.
$wgSaintapediaGraphUseStandaloneRenderer
Emit interactive Mermaid containers. Set to false to show the generated source only. Default: true.
$wgSaintapediaGraphWarnCycles
Warn beneath the diagram when directed cycles are detected. Default: true.
$wgSaintapediaGraphBreakCycles
Drop the edges that close directed cycles instead of drawing them. Default: false.
$wgSaintapediaGraphStylePalette
Array of colours used for the classDef fills generated by style_by. Values are validated (hex, named colour, or a tight rgb()/hsl() form) and invalid entries are skipped. Default: ten qualitative colours.

Security

[edit]
  • Mermaid is initialised with securityLevel: 'antiscript' as of 0.2.5. Click targets still work at that level, and scripts inside the generated SVG are blocked. Earlier tags (v0.2.1–v0.2.4) used the less strict 'loose' level and should not be deployed.
  • Click targets are same-origin local paths taken from Title::getLocalURL(). Absolute and protocol-relative URLs are discarded, so a diagram cannot link off-wiki.
  • Themes, arrow styles, and palette colours are allowlisted or validated before they reach the generated source.
  • Diagram source is base64-encoded into a data-mermaid attribute so MediaWiki's HTML tidy cannot reflow Mermaid's whitespace-sensitive syntax.

Content Security Policy

[edit]

Scripts come only from the wiki's own ResourceLoader, never a CDN, so a CSP needs nothing beyond the wiki origin in script-src. Mermaid 10 does write some presentation styles into the SVG it builds, so style-src should allow either 'unsafe-inline' or the wiki origin; a policy that forbids inline styles renders the diagrams unstyled rather than breaking them.

Interactive rendering needs JavaScript. Without it, the page shows the Mermaid source inside <noscript>.

Languages

[edit]

User-visible messages (errors, warnings, the Special:Version description) are English only, in i18n/en.json. Wikis with another $wgLanguageCode still see English text. Further languages can be added as i18n/<code>.json in the repository; the extension is not yet on translatewiki.net.

See also

[edit]