%% | The extension of the file that will be generated. This will also determine the mime type of the generated media |
^ %%%% | Text to go before the text the user wrote in the wiki page. You can use this to set parameters in the program or otherwise set up the environment of the program. |
^ %%%% | Text to go after the text the user wrote in the wiki page. You can use this to clean up variables, generate pictures, etc. |
^ %%%% | The command to run via the PHP system call. There are two variables that can be substituted in the command line. ''@INPUTFILE@'' refers to the file containing, in order, the ''%%%%'' text, the text the user wrote in the wiki, and the ''%%%%'' text. ''@MEDIAFILE@'' contains the path and name of the file you should put your result into. There's actually another variable substituted (''@OUTFILE@''), but that's experimental only. |
Here is an example ''conf/default.php'' file:
"PIC diagram",
'xhtml' => array('ext' => 'png',
'pre' => ".PS\n",
'post' => "\n.PE\n",
'command' => '/usr/local/bin/dpic-safe -r @INFILE@ | /usr/local/bin/convert -density 200 - png:- > @MEDIAFILE@'));
foreach (array('dot','neato','twopi','circo','fdp') as $key => $prog) {
$conf[$prog]=array('name' => "Graph",
'xhtml' => array('ext' => 'png',
'pre' => "",
'post' => "",
'command' => 'SERVER_NAME=xxx GV_FILE_PATH="" /usr/local/bin/'.$prog.' -Tpng -o @MEDIAFILE@ @INFILE@'));
}
$conf['gnuplot']=array('name' => 'Plot',
'xhtml' => array('ext' => 'png',
'pre' => "set terminal PNG transparent nocrop enhanced size 420,320\nset output '@MEDIAFILE@'",
// if you are using a version of gnuplot supporting the OLD PNG library
// this line has to be
// 'pre' => "set terminal PNG transparent picsize 420 320\nset output '@MEDIAFILE@'",
'post' => "\nexit\n",
'command' => 'cat @INFILE@ | /usr/local/bin/gnuplot'));
$conf['graph']=array('name' => 'GLE Graph',
'xhtml' => array('ext' => 'png',
'pre' => "",
'post' => "",
'command' => '/usr/local/bin/gle -safemode -r 200 -d png -output @MEDIAFILE@ @INFILE@ '));
(the SERVERNAME and GV_FILE_PATH variables are set to help with security---see [[http://www.graphviz.org/doc/info/command.html]] )
With this setup (assuming that you have all of the right programs in place), you could use gnuplot in a wiki page like this:
plot [-20:20] sin(x)/x
and the block of code is replaced by the graph generated by gnuplot.
You could also use the GNU PIC implementation [[http://www.ece.uwaterloo.ca/~aplevich/dpic/|dpic]] to generate diagrams, like this:
box "start"
arrow 2 "process" above
circle "end"
and the resulting diagram would show up on the page (see the Demo below for this example).
===== File storage =====
The generated media files are stored in the %%data/media/format//%% folder (the %%:format::%% media namespace). Permissions are not checked on this directory. If someone wants to make a patch to check permissions, feel free to send it to me. I'm thinking it would be nice to check permissions on the %%:format::%% namespace so that administrators can easily disable an external program for certain users/groups.
===== Thanks =====
This plugin is a modification and generalization of the existing graphviz and gnuplot plugins. Special thanks goes to the authors of those plugins.
===== Demo =====
I've put a short page up demonstrating this plugin at [[http://math.byu.edu/~grout/software/dokuwiki/format-plugin]].
I've put an other short page up demonstrating this plugin generating sequence diagrams. Look at [[http://astade.homeip.net/wiki/doku.php?id=howto:trace2uml_in_dokuwiki|my Wiki page]].
This demonstrates how to use it with Trace2UML [[http://trace2uml.tigris.org]]
'command' => 'xvfb-run /usr/bin/Trace2UML -i @INFILE@ -o @MEDIAFILE@'))
===== Discussion =====
Some things had to be changed
On my machine, compiling dpic in safe mode and renaming it to dpic-safe had the consequence that it would not
produce output when called by PHP. Therefore, the command had to be
'command' => '/usr/local/bin/dpic -r @INFILE@ | /usr/local/bin/convert -density 200 - png:- > @MEDIAFILE@'));
instead of
'command' => '/usr/local/bin/dpic-safe -r @INFILE@ | /usr/local/bin/convert -density 200 - png:- > @MEDIAFILE@'));
dpic still is compiled for safe mode, so security is not broken.
gnuplot has a problem also, because how gnuplot handles PNG output depends on the libraries available at compile time.
It the command
'pre' => "set terminal PNG transparent nocrop enhanced size 420,320\nset output '@MEDIAFILE@'",
does not work, changing the prologue for the older version of PNG like this
'pre' => "set terminal PNG transparent picsize 420 320\nset output '@MEDIAFILE@'",
can help.
Finally, for all the graphviz programs to work, the command had to be changed to
'command' => 'SERVER_NAME=xxx GV_FILE_PATH="" /usr/local/bin/'.$prog.' -Tpng -o @MEDIAFILE@ @INFILE@'));
from
'command' => 'SERVER_NAME=xxx GV_FILE_PATH="" /usr/local/bin/'.$prog.' -Tpng -o @MEDIAFILE@'));
\\
I've recently created a patch against the 2007-02-22 version\\
[[http://homepage.ntlworld.com/garlicbread/images/web/projects/dokuwiki_web/format.diff|patch]]\\
this puts the output image files into %%data/media/auto/////%%\\
(I've added "auto" to the path to try and keep any files auto-generated from other plugins all in one location)\\
also on the first invocation of header() for a given page, it will remove any existing files within this directory\\
(just the directory/namespace of the page being loaded) as a sort of cleanup of old files\\
probably not the best way to do things, but it does work, and avoids lots of old image files lying around when making small changes to the diagrams\\
Also I've put up an example of altering the formatting of the diagram for gnuplot / graphviz (for example with dark themes), from within the default.php\\
[[http://homepage.ntlworld.com/garlicbread/pages/web/projects/dokuwiki_web/plugin_setup.html|example page]]\\
--- //[[garlicbready@googlemail.com|Richard Westwell]] 2008-03-09 14:48//
\\
For Windows (at least) installations, I found some changes were necessary; in particular, the @MEDIAFILE@ and @INFILE@ items in the default.php had to be quoted. (Otherwise, the c:\Program Files\... path would cause problems, among others.)\\
\\
Here's my working mscgen section from default.php. (mscgen is c:\usr\bin\mscgen.exe)\\
/* mscgen setup */
foreach (array('mscgen') as $key => $prog) {
$conf[$prog]=array('name' => "MSCGen",
'xhtml' => array('ext' => 'png',
'pre' => "msc{",
'post' => "}",
'command' => '/usr/bin/'.$prog.' -Tpng -o "@MEDIAFILE@" "@INFILE@"'));
}
--- // bchartrand, 2010-02-25//
\\
I have just completed a comment for the [[plugin:chain]] plugin that will apply wiki formatting to syntax text. Since these two plugins are very similar, it should work here too. If you've been interested in bringing in external wiki-formatted text, check it out.\\
- Jared Meeker (jaredm@tni.com) 25Aug2010