Extension talk:PlantUML

From MediaWiki.org
Jump to: navigation, search

Problem with Title[edit]

Hello! I've found a bug in the classical version - at least in combination with MediaWiki 1.15: The usage of $wgTitle as MD5 source does not work - it always results in an empty string. As a result, all images are stored as "uml--(CodeHash).png" - and when another page is saved, the cleanImages() deletes ALL images. Other (cached) pages then can't find their images unless they are re-created.

As a fix, instead of using global $wgTitle (which is also described as not to be used), I'm using the following function:

function getPageTitle() {
    global $wgArticle;
    $title = $wgArticle->getTitle()->getText();
    return $title;
}

and use getPageTitle() instead of $wgTitle.

I don't know whether this is the best solution, but for now it works as intended - image files are stored with a proper hash for the title AND are kept for all pages :) .

- Ok, thanks, I've just made the correction (April 29th, 2011)

Actually, it seems to depend of MediaWiki, so I suggest the following code:

function getPageTitle() {
   global $wgArticle;
   global $wgTitle;
   // Retrieving the title of a page is not that easy
   if (empty($wgTitle)) {
       $title = $wgArticle->getTitle()->getText();
       return $title;
   }
   return $wgTitle;
}

Any though ?

GraphViz[edit]

I found that GraphViz was required to have this working... you might want to add this to the install instructions?

- Ok, thanks for this suggestion!

Changed font[edit]

Hi - I installed on our test environment (without GraphWiz) and it worked fine (the first example on the article page). But on our real environment the font suddenly changed (test: Arial, real: some kind of joined up Word link font). Any idea why this is? The skin on both is the same. --Robinson Weijman 11:27, 5 February 2010 (UTC)

I am not sure to understand your issue. Could you contact me by mail (plantuml@gmail.com) ? Thanks - 13 February 2010

Thanks for the reply. We solved the issue - each environment had a different version of java. Now that this is corrected, the problem is resolved. --Robinson Weijman 09:17, 15 February 2010 (UTC)

Spaces in Windows Apache Home Path[edit]

On my windows machine I had to change:

 // Lauch PlantUML
  $command = "java -jar ".$plantumlJar.
              " -o ".getUploadDirectory()." ".$umlFile;

to

 // Lauch PlantUML
  $command = "java -jar ".$plantumlJar.
              " -o \"".getUploadDirectory()."\" \"".$umlFile."\"";

Otherwise the script failed because of some spaces in the installation path of the Apache. Maybe someone with more experience in php than myself could fix this to a more robust version.

How it run into CentOS?[edit]

  • It works in Ubuntu and FreeBSD, but i can't run it into CentOS.

You should double check that the Sun JVM is used, and not the OpenJDK.

error on uploading?[edit]

hello

I get this error when doing regular uploads

Fatal error: Call to a member function getTitle() on a non-object in /var/www/tids/extensions/PlantUML.php on line 181

BTW useful extension and thanks

Msevero 08:06, 30 April 2011 (UTC)

Ok, I just change the getPageTitle() function. Does it work better ?

PlantUML 20:19, 30 April 2011 (UTC)

CPanel Centos php.ini edit fix[edit]

In running my MediaWiki off of a CPanel hosted site I was continually getting:

[An error occured in PlantUML extension]

Every now and then I would see this:

Warning: copy() [function.copy]: URL file-access is disabled in the server configuration in /home/username/public_html/extensions/PlantUML.php on line 98

