Extension talk:GraphViz/v0.9

= Extension_talk =

= Archived Extension_talk =

New "improved improved" version of the GraphViz-Extension
Dear Users of the GraphViz-Extension,

I am a student assistant at the FZI, a German research center. We're using the Graphviz-Extension(s) for some of our own projects.

Actually the problem is that it is not that easy to use a GraphViz Extension, because there are many different versions and improvements circulating around on mediawiki.org: some for windows and others for linux, some work out of the box and others don't, some support different renderers and others have automatic clean-up. I think you know what I mean.

So I'm currently combining the various GraphViz Extensions into one functional and up to date Extension. This means that I try to get the best out of each extension and I think that the result is a very good "improved improved" GraphViz-Extension.

My question is now if you'd mind if I was refreshing the Extension-Page (Extension:GraphViz) on MediaWiki as well. I'd like to clean up the old parts and the Discussion-Page so that there is space for some instructions.

If this is a problem, I will create another "Graphviz"-Extension, but I think that this would not help to get rid of the current chaos.

You can have a look at my current code and the corresponding page here: User:Hummel-riegel/GraphViz

Of course I'll try to name all the actual and previous contributors like the FDL/GPL-Licences specify. And as this is a wiki feel free to add some stuff if you want to.

Thanks for your response in advance, Yours sincerely

Thomas Hummel    --Hummel-riegel 13:28, 1 November 2010 (UTC)

I've added a link to Extension:GraphVizAndMSCGen, which is has some improvements for Windows and allows the use of MSCGen graphs too. Please move around these links if required or integrate the code from my extension into this one, etc.. Matthewpearson 16:36, 10 December 2008 (UTC)

Graphviz
Please compare Extension:GraphViz with Extension:Graphviz (lowercase 'v'). -- Tim Chambers 1E4AF729D5CEFFD0

tags
I have installed GraphViz on a Debain server using apt.

I seem to have most/all of the executables installed and have put Graphviz.php in the extensions directory. Unfortunately it seems that MediaWiki is not interpreting the tags.

Is there a 'preferred' way to test the extension(s)?

I trust you also added include("extensions/Graphviz.php"); $wgGraphVizSettings->dotCommand = "$DOT_PATH/dot"; to your LocalSettings.php. After that you can test if it works with the code: digraph G{ A -> B } If you see a graph with a blob A connected with an arrow to a blob B then it works.

Some of my experiences: --Coriolan 05:37, 14 Jun 2005 (UTC)
 * 1) The current sources of Graphviz.php are in Wicle's CVS.
 * 2) When compiling the Graphviz from the sources I needed the --with-mylibgd to get dot generate .png files.
 * 3) The graphs seen in IslandSeeds look better because that engine runs on Mac (see } and its follow-up.

Hi, but, nothing works, ... seems to be unreaded. Nothing inside is shown.
 * i have installed this extension on MW 1.13.0 and Ubuntu Hardy
 * i have added the path to dot /usr/bin/dot
 * i have included the php to LocalSettings
 * pngs are created, but damaged
 * the *.map files are empty 

If I am using MW 1.7.3 I do have the same problem

btw. GraphViz Category Browser is not running, too The Special Page is there, but empty

GraphViz (/usr/bin/dot) is running without trouble

--ViktorD

Windows
If we only want to directly use the GIF file, please modified as following

...     str_replace("\\",'/',      substr($timelinesrc, 0, strpos($timelinesrc,'{') )))); }     $ext = ".gif"; $src = $dest. $storagename; $imgn = $dest. $storagename. $ext; $mapn = $dest. $storagename. '.map'; if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".gif" ) || file_exists(   $src.".err" ) ) ) {     $handle = fopen($src, "w"); fwrite($handle, $timelinesrc); fclose($handle); $cmdline   = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tgif  -o '.wfEscapeShellArg($imgn).' '.wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tcmapx -o '.wfEscapeShellArg($mapn).' '.wfEscapeShellArg($src); $WshShell = new COM("WScript.Shell"); $WshShell->Exec($cmdline); $WshShell->Exec($cmdlinemap); }     ...	      $map  = str_replace(' ','',$map); $txt = ''.$map.' '.''; }     unlink($src); return $txt; } -- By Bennix, Fudan University, 2008

