Extension:Diagrams

Category:MIT licensed extensions
MediaWiki extensions manual
Diagrams
Release status: stableCategory:Stable extensions
Implementation Tag Category:Tag extensions
Description Display various types of diagrams rendered from text within wiki pages.
Author(s) Sam Wilson (Samwilsontalk)
Latest version 0.14.0 (2024-08-27)
Compatibility policy Master maintains backward compatibility.Category:Extensions with master compatibility policy
MediaWiki >= 1.34.0, <= 1.43
Database changes No
Composer samwilson/diagramsCategory:Extensions supporting Composer
License MIT License
Download Category:Extensions in GitHub version control
README
$wgDiagramsServiceUrl
<graphviz>, <mscgen>, and <uml>
Category:All extensions

The Diagrams extension displays GraphViz, Mscgen, PlantUML, and Mermaid diagrams in a wiki. It can be configured to use a small web service to render the images.

It replaces the GraphViz, PlantUML, and Mermaid extensions in some ways, but does not (yet) support all features of all of them. The original reason for creating a new extension was to not store the rendered images as wiki files (as the GraphViz extension did). Still, it has changed to become a general diagramming extension.

Installation

  • Download and place the file(s) in a directory called Diagrams in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Diagrams' );
    
  • Rendering: For formats other than Mermaid, and if you do not use the external rendering service (see below), you must install graphviz, mscgen and/or plantuml on the computer running the web server. For example, on Debian or Ubuntu systems, this can be done with:
    $ sudo apt install graphviz mscgen plantuml
    
  • If you get the following error:
Diagrams error (with plantuml command): /bin/bash: line 1: plantuml: command not found

then discover where your plantuml binary is with:

which plantuml

then open your LocalSettings.php and add this line pointing to the plantuml binary

$wgDiagramsPlantumlCommand = '/usr/bin/plantuml';
  • Private wikis: if you are using image authorization then you need to add the following to LocalSettings.php:
    $wgUploadPath = "$wgScriptPath/img_auth.php";
    $wgImgAuthUrlPathMap['/diagrams/'] = 'mwstore://local-backend/local-public/diagrams/';
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Optional external rendering

This extension can also be configured to generate the diagram files using an external rendering web service. This is useful if you do not want the rendered files to be stored in the wiki or have security requirements that make it more convenient to run the external rendering commands somewhere other than on the web server.

Earlier versions of this extension required this service, but since 0.4.0, it's been optional.

There are two implementations of the service:

  1. A PHP (Symfony) based serviceinstallation instructions
  2. A Python-based serviceinstallation instructions, demo

Once you have the servicing installed and running correctly, add the following to your "LocalSettings.php" file:

// The URL at which you installed the Diagrams Service.
$wgDiagramsServiceUrl = 'https://diagrams.example.com/subdir';

Local rendering commands

When using the local/internal rendering (i.e., the commands are run by the web server), it may be necessary to change the command run. This can be done with the $wgDiagramsLocalCommands array. The keys of this array are mscgen, plantuml, dot, neato, fdp, sfdp, circo, or twopi.

For example, to set a custom location for the PlantUML jar file:

$wgDiagramsLocalCommands = [
	'plantuml' => '/usr/bin/java -jar /usr/local/bin/plantuml-1.2024.6.jar',
];

Usage

This extension adds four tags: <graphviz>, <mscgen>, <uml>, and <mermaid>.

See also

Category:GraphViz extensions Category:Graph extensions
Category:All extensions Category:Extensions in GitHub version control Category:Extensions supporting Composer Category:Extensions with master compatibility policy Category:GraphViz extensions Category:Graph extensions Category:MIT licensed extensions Category:ParserFirstCallInit extensions Category:Stable extensions Category:Tag extensions