Warning: copy(http://www.plantuml.com/plantuml/img/ROr1RW8n34NtEOMNPT4B83GIK9LkA8jH3_0Ph19D9XuSJojktoI3119Tsdv-pwNUnn6AWQR47H9lqFNVAbCyRIM8qXkqRnaxPOxkYLwhokyC7eB_uGS2dObkH4-iCt0CMVsiU4HgBC1ufxZ-KolATudsYO5fAvDwLkU-4YkjLlGn3OZKD6wvXuzPPZZchoKXqVxQNaA1rkCOV0VpKj6Nrg2sA9T3P6hFOdMTdMHd9jpnHV6KGwLh8fDp_RMXc-asbqL1tHo-pty0) [function.copy]: failed to open stream: no suitable wrapper could be found in /home/username/public_html/extensions/PlantUML.php on line 98

After some Google Searching I found references to disabling this by default to prevent certain attacks.

Create a php.ini file containing this entry:

allow_url_fopen = On

Upload it to /username/public_html (where your LocalSettings.php file would be) and now I no longer get the error messages and the PlantUML files render as expected in the article.

New classic version.[edit]

Hi, I would like to contribute a new "classic version" which follows mediawiki standards more and is able to handle image maps and SVG graphics. Pleas advise for best approach.

--Pjkersten 15:23, 5 May 2011 (UTC)

Hello, good idea! It depends wether you know already MediaWiki engine or not. Any maybe it should be better to put the code of this new "classic version" into a really repository (SVN/GIT). For imagemap, as long as there are some URL in the diagram description, a cmap file will be generated with the PNG file. (See [[1]])

You will probably have to parse this cmap file.

You may have a look to this extension Extension:ImageMap which shows how to enable imagemap in MediaWiki.

--Plantuml 17:17, 5 May 2011 (UTC)

Actually, it's already finished. Tested and working - at least, for me that is. Any preferences for bzr, sf or git?

--Pjkersten 19:59, 5 May 2011 (UTC)

Wow, I am curious to see the result. Thanks for your job. Actually, since several plugins are on [[2]] so maybe git is a good option.

--Plantuml 20:49, 5 May 2011 (UTC)

I've created a project on github If you have remarks, please mail me (somehow I don't receive updates for this page).

--Pjkersten 10:04, 6 May 2011 (UTC)

Quick & dirty fix to allow additional html tags for formatting (and linking to source picture)[edit]

Hi,

I did a small modification to the PNG rendering to add custom html tags to the <uml> header. Reason was to reduce the resulting image size. The image now also links to the original file behind.

Changed functions below. Modified and tested only the PNG case, renderSVG still has to be modified.

function renderPNG($image,$argv) { //the same...
    if ($image['map']) {
        $usemap = ' usemap="#'.$image['mapid'].'"';
    } else {
        $usemap = '';
    }
    return "<a href=\"{$image['src']}\"><img class=\"plantuml\" src=\"{$image['src']}\"$usemap $argv>{$image['map']}</a>"; //added $argv and link here
}

function renderUML( $input, $argv, $parser=null ) {
    global $plantumlImagetype;
    $image = getImage($input, $parser);
 
    if ($image['src'] == false) {
        $text = "[An error occured in PlantUML extension]";
    } else {
        if ($plantumlImagetype == 'svg') {
            $text = renderSVG($image);
        } else { //recreate html-tags from $argv
			$args = '';
			foreach ($argv as $tag => $tagval) 
			{
			$args .= " $tag=\"$tagval\" ";
			}
            $text = renderPNG($image,$args); //added $args to function call
        }
    }
    return $text;
}

PlantUML with a dedicated plantuml server behind proxy[edit]

Hello,

while using plantuml with a dedicated instance in cloud mode
$usecloud = true;
you should sometime be able to specify a proxy (eg. avoiding "Connect timeout" error).
To do this, you should replace "copy(...)" by a dedicated mechanism including proxy config.
Here is the actual code (PlantUml.php:line 231)
function renderPlantUML_cloud($PlantUML_Source, $imgFile) {
    // Build URL that describes the image
    $img = "http://www.plantuml.com/plantuml/img/"; 
    $img .= encodep($PlantUML_Source); 
 
    // Copy images into the local cache 
    copy($img, $imgFile);
 
    if (is_file($imgFile)) {
        return $imgFile;
    }
 
    return false;
}
Here is the expecting code to set "betweenProxyHost.intranet'" proxy server : a proxy between your mediawiki server and the dedicated.plantuml.server.intranet src :
function renderPlantUML_cloud($PlantUML_Source, $imgFile) {
    // Build URL that describes the image
    $img = "http://dedicated.plantuml.server.intranet:8080/plantuml/img/"; 
    $img .= encodep($PlantUML_Source); 
 
    // Copy images into the local cache
    // -------------------------------------------
    // copy($img, $imgFile);
	$proxy = getenv("http_proxy");
	if ($proxy == "") {
		$proxy = "betweenProxyHost.intranet:3128";
	}
	$proxyOpt = "tcp://" . $proxy;

 	$opts = array(
  				'http'=>array
				(
					'method'=>"GET",
					'proxy' => $proxyOpt,
					'request_fulluri' => true  
				)
			);
	$context = stream_context_create($opts);
	
	$contentx = file_get_contents($img,false,$context);
	$openedfile = fopen($imgFile, "w");
	fwrite($openedfile, $contentx);
	fclose($openedfile);	
	// -------------------------------------------
	
 
    if (is_file($imgFile)) {
        return $imgFile;
    }
 
    return false;
}
Enjoy.
--Boly38 (talk) 13:18, 19 February 2013 (UTC)