You must enable internet users to have read/execute access to cmd.exe before trying to use the Graphviz extension. Matt 16:44, 30 April 2008 (UTC)

What's the point in this?

if (substr(php_uname, 0, 7) == "Windows") { $ext = "gif"; } else { $ext = "png"; }

.png is used everywhere else in the file, so this actually makes it break! I removed it and changed the $txt line to always use .png.

Also I found it necessary to use $ret = `"{$cmdline}"`; instead of        $ret = `{$cmdline}`; because the default windows install directory for Graphviz is "c:\Program Files\Graphviz..." which contains a space. Without the quotes, windows assumes everything following the space is a parameter, which generates only a "'c:\Program' is not recognized as an internal or external command, operable program or batch file." error.

Thanks for the extension, it looks like it could be very useful once I get the hang of it!

--ProgMania 23:20, 3 September 2005 (UTC)

 COM("WScript.Shell") instead of shell_exec 

Using using the improved version found below on this page, I had problem getting this to work on a Windows Server 2003 machine with Apache 2.2 and PHP 5.2.6. The shell_exec command refused to execute the dot program for some reason. Replacing the two shell_exec calls with this code works for me.

$WshShell = new COM("WScript.Shell");

$WshShell->Exec($cmdline); $WshShell->Exec($cmdlinemap);

--Oskar, 2008-05-19

I found all the instructions above do not work on my Windows installation. However, the instructions found here worked the first time: http://www.wickle.com/wiki/index.php/Windows_Graphviz_Installation_Instructions. (Segraves, 2009-02-26)

safe_mode and antialiased rendering
please use popen instead of shell_exec, so that php safe_mode can work. not all of us want to run our servers as loose as a mexican whore.

i've also modified this plugin to use GraphicsMagick to render antialiased graphs from dot's svg output, it works very nice indeed. --207.109.251.117 11:26, 6 November 2005 (UTC)


 * Can you please provide the modified plugin? --202.1.193.10 17:45, 13 January 2006 (UTC)

Some Help Getting Graphviz to Work
I have an unusual set up as in I have a Uniform Server's WAMP ( Windows Apache MySQL PHP ) running from a Thumbdrive. Mediawiki ver 1.5. Graphviz.php extension installed The Graphviz is installed in the psedo drive W:\usr\local\ATT\Graphviz
 * The dot.exe is therefore W:\usr\local\ATT\Graphviz\bin

While adding in elements does have a Dos Prompt window pop-up momentarily, the resulting graph was never generated.

''Has anyone encountered this problem? And found a solution?'' Suggestions?

Directories and rights
My experiences from an install under FreeBSD 7.1:


 * Installed GraphViz from ports
 * (cd /usr/ports/graphics/graphviz/; make install clean)
 * Path for dot is: /usr/local/bin/dot, use that in LoacalSettings.php
 * create dir for images: .../wikiurl/images/graphviz/
 * replace ".../wikiurl/" with the full path for your wiki installation
 * chown www .../wikiurl/images/graphviz/
 * a cron entry to cleanup .../wikiurl/images/graphviz/ is a good idea
 * delete all png/gif/maps etc older than 7 days:
 * find .../wikiurl/images/graphviz/ -mtime +7 -type file -delete

--Schatchaos 20:20, 24 January 2009 (UTC)

Deletion of unused images
Hi is it possible to delete all the unused pngs ? i got only 20 images with graphviz, but the creationprocess produced over 400 files...(testing and stuff :) ) Is it possible to delete those ? They mess up my box :-/

Size limit and work-arounds
I'm using the GraphViz extension w/ great delight (hoping to get my company's employees to document some of their formal business processes using the GraphViz extension on the company's MediaWiki-based wiki thing). However, I have been hitting an apparent size limit on the size of the graph you can specify using the GraphViz extension (go figure... there's a size limit on GET request lengths, after all).

