Jump to content
MediaWiki

Extension:ExternalUML

From mediawiki.org
Revision as of 20:36, 19 August 2016 by MaxSem (talk | contribs) (grrr)
Warning: The code or configuration described here poses a major security risk.

Site administrators: You are advised against using it until this security issue is resolved.


Problem: Vulnerable to Cross-site scripting attacks, because it passes user input directly to the browser. This may lead to user accounts being hijacked, among other things.
Solution: strictly validate user input and/or apply escaping to all characters that have a special meaning in HTML
This extension stores its source code on a editable wiki page rather than in a code repository. As a result, this code may be maliciously altered.
It may contain security vulnerabilities, and will not receive localisation updates from translatewiki.net . Developers are strongly encouraged to host their code in a code repository rather than a wiki page so that the extension can be properly maintained, reviewed, and kept secure.
MediaWiki extensions manual
ExternalUML
Release status: beta
Implementation Tag
Description Renders a UML model from text using yUML and websequencediagrams
Author(s) Various
Latest version 0.2.0 (2011年06月26日)
MediaWiki
Licence "No Blame"
Download see below


ExternalUML is an extension written for MediaWiki that renders a UML model from text using the online services yUML and websequencediagrams. These tools use scripting languages to automatically place the visual elements of diagrams. This supports class diagrams, activity diagrams, use case diagrams, and sequence diagrams.


License

The "No Blame" License.

Feel free to use this code as you wish, so long as you assume full responsibility for the consequences of said use. That is to say, don't blame the author(s) if something goes wrong. This code can be shared without any restrictions, as long as you accept the fact that it is your fault if something goes wrong. Although this program is distributed in the hope that it will be useful, it is provided WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Usage

Use the corresponding scripting language inside of the <uml></uml> tag.


Example Class

 <uml class>
 [Customer]+1->*[Order]
 [Order]++1-items >*[LineItem]
 [Order]-0..1>[PaymentMethod{bg:orange}]
 </uml>


Example Sequence

 <uml sequence>
 Janice->Greg: Status Request
 alt normal case
 Greg->Janice: Everything's fine
 else exceptional case
 Greg->Janice: Things are out of sync
 note right of Greg: Greg clears the cache 
 end
 </uml>


Example Activity

 <uml activity>
 (start)-><d1>logged in->(Show Dashboard)->|a|->(end)
 <d1>not logged in->(Show Login)->|a|
 </uml>


Example Use Case

 <uml usecase>
 [Customer]-(Login)
 [Customer]-(note: Cust can be registered or not{bg:beige})
 </uml>


Installation

  1. Copy & paste the code below in a file called ExternalUML.php and place it in your extensions directory of your MediaWiki folder.
  2. Put this line near the end of your LocalSettings.php in the MediaWiki root-folder to include the extension:
require_once('extensions/ExternalUML.php');


Code

Version 0.2.0

<?php
/**
 * Parser hook extension adds a <uml> tag to wiki markup for rendering UML
 * diagrams within a wiki page using yUML and websequencediagrams.
 *
 * Version 0.1 for sequence diagrams by James Kilts.
 * Version 0.2 changes to support other diagram types using yUML
 * based on code by Sindri Traustason
 * <http://wiki.sindri.info/wiki/YUML_MediaWiki_Extension>
 * Which had also been modified by dave@davesmith.me <http://davesmith.me/>
 * to support activity diagrams and the direction attribute.
 *
 * Parameters:
 * class|activity|usecase|sequence
 * style scruffy|nofunky|plain (except for sequence)
 * default|modern-blue|vs2010 (sequence only)
 * scale y|n (except for sequence)
 * direction lr|td (except for sequence)
 *
 * Syntax:
 * <uml class style="scruffy|nofunky|plain" scale="n" direction="lr|td">
 * [Person]->[Address]
 * </uml>
 * <uml sequence style="default|vs2010">
 * Alice->Bob: Authentication Request
 * Bob->Alice: Authentication Failure
 * </uml>
 * <uml usecase style="scruffy|nofunky|plain" scale="n" direction="lr|td">
 * [User]-(Login)
 * [User]-(Logout)
 * </uml>
 * <uml activity style="scruffy|nofunky|plain" scale="n" direction="lr|td">
 * (start)-><d1>logged in->(Show Dashboard)->|a|->(end)<d1>not logged in->(Show Login)->|a|
 * </uml>
 */
if ( !defined( 'MEDIAWIKI' ) ) {
 echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
 die( -1 );
}
 
/* Avoid unstubbing $wgParser too early on modern (1.12+) MW versions, as per r35980
 */
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
 $wgHooks['ParserFirstCallInit'][] = 'wfMetaUMLExtension';
}
else {
 $wgExtensionFunctions[] = 'wfMetaUMLExtension';
}
function wfMetaUMLExtension() {
 global $wgParser;
 $wgParser->setHook( 'uml', 'callbackGenerateUmlHtml' );
 return true;
}
function callbackGenerateUmlHtml( $input, $args ) {
 if (array_key_exists('class', $args))
 $url = getYumlImageUrl($input, $args, "class");
 else if (array_key_exists('activity', $args))
 $url = getYumlImageUrl($input, $args, "activity");
 else if (array_key_exists('usecase', $args))
 $url = getYumlImageUrl($input, $args, "usecase");
 else
 $url = getSequenceDiagramURL($input, $args);
 if ($url == false) {
 return "[An error occurred generating the UML Diagram in the ExternalUML extension]";
 }
 else {
 return "<img src='$url'>";
 }
}
function getYumlImageUrl( $input, $args, $diagramType ) {
 $style = "";
 if (array_key_exists('style', $args)) {
 $style = "/" . $args["style"];
 }
 $scale = "";
 if (array_key_exists('scale', $args)) {
 $scale=";scale:".$args["scale"];
 }
 $direction = '';
 if (array_key_exists('direction', $args)) {
 $direction=";dir:".$args['direction'];
 }
 $uml_code = preg_replace(
 array("/\n/", "/,,/"),
 array(", ", "," ),
 trim($input));
 return "http://yUML.me/diagram"
 .$style.$scale.$direction.'/'
 .$diagramType.'/'
 .$uml_code;
}
function getSequenceDiagramURL( $input, $args ) {
 /* HTTP Post to websequencediagrams.com to generate and retrieve the corresponding image
 */
 $style = "vs2010";
 if (array_key_exists('style', $args)) {
 $style = $args["style"];
 }
 $postdata = http_build_query(
 array(
 'message' => $input,
 'style' => $style,
 'apiVersion' => '1'
 )
 );
 $opts = array('http' =>
 array(
 'method' => 'POST',
 'header' => 'Content-type: application/x-www-form-urlencoded',
 'content' => $postdata
 )
 );
 $context = stream_context_create($opts);
 $result = file_get_contents('http://www.websequencediagrams.com', false, $context);
 /* Extract the "img" attribute of the JSON response.
 * Note: If json isn't available, use hardcoded:
 * strstr(substr($result, 9), '"', true);
 */
 $json_o = json_decode($result);
 return "http://www.websequencediagrams.com".$json_o->img;
}
?>

See also

AltStyle によって変換されたページ (->オリジナル) /