Strange grey line shows up around the boarders of PlantUML-images[edit]

Hi!

I use mwlib to generate PDF articles from MediaWiki documents. We use PlantUML with Graphviz 2.30.0. Of some strange reason, under the UML diagram pictures strange grey lines always appear on the converted PDF-files. See picture.

http://img211.imageshack.us/img211/7321/6e3s.png

Anyone got any idea of to fix this and take away the grey lines? Thanks in advance!

PS:

The grey lines shows up only in the PDF-documents, not the WikiaArticles they were generated from. When you view the PDF file in Ubuntu, the entire images has a grey border around it, and in Windows it's only the line below the image like in the picture above.

--Samuelspik (talk) 14:54, 31 July 2013 (UTC)

X11 connection rejected because of wrong authentication[edit]

I am trying to run PlantUML on a linux hosted wiki.

I keep getting a "X11 connection rejected because of wrong authentication" error when the java command runs. Any ideas on how to deal with this?

Thanks

/usr/bin/java -jar /data/mediawiki/extensions/PlantUml/plantuml.jar -tsvg -o "/data/mediawiki/web_support/images" "/data/mediawiki/web_support /images/uml-ebd4e0d7be03d05feba0724a4aee627b-b77cde4509f8f99422145350f34866e7.uml"
 X11 connection rejected because of wrong authentication.
 Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
	at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
	at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:77)
	at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:122)
	at java.security.AccessController.doPrivileged(AccessController.java:229)
	at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:86)
	at java.lang.J9VMInternals.initializeImpl(Native Method)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:241)
	at java.lang.Class.forNameImpl(Native Method)
	at java.lang.Class.forName(Class.java:139)
	at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:113)
	at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:92)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1163)
	at net.sourceforge.plantuml.EmptyImageBuilder.<init>(Unknown Source)
	at net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek.<clinit>(Unknown Source)
	at java.lang.J9VMInternals.initializeImpl(Native Method)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:241)
	at net.sourceforge.plantuml.cucadiagram.CucaDiagram.exportDiagramInternal(Unknown Source)
	at net.sourceforge.plantuml.UmlDiagram.exportDiagram(Unknown Source)
	at net.sourceforge.plantuml.PSystemUtils.exportDiagramsCuca(Unknown Source)
	at net.sourceforge.plantuml.PSystemUtils.exportDiagrams(Unknown Source)
	at net.sourceforge.plantuml.SourceFileReader.getGeneratedImages(Unknown Source)
	at net.sourceforge.plantuml.Run.manageFileInternal(Unknown Source)
	at net.sourceforge.plantuml.Run.processArgs(Unknown Source)
	at net.sourceforge.plantuml.Run.manageAllFiles(Unknown Source)
	at net.sourceforge.plantuml.Run.main(Unknown Source)

Make output auto-resize[edit]

First, add these codes into your MediaWiki:common.css

/* Contains am image */
#imagecontain
{
}
#imagecontain img
{
max-width:100%; 
max-height:100%;
margin:auto;
display:block;
}

Then, go to plantUML.php, and change:

Original Line 382