So, for a simple work-around, I'm advising my users to split up their graphs into several subgraphs (only slightly nasty-looking, and there's probably some slick way to make it look almost like one connected graph).

For a more complicated work-around, I'm considering making a revised version of the tag(s) (e.g. &lt;dot_graph&gt;) that would "optimize" the graph code for reduced length (only on conversion into raw HTML), doing things like stripping out comments and renaming labeled nodes (to give them a super-short name while still allowing verbose node names in the original Wiki markup).

Just a thought. Nothing's really happening yet, and I thought it would be nice to at least warn people about the length limit (above). Mlibby 17:04, 22 December 2006 (UTC)


 * Maybe I'll include an approach like this, too: http://meta.wikimedia.org/wiki/User_talk:Cygon/Graphviz_Extension#Shorting%20the%20URLs Mlibby 17:14, 22 December 2006 (UTC)

Use with MW1.10
Has anyone been able to make any of the GraphViz extensions work with MediaWiki version 1.10? I have tried both this one and the one at http://www2.hds.utc.fr/~rherault/index.php/Graphviz_Extension, and neither works. Pages show up without content (completely white) as soon as I activate the extension in LocalSettings. Any advice would be gratefully accepted. 160.33.43.231 July 2nd, 2007, 12:00pm PDT

GRAFCET
Can we create GRAFCET diagrams with this extension? (original question reformulated from French!)


 * The only reference I could find in english about this is here
 * A german Grafcet information page is here.

There seems no way to render these kind of diagrams with GraphViz yet.

Improvement
Well, I decided that it might be a good thing to incorporate those issues seen above in a version that works out of the box AND does not require anything but "standard php" compared to those two alternate versions: Alternate Version and Updated alternate Version -- the Links are dead!

This is an update ... for those who do not want to take/require the more complex version or do not have access to its required SPL module.

Known Issues
 * Well this plugin has a few issues with special characters in combination with "named naming". Just don't use them. This is true because Filesystem restrict other characters as URL's. Anyway that filename will only be used for referencing and is not displayed, so you don't have to worry if it is a workaround.

Security issues
 * This plugin does not properly sanitize user input when generating the "named" version of the files. This can lead to clobbered files and/or more serious vulnerabilities. --Andy753421 04:54, 27 July 2010 (UTC)

dotCommand *   Describes where your actual dot executable remains. * *   Windows Default: C:/Programme/ATT/Graphviz/bin/dot.exe *   Other Platform : /usr/local/bin/dot * * $wgGraphVizSettings->named *   Describes the way graph-files are named. * *   named: name of your graph and its type determine its filename *   md5  : name of your graph is based on a md5 hash of its source. *   sha1 : name of your graph is based on a SHA1 hash of its source. * *   Default : named * * $wgGraphVizSettings->install *   Gets you an errormessage if something fails, but maybe ruins your *   wiki's look. This message is in English, always. * *   Default : false * * Improvements * - Selects defaults for Windows or Unix-like automatically. * - should runs out of the box * - Creates PNG + MAP File * - additional storage modes (see discussion below) *  - Meaningful filename *  - Hash based filename *  - Configurable (name/md5/sha1) * * Storage Modes: * MD5: * + don't worry about graphnames * + pretty fast hash * - permanent cleanup necesary (manually or scripted) * - md5 is buggy - possibility that 2 graphs have the same hash but *  are not the same * SHA1: * + don't worry about graphnames * + no hash-bug as md5 * - permanent cleanup necessary (manually or scripted) * - not so fast as md5 * Named: * + Graphs have a name, now it's used * + no permanent cleanup necessary. * - Naming Conflicts *  a) if you have multiple graphs of the same name in the same *      article, you will only get 1 picture - independently if they're *		the same or not. *   b) possible naming conflicts in obscure cases (that should not happen) *     Read code for possibilities / exploits * */

