It's better when it's simple

User Tools

Site Tools


Format Plugin

Compatible with DokuWiki


plugin Sends text to external programs and embeds the resulting media in a wiki page (can replace the basic functionality of the graphviz and gnuplot plugins, for example).

Last updated on

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to gnuplot, graphviz, latex

Tagged with embed, media, program

Authors Jason Grout
Version 2007-02-22
Required DokuWiki version 2006-11-06
Main page


This plugin allows you to send text to an external program and display the resulting media (image, pdf, text, etc.) in the current wiki page.


This plugin can be very dangerous, as it allows anyone who can edit a page on your wiki to potentially execute arbitrary code on your web server. Use the plugin at your own risk. You may only use the plugin with the understanding that I will not be liable for anything that you do with it.

Personally, I am not using the gnuplot configuration noted below, since gnuplot gives the wiki user the ability to execute arbitrary code on the server. There is apparently no easy way around this. I am only using “safe” versions of other programs that disallow any file access and any system access to the user.

The plugin takes precautions in that it does not put any user input on the command line. Instead, all user input is loaded in a file, wrapped in the 'pre' and 'post' text specified in the configuration file. The resulting file is then made available through the @INPUTFILE@ variable for the command line.


After setting up the external programs in the conf/default.php file, you can call an external program like:

<format program-name>
text to feed into the program

Configuration settings

All of the interesting setup happens in the conf/default.php file. For each program to be called, add a block to the conf/default.php file that is similar to:

$conf['<program-name>']=array('name' => "<user name>",
                    '<mode>' => array('ext' => "<extension>",
                                     'pre' => "<pre>",
                                     'post' => "<post>",
                                     'command' => "<command line>" ));

The various fields are:

<program-name> The name of the program, as it will be used in the <format program-name> syntax
<user name> The user-friendly name of the program
<mode> The mode these particular commands apply to. You can run different programs based on the rendering pass of the page. For example, you can return some text in the 'metadata' mode, but render an image in XHTML mode, and render a PDFimage in 'latex' mode.
<extension> The extension of the file that will be generated. This will also determine the mime type of the generated media
<pre> 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.
<post> Text to go after the text the user wrote in the wiki page. You can use this to clean up variables, generate pictures, etc.
<command line> 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 <pre> text, the text the user wrote in the wiki, and the <post> 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:


$conf['dpic']=array('name' => "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 )

With this setup (assuming that you have all of the right programs in place), you could use gnuplot in a wiki page like this:

<format gnuplot>
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 dpic to generate diagrams, like this:

<format dpic>
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/<program-name>/ folder (the :format:<program-name>: 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:<program-name>: namespace so that administrators can easily disable an external program for certain users/groups.


This plugin is a modification and generalization of the existing graphviz and gnuplot plugins. Special thanks goes to the authors of those plugins.


I've put a short page up demonstrating this plugin at

I've put an other short page up demonstrating this plugin generating sequence diagrams. Look at my Wiki page.
This demonstrates how to use it with Trace2UML

  'command' => 'xvfb-run /usr/bin/Trace2UML -i @INFILE@ -o @MEDIAFILE@'))


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@'));


                      '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
this puts the output image files into data/media/auto/<plugin name>/<program-name>/<Namespace>/<Pagename>/
(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
example page
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 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 ( 25Aug2010

plugin/format.txt · Last modified: 2010-10-10 14:50 by lupo49