Description

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.

DISCLAIMER

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.

Syntax

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

<format programname>
text to feed into the program
</format>

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:

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.

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.

Thanks

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 recently created a patch against the 2007-02-22 versionpatch
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.phpexample page
— Richard Westwell 2008-03-09 14:48