DokuWiki Plugins

My personal website used to use DokuWiki. I authored or extended several plugins useful when I was teaching.

Format plugin

See http://www.dokuwiki.org/plugin:format

The format plugin allows you to run external programs and embed the resulting images or other files into a wiki page. The nice thing about this is that you don’t have to create images with other programs and then upload them to the webserver. Additionally, the changes are tracked between pages (so, for instance, you can change a graph on a page and old versions of the page will still display the old version of the graph). I’m using it to allow a person to draw diagrams or graphs by giving the commands in the page and having DokuWiki convert those commands to a picture through an external program.

GNU PIC (using dpic)

Dwight Aplevich wrote dpic (http://www.ece.uwaterloo.ca/~aplevich/dpic/), a wonderful implementation of the GNU PIC language. This program allows a person to draw diagrams with a very easy programming language. I’ve personally used this extensively in drawing graphs for my research.

Putting this in a dokuwiki page is as simple as:

<format dpic>
  box "start" 
  arrow right 2 "process" above
  circle "end"
</format>

More examples and a manual of the syntax comes with dpic and also can be found in the “pic” section of http://www.kohala.com/start/troff/troff.html or on Wikipedia.

Graphing (using GLE)

GLE (http://glx.sourceforge.net/) is a program for drawing graphs and diagrams. I use it to insert nice graphs into a wiki.

Here is an example:

<format graph>
  ! An exclamation point is the comment character
  size 7 4 ! Make the picture 7cm by 4cm
  begin graph
    size 7 4 ! Make the graph fit the picture
    xaxis min 0 max 2*pi dticks pi/2 format "pi" ! Set up the x-axis
    yaxis nticks 5 ! Set up the y-axis
    
    ! Define three data sets
    let d1 = 1/x from 0.2 to 10 
    let d2 = sin(x)*2+2 from 0 to 10 
    let d3 = 10*(1/sqrt(2*pi))*exp(-2*(sqr(x-4)/sqr(2))) from 0.2 to 10 step .1 


    d1 line ! Plot dataset d1
    d2 line lstyle 2 color red  ! Plot dataset d2 in red
    d3 line impulses color light_grey ! Plot dataset d3
  end graph 
</format>

More examples can be found at:

Graphing (with gnuplot)

I decided not to use gnuplot because it is not safe. There is no way to make sure that the wiki user can’t execute arbitrary commands on the wiki server. However, if you want to use gnuplot, you can.

Newpagetemplate Plugin

See http://www.dokuwiki.org/plugin:newpagetemplate

The newpagetemplate plugin allows you to specify a template and also replacement variables for the template for a new page creation. This plugin loads into the new page creation box a template specified in the $_REQUEST “newpagetemplate” parameter. Effectively, this means that you can pass a template page, similar to the namespace template pages, either in the URL or in a POST form to the creation page. The motivation behind developing this plugin was a need for a way to present a student with a way to create a homework page from a predefined template.

I’ve posted a patch below to modify the addnewpage plugin to take advantage of this functionality.

How do I use this? If I have a template that I would like students to use for a particular homework set, say “:templates:homeworkset1”, then I just put

{{NEWPAGE>|newpagetemplate=:templates:homeworkset1&newpagevars=@LINK@,[[link:to:homework:page]]}}

in the homework submission page. Any page a student creates using the resulting “Add new page” button will automatically be pre-filled with the template. In addition, the template will substitute the variable @LINK@ with the link I provided.

addnewpage plugin

Here is the patch for the addnewpage plugin:

--- syntax.php  (revision 1141)
+++ syntax.php  (revision 1142)
@@ -28,8 +28,8 @@
     }
 
     function handle($match, $state, $pos, &$handler){
1.         $ns = substr($match, 10, -2);  // strip markup
2.      return $ns;
+          $ns = explode('|',substr($match, 10, -2),2);  // strip markup
+          return array(trim($ns[0]),trim($ns[1]));
     }
     
  
@@ -38,7 +38,7 @@
                $renderer->info['cache'] = false;
     
                if ($mode ###### 'xhtml') {
1.                       $cmb=$this->_makecombo($data);
+                       $cmb=$this->_makecombo($data[0]);
                        if ($cmb######$this->getLang('nooption')) {
                                $renderer->doc .=(!$this->getConf('addpage_hideACL'))?$cmb:'';
                                return true;
@@ -49,7 +49,15 @@
                    $renderer->doc .= $cmb;
                    $renderer->doc .###### '<input class"edit" type######"text" name"title" id######"addnewpage_title" size"20" maxlength######"255" tabindex"2" />';
                        $renderer->doc .###### '<input type"hidden" name######"do" id"do" value="edit" />';
1.                   $renderer->doc .###### '<input class"button" type######"submit" value"'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex######"3"  onclick"setName();" />';
+                        if(strlen($data[1])>1) {
+                         $t=explode("&",$data[1]);
+                         foreach($t as $value) {
+                           $parameter######explode("",$value,2);
+                           $renderer->doc .###### '<input type"hidden" name######"'.htmlentities(trim($parameter[0]),ENT_QUOTES).'" id"'.htmlentities(trim($parameter[0]),ENT_QUOTES).'" value="'.htmlentities(trim($parameter[1]),ENT_QUOTES).'" />';
+                         }
+                       }
+
+                       $renderer->doc .###### '<input class"button" type######"submit" value"'.((@$this->getLang('okbutton'))?$this->getLang('okbutton'):'ok').'" tabindex######"3"  onclick"setName();" />';
                    $renderer->doc .= '</form>';
                    $renderer->doc .= '</div>';