class GraphVizSettings { public $dotCommand, $named, $install; };

$wgGraphVizSettings = new GraphVizSettings;

// Config // -- if ( ! (stristr (PHP_OS, 'WIN' ) === FALSE) ) { $wgGraphVizSettings->dotCommand = 'C:/Programme/ATT/Graphviz/bin/dot.exe'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; } $wgGraphVizSettings->named = 'named'; $wgGraphVizSettings->install = false;

// Media Wiki Plugin Stuff // --- $wgExtensionFunctions[] = "wfGraphVizExtension";

$wgExtensionCredits['parserhook'][] = array( 'name'=>'Graphviz',  'author'=>'CoffMan , MasterOfDesaster ',  'url'=> 'http://www.mediawiki.org/wiki/Extension:GraphViz',  'description'=>'Graphviz (http://www.graphviz.org) is a program/language that allows the creation of numerous types of graphs.  This extension allows the embedding of graphviz markup in MediaWiki pages and generates inline images to display.',  'version'=>'0.4' );

function wfGraphVizExtension { global $wgParser; $wgParser->setHook( "graphviz", "renderGraphviz" ); }

function renderGraphviz( $timelinesrc )	// Raw Script data {	global $wgUploadDirectory,	// Storage of the final png & map $wgUploadPath,			// HTML Reference $wgGraphVizSettings;	// Plugin Config

// Prepare Directories $dest = $wgUploadDirectory."/graphviz/"; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); }

$storagename = urldecode($_GET['title']).'---'; $storagename = str_replace("&",'_amp_',$storagename); $storagename = str_replace("#",'_shrp_',$storagename); $storagename = str_replace("/",'_sd_',$storagename); $storagename = str_replace("\\",'_sd_',$storagename); $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named);

if($wgGraphVizSettings->named == 'md5') { $storagename .= md5($timelinesrc); } else if ($wgGraphVizSettings->named == 'sha1') { $storagename .= sha1($timelinesrc); } else { $storagename .= trim(			str_replace("\n",'', str_replace("\\",'/',					substr($timelinesrc, 0, strpos($timelinesrc,'{') )				) )		);	}

$src = $dest. $storagename;

$imgn = $dest. $storagename. '.png'; $mapn = $dest. $storagename. '.map';

if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) ) {		$handle = fopen($src, "w"); fwrite($handle, $timelinesrc); fclose($handle);

$cmdline   = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tpng  -o '.wfEscapeShellArg($imgn).' '.wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($wgGraphVizSettings->dotCommand). ' -Tcmapx -o '.wfEscapeShellArg($mapn).' '.wfEscapeShellArg($src);

$ret = shell_exec($cmdline); if ($wgGraphVizSettings->install && $ret == "" ) { echo ' Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.' '; exit; }

$ret = shell_exec($cmdlinemap); if ($wgGraphVizSettings->install && $ret == "" ) { echo ' Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdlinemap.' '; exit; }

unlink($src); }	@$err=file_get_contents( $src.".err" );

if ( $err != "" ) { $txt = ' '.$err.'</tt> '; } else { @$map = file_get_contents( $mapn ); $map = preg_replace('#<ma(.*)>#',' ',$map); $map = str_replace(' ','',$map);

$txt = '<map name="'.$storagename.'">'.$map.' '. '<img src="'.$wgUploadPath.'/graphviz/'.$storagename.'.png"'. ' usemap="#'.$storagename.'" />'; }	return $txt; } ?>

Fixed Special Char problem
Well here is a manual patch.

Make Named Files Umlaut-safe
Look for: function renderGraphviz( $timelinesrc )

Replace these lines: $storagename = urldecode($_GET['title']).'---'; $storagename = str_replace("&",'_amp_',$storagename); $storagename = str_replace("#",'_shrp_',$storagename); $storagename = str_replace("/",'_sd_',$storagename); $storagename = str_replace("\\",'_sd_',$storagename); With that line $storagename = str_replace("%",'_perc_',urlencode($_GET['title'])).'---';

Then replace this block: } else { $storagename .= trim(                       str_replace("\n",'', str_replace("\\",'/',                                       substr($timelinesrc, 0, strpos($timelinesrc,'{') )                                ) )               );        } With that one } else { // 'named' $storagename .= str_replace("%",'_perc_',			urlencode( trim(					str_replace("\n",'', str_replace("\\",'/',							substr($timelinesrc, 0, strpos($timelinesrc,'{'))						) )				)			)		);	}

A typo
There is also a type in the above listed file: if ( $wgGraphVizSettings->named == 'named' | ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) )

