YUML MediaWiki Extension

From Sindri's Personal Wiki

Jump to: navigation, search

I just created a MediaWiki extension to add yUML images using a simple wiki syntax.

The idea is to make wiki code like:

 [Order]++1-items >*[LineItem]

generate a img tag pointing to the respective yUML generated image.

Here comes the first test:

and here is a use case:

You can use two attribute parameters, type will make it use the scruffy type if you set it to "scruffy" and scale will set the scale of the image rendered. For example

 <classdiagram type="scruffy" scale="125">
 [Order]++1-items >*[LineItem]


Here is the code:

// Author: Sindri Traustason http://sindri.info
//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
	$wgHooks['ParserFirstCallInit'][] = 'efYUMLInit';
} else { // Otherwise do things the old fashioned way
	$wgExtensionFunctions[] = 'efYUMLInit';
function efYUMLInit() {
	global $wgParser;
	$wgParser->setHook( 'classdiagram', 'efClassdiagramRender' );
	$wgParser->setHook( 'usecase', 'efUsecaseRender' );
	return true;

function yUMLRenderDiagram( $input, $args, $diagramType ) {
	$type = "";
	if($args["type"] != null){
		$type = "/".$args["type"];
	$scale = "";
	if($args["scale"] != null){
	$yumldir = "";
	if($args["dir"] != null){
	$uml_code = preg_replace(
		array("/\n/", "/,,/"),
		array(", ",   ","   ),
	$output = "<img src=\"http://yUML.me/diagram".$type.$scale.$yumldir."/".$diagramType."/";
	return $output.htmlspecialchars( $uml_code )."\"/>";
function efClassdiagramRender( $input, $args, $parser ) {
	return yUMLRenderDiagram( $input, $args, "class" );
function efUsecaseRender( $input, $args, $parser ) {
	return yUMLRenderDiagram( $input, $args, "usecase" );

To install it, put the code above in extensions/yUML/yUML.php and add the line

 require_once( "$IP/extensions/yUML/yUML.php" );

to LocalSettings.php in your MediaWiki folder.

Personal tools