YUML MediaWiki Extension
From Sindri's Personal Wiki
I just created a MediaWiki extension to add yUML images using a simple wiki syntax.
The idea is to make wiki code like:
<classdiagram> [Customer]+1->*[Order] [Order]++1-items >*[LineItem] [Order]-0..1>[PaymentMethod] </classdiagram>
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"> [Customer]+1->*[Order] [Order]++1-items >*[LineItem] [Order]-0..1>[PaymentMethod] </classdiagram>
gives:
Here is the code:
<?php // Author: Sindri Traustason http://sindri.info //Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $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){ $scale=";scale:".$args["scale"]; } $yumldir = ""; if($args["dir"] != null){ $yumldir=";dir:".$args["dir"]; } $uml_code = preg_replace( array("/\n/", "/,,/"), array(", ", "," ), trim($input)); $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.