Should be that: if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists( $src.".err" ) ) )


 * Fixed. (This appears to be not related to ) --Alvin-cs 12:19, 17 November 2007 (UTC)

On Updating
The update will work without noticing. Old (and unchanged) pages will stay the same and reference old images, a graph that is updated will automatically create a file in the new naming shema. If you worry about diskspace ... you can easily detect old files and new files.
 * Old files contain: _amp_, _shrp_, _sd_ instead of &, \ and /
 * New files: Replacing "_perc_" -> with "%" makes them valid urls.
 * Independent files: Usually don't have any of those things.


 * Had problem with ':' (COLON) in file names under windows. This happens when the article is not

in the default namespace. What about adding the following line: $storagename = str_replace(":",'_colon_',$storagename); around line 113? --195.206.74.130 13:08, 7 February 2008 (UTC)


 * I had the same problem with colons on a debian, $storagename = str_replace(":",'_colon_',$storagename);</tt> works perfectly :) --Church of emacs talk · contrib 15:51, 26 March 2010 (UTC)

local wiki URLs
A rather crude hack to allow local wiki url tags (--Dannyh 23:18, 26 March 2008 (UTC)). Suppose you want your graph to contain local links like the following: digraph G { Boss [URL = "User:Boss"] John [URL="User:John" ] Boss->John }

Then add the following function to GraphViz.php function rewriteWikiUrls( &$source) {    $line = preg_replace(         '|\[\[([^]]+)\]\]|e',         'Title::newFromText("$1")->getFullURL',         $source     ); return $line; }

And then, right before this block:

$handle = fopen($fname, "w"); fwrite($handle, $timelinesrc); fclose($handle);

Add the following line:

$timelinesrc = rewriteWikiUrls( $timelinesrc);

Wikilinks from within graph
A neat feature would be to be able to use wikilinks inside the graphviz code. Is this by any means feasible? --Berland 13:23, 3 October 2008 (UTC)

Broken with MW 1.12?
Is this broken again with MW 1.12? I'm getting no images. I tried both the main page version and the one added above on this page. --Cymen 15:31, 3 October 2008 (UTC)

Update: The RedHat version of graphviz requires the graphviz-gd package for PNG (and more) suport. I modified the script to replace spaces (' ') with underscore ('_') too. $storagename = str_replace(' ','_',$storagename); #new $src = $dest. $storagename; # not modifed And to print an error if it can't write to disk: $handle = fopen($src, 'w'); if (! $handle) return 'Error writing graphviz file to disk.'; fwrite($handle, $timelinesrc); --Cymen 16:07, 3 October 2008 (UTC)

Suse 11 + MW 1.13.2
I think this plug in will be great, once it works which is what I can't do.

I installed a Fresh Suse 11 distro and put MW 1.13.2 on it, configured correctly as far as I can tell, the graphviz plugin picks up the tags, and generates the images, which are correct, but they will not display in the wiki page.

The error I keep getting is:

Timeline error: Executable not found. Command line was: '/usr/local/bin/dot' -Tpng -o '/srv/www/htdocs/wiki/images/graphviz/Test---graph+G.png' '/srv/www/htdocs/wiki/images/graphviz/Test---graph+G'

I'm no expert in php since I think if I were I'd be able to figure this out, but if someone could lend a hand I'd be very grateful.

The original documentationf or the plugin states to use /usr/bin for the dot command, however since mine is generating the files from /usr/local/bin, I don't see why I would need to change it.