function renderPNG($image) {
    ...
    return "<img class=\"plantuml\" src=\"{$image['src']}\"$usemap>{$image['map']}";
}

Modified Line 382

function renderPNG($image) {
    ...
    return "<div id=\"imagecontain\"><a target=\"_blank\" href=\"{$image['src']}\"><img class=\"plantuml\" src=\"{$image['src']}\"$usemap>{$image['map']}</a></div>";
}

-Joshua.yathin.yu (talk) 09:18, 20 November 2013 (UTC)

No png image generated by PlantUML is shown when we generate a book with Collection[edit]

We installed the PlantUML, GraphViz and Collection extensions. To generate the books with Collection we have installed a render server. When we try to generate a book adding pages with PlantUML graphics, they are not displayed in the generated pdf. Is there any way to display them in the book?

- Did you found a way around this? I want to know to how can I get the diagrams into generated PDFs.

Java[edit]

OK, I know this is obvious, but it created a little bit of trouble before getting the solution. When you make a local install you must have java installed to make "plantuml.jar" work, otherwise you get an error. --Gborgonovo (talk) 10:45, 5 March 2014 (UTC)

Using this extension in templates[edit]

<uml>actor Mik #99FF99</uml> will return the uml object after being processed by the PlantUML extension.

But this wont work if you use the uml tag in a template and you want to build your uml code with triple braces vaiables.

To bypass this problem, I created the function {{#uml:...}}, included in my extension MikFunctions, which calls the renderUML function after the raw wikitext has been processed.

Links within PlantUML when using cloud[edit]

Links can be embedded with the PlantUML extension

e.g. <uml> participant Bob [[http://www.yahoo.com]] Bob -> Alice : [[http://www.google.com]] hello </uml>

will provide links if code is changed as per pull request at https://github.com/pjkersten/PlantUML/pull/12

SELinux[edit]

I found that the Java command could run from the terminal, but that Apache could not run it. /var/log/messages told me "SELinux is preventing /usr/java/jre1.8.0_31/bin/java from using the execmem access on a process." sealert suggested I ran the following command, which solved the problem:

setsebool -P httpd_execmem 1

RobFisher (talk) 10:59, 26 February 2015 (UTC)

usecloud has no effect[edit]

I have the setting $usecloud = false;

But i get the failure Warning: copy(http://www.plantuml.com/plantuml/img/LOz1JuD048Nl-oiczQ96sDGZ8HfjJIIfaKZu0TDb2YlBGdPdGxNslmiO3ts7oNkJzmwV652rM1EiDWQzrmeslJ6aMFVMh-1gkqYyxp-d7wG_KGHFpk7NJdiMudziYMFV1wVeqBkQui6WvT2PYzsMkdujbWktV_5Uf7AkYNAea2a1R3cGCT2YjO3X0AghOZeIjAGjmJCvKWthEjWQQlB4tmmZkOhitLAV3EIlULHwSd2TPKLPV1IFD-dUWNmGNbD3a5dFQ0pEY907spAi4sYO1vz8EOvZt56bSTIjZYSQEHlvScIoVbea-SnMlkt4fDEf61ogXkpv_0i0) [function.copy]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\inetpub\wwwroot\wiki\extensions\PlantUML\PlantUML.php on line 262

An in the wiki page:
[An error occured in PlantUML extension]

what to do?

PlantUML Causes Java to hog CPU then generates error 500[edit]

Hi; has anyone seen this scenario before?

I've noticed this on particularly long/complex UML diagrams. When submitting new UML text, or updating existing text: on submission, the MediaWiki application hangs (for all users, I think) then produces an error 500 message:

"The FastCGI process exceeded configured activity timeout"

In the meantime, the server shows that Java.exe hogs all available CPU and an increasing chunk of memory (rises from 60MB to about 90MB before conking out).

I've tried changing the default format from SVG to PNG, but no luck there. Any other suggestions for what I could try at all?

We're running a 1.24.1 instance on Windows Server 2008 R2.

Many thanks

--Dshinks (talk) 10:08, 3 October 2016 (UTC)