Thanks

You have to change the path in Graphviz.php and use this one /usr/bin because dot in suse is there.

xp190 38.113.160.194 20:57, 3 October 2008 (UTC)

Does this work on MW 1.12+?
If anyone has gotten this working on MW 1.12+, please post. I've tried nearly everything (the original Graphviz.php, the 'updated' one, and various combinations of the fixes supplied on this page) and MW1.13.2 never processes the element. I also tried the newest Graphviz 2.20, and the oldest one I could find (1.14). This is on windows. For paths I have tried backslash, two backslashes, and forward slash, as well as pointing at the Graphviz in Program Files or copying it to the wiki extensions directory. I'm inclined to believe this won't work on newer wikis.

Hi, i'm running graphviz under windows with MW 1.13.4. without problems. I use the latest graphviz extension and also the latest dot. --Ozz 09:50, 10 February 2009 (UTC)

I realized this was due to a change in how plugins are 'activated' in recent MW's. The documentation says 1.12+ but I found the old way worked on 1.12.0 but not 1.13.2. Here is my final working version for Windows (based off the updated plugin):

<?php /* * Extension to allow Graphviz to work inside MediaWiki. * This Version is based on CoffMan's nice Graphviz Extension. * * Licence: http://www.gnu.org/copyleft/fdl.html * * Configuration * *  These settings can be overwritten in LocalSettings.php. * Configuration must be done AFTER including this extension using * require("extensions/Graphviz.php"); * *  $wgGraphVizSettings->dotCommand *   Describes where your actual dot executable remains. * *    Windows Default: C:/Programme/ATT/Graphviz/bin/dot.exe *   Other Platform : /usr/local/bin/dot * *  $wgGraphVizSettings->named *   Describes the way graph-files are named. * *    named: name of your graph and its type determine its filename *   md5  : name of your graph is based on a md5 hash of its source. *   sha1 : name of your graph is based on a SHA1 hash of its source. * *    Default : named * *  $wgGraphVizSettings->install *   Gets you an errormessage if something fails, but maybe ruins your *   wiki's look. This message is in English, always. * *    Default : false * * Improvements * - Selects defaults for Windows or Unix-like automatically. * - should runs out of the box * - Creates PNG + MAP File * - additional storage modes (see discussion below) *  - Meaningful filename *  - Hash based filename *  - Configurable (name/md5/sha1) * * Storage Modes: * MD5: * + don't worry about graphnames * + pretty fast hash * - permanent cleanup necesary (manually or scripted) * - md5 is buggy - possibility that 2 graphs have the same hash but *  are not the same * SHA1: * + don't worry about graphnames * + no hash-bug as md5 * - permanent cleanup necessary (manually or scripted) * - not so fast as md5 * Named: * + Graphs have a name, now it's used * + no permanent cleanup necessary. * - Naming Conflicts *  a) if you have multiple graphs of the same name in the same  *      article, you will only get 1 picture - independently if they're  *            the same or not.  *   b) possible naming conflicts in obscure cases (that should not happen) *     Read code for possibilities / exploits *  */ class GraphVizSettings { public $dotCommand, $named, $install; }; $wgGraphVizSettings = new GraphVizSettings; // Config // -- if ( ! (stristr (PHP_OS, 'WIN' ) === FALSE) ) { $wgGraphVizSettings->dotCommand = 'C:/Program Files/Graphviz2.20/bin/dot'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; } $wgGraphVizSettings->named = 'named'; $wgGraphVizSettings->install = false; // Media Wiki Plugin Stuff // --- //$wgExtensionFunctions[] = "wfGraphVizExtension"; if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'wfGraphVizExtension'; } else { // Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'wfGraphVizExtension'; } $wgExtensionCredits['parserhook'][] = array(  'name'=&gt;'Graphviz',   'author'=&gt;'CoffMan &lt;http://wickle.com&gt;, MasterOfDesaster &lt;mailto://arno.venner@gmail.com&gt;',   'url'=&gt; 'http://www.mediawiki.org/wiki/Extension:GraphViz',   'description'=&gt;'Graphviz (http://www.graphviz.org) is a program/language that allows the creation of numerous types of graphs.  This extension allows the embedding of graphviz markup in MediaWiki pages and generates inline images to display.',   'version'=&gt;'0.4' ); function wfGraphVizExtension { global $wgParser; $wgParser->setHook( "graphviz", "renderGraphviz" ); return true; } function renderGraphviz( $timelinesrc, $params, &$parser )     // Raw Script data {      global $wgUploadDirectory,     // Storage of the final png & map $wgUploadPath,                 // HTML Reference $wgGraphVizSettings;     // Plugin Config $parser->disableCache; $output = ""; //$output = "&lt;pre&gt;Called render&lt;/pre&gt;"; // Prepare Directories $dest = $wgUploadDirectory."/graphviz/"; if ( ! is_dir( $dest ) ) { mkdir( $dest, 0777 ); } $output .= "&lt;pre&gt;Dir=$dest&lt;/pre&gt;"; $storagename = urldecode($_GET['title']).'---'; $storagename = str_replace("&",'_amp_',$storagename); $storagename = str_replace("#",'_shrp_',$storagename); $storagename = str_replace("/",'_sd_',$storagename); $storagename = str_replace("\\",'_sd_',$storagename); $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named); $output .= "&lt;pre&gt;dotCommand=".$wgGraphVizSettings->dotCommand ."&lt;/pre&gt;"; $output .= "&lt;pre&gt;named=".$wgGraphVizSettings->named ."&lt;/pre&gt;"; if($wgGraphVizSettings->named == 'md5') { $storagename .= md5($timelinesrc); } else if ($wgGraphVizSettings->named == 'sha1') { $storagename .= sha1($timelinesrc); } else { $storagename .= trim(                  str_replace("\n",'', str_replace("\\",'/',                              substr($timelinesrc, 0, strpos($timelinesrc,'{') ))      )); }      $src = $dest. $storagename; $imgn = $dest. $storagename. '.png'; $mapn = $dest. $storagename. '.map'; $output .= "&lt;pre&gt;Src=$src&lt;/pre&gt;"; if ( $wgGraphVizSettings->named == 'named' || ! ( file_exists( $src.".png" ) || file_exists($src.".err"))) {            $handle = fopen($src, "w"); $ret2 = fwrite($handle, $timelinesrc); $ret3=fclose($handle); $output.="&lt;pre&gt;Opened and closed $src, handle=$handle, timeelinesrc=$timelinesrc, ret2=$ret2, ret3=$ret3&lt;/pre&gt;"; $cmdline   = wfEscapeShellArg($wgGraphVizSettings->dotCommand).' -Tpng   -o '.wfEscapeShellArg($imgn).' '.wfEscapeShellArg($src); $cmdlinemap = wfEscapeShellArg($wgGraphVizSettings->dotCommand).' -Tcmapx -o '.wfEscapeShellArg($mapn).' '.wfEscapeShellArg($src); //$ret = shell_exec($cmdline); $WshShell = new COM("WScript.Shell"); $WshShell->Exec($cmdline); $WshShell->Exec($cmdlinemap); $output.="&lt;pre&gt;Ran cmd line. ret=$ret cmd=$cmdline&lt;/pre&gt;"; if ($wgGraphVizSettings->install && $ret == "" ) { //echo '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.'&lt;/tt&gt;&lt;/div&gt;'; $output.= '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdline.'&lt;/tt&gt;&lt;/div&gt;'; exit; }            //$ret = shell_exec($cmdlinemap); if ($wgGraphVizSettings->install && $ret == "" ) { echo '&lt;div id="toc"&gt;&lt;tt&gt;Timeline error: Executable not found.'. "\n".'Command line was: '.$cmdlinemap.'&lt;/tt&gt;&lt;/div&gt;'; exit; }            //unlink($src); }      @$err=file_get_contents( $src.".err" ); if ( $err != "" ) { $txt = '&lt;div id="toc"&gt;&lt;tt&gt;'.$err.'&lt;/tt&gt;&lt;/div&gt;'; } else { @$map = file_get_contents( $mapn ); $map = preg_replace('#&lt;ma(.*)&gt;#',' ',$map); $map = str_replace('&lt;/map&gt;','',$map); $txt = '&lt;map name="'.$storagename.'"&gt;'.$map.'&lt;/map&gt;'. '&lt;img src="'.$wgUploadPath.'/graphviz/'.$storagename.'.png"'. ' usemap="#'.$storagename.'" /&gt;'; }      $txt .= $output;//"&lt;pre&gt;MOOOO&lt;/pre&gt;"; return $txt; } ?>

Fix for Darwin
auto-detection fails for Darwin (because it matches "WIN"). Fix:

if ( stristr(PHP_OS, 'WIN' ) && !stristr(PHP_OS, 'Darwin') ) { $wgGraphVizSettings->dotCommand = 'C:/Programme/ATT/Graphviz/bin/dot.exe'; } else { $wgGraphVizSettings->dotCommand = '/usr/local/bin/dot'; }

Problems with mediawiki 1.16 (ubuntu 8.10) - dot command not found
I'm currently using the svn version of mediawiki, which is currently at 1.16. Although I have correctly set the location of dot,I keep getting the error:

Solution: This problem arises only when you set the because it gives and error when dot output is an empty string "", which is exactly the case of a succesful execution. To fix this we must look at the dot command return value rather than its stdout/stderr output.

--Drunken sapo 14:26, 22 June 2009 (UTC)

Do away with serverfiles
I have img_auth.php installed on the wiki, hence could not use this extension directly. Don't really want to touch permissions, so I did as suggested here and embedded the graphviz output inside the response html. Just threw together some code to verify this (missing all the error handling and what not, but works fine on sample graphs); feel free to reuse whatever you see fit as I am definitely still missing much functionality. --Vopap 03:56, 23 September 2009 (UTC)

Display Examples
I tried to display the example graphics that get produced by the examples on this page, but it seemed to just display the text even though I took it out of the 'code' tag. Any reason this would happen? Daviddoria 18:05, 1 November 2009 (UTC)

Bug in extreme fast redrawings
In case of redrawing the same graphic very fastly, the new graphviz call gets stuck. In the process list, the CMD and graphviz call does not get cleaned, because the created file is locked by the previous call.

A work around is to unlink the bare file ($fname) and the $fname.map before opening the handle to $fname: if (file_exists($fname)) unlink($fname); if (file_exists($fname.'.map')) unlink($fname.'.map');

This should solve the issue, but it needs to be tested thoroughly.

Custom Shapes
Is there any trick to getting a custom shape (image) rendered in the graphs? I have uploaded a "stick figure" image to my mediawiki, and can see it if I include the markup in page bodies, but it is not rendered when I include that markup in my graphviz code --srl100 11:18, 14 April 2010 (UTC)

e.g.

graph G { subgraph clusterMain { subgraph clusterActor1 { color=white; label="actor1"; actor1 ; }       system [shape=circle]; actor1 -- system; } }

Update 15 April 2010, by srl100...

It turns out that I needed to include the relative path to the image, in the (hashed) images directory structure.

graph G { subgraph clusterMain { subgraph clusterActor1 { color=white; label="actor1"; actor1 [image="images/a/aa/Stick.png" shape=none label=""]; }       system [shape=circle]; actor1 -- system; } }


 * I think you have to hack this feature into the extension by yourself. Perhaps this can help you on the way: --Danwe 21:39, 16 April 2010 (UTC)

Category pages and graphviz
The extension cannot work on category pages unless you include the following at line 117:

... $storagename = str_replace("\\",'_sd_',$storagename); $storagename = str_replace(":",'_colon_',$storagename); #<-- added... $wgGraphVizSettings->named = strtolower($wgGraphVizSettings->named); ...