FWIW, this is the code, minus the Perl "service program" that's called to do the text processing. It seems to work fine. Suggestions welcome!
<?php
/*
* Copyright (c) Chap Harrison <charrison@wiland.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
if (!defined('DOKU_INC')) {
die();
}
if (!defined('DOKU_PLUGIN')) {
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
}
require_once(DOKU_PLUGIN . 'action.php');
/**
* DokuWiki Plugin wilandglossary (Action Component).
*
* @license BSD license
* @author Chap Harrison <charrison@wiland.com>
*/
class action_plugin_wilandglossary extends DokuWiki_Action_Plugin
{
private $gloss_ns = '';
private $gloss_page = 'glossary';
private $service_program = '/Users/chap/private/perl/glossary_pagesave';
private $explain_conf = DOKU_CONF . 'explain.conf';
private $local_conf = DOKU_CONF . 'local.php';
/**
* Register for events.
*
* @param Doku_Event_Handler $controller
* DokuWiki's event controller object. Also available as global $EVENT_HANDLER
*/
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'handle_pagewrite_before', array());
$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_pagewrite_after', array());
}
/**
* Glossary page is being saved to disk. Validate it, standardize it.
*
* Currently hardcoded to look for ':glossary' being saved.
*
* @param Doku_Event $event
* the DokuWiki event
* @param mixed $param
* not used
*/
public function handle_pagewrite_before(Doku_Event $event, $param)
{
// Bail out now if we're just writing page into attic.
if ( $event->data[3] ) return;
$ns = $event->data[1];
$page = $event->data[2];
// We're looking specifically for changes to 'glossary' in the root ns.
if ( $ns == $this->gloss_ns and $page == $this->gloss_page ) {
// Build a shell command to send glossary off for validation.
$cmd = "cat <<EOF | "
. $this->service_program
. " -n \n"
. $event->data[0][1]
. "\nEOF\n";
// Run the command. Reformatted version is returned.
$reformat = shell_exec($cmd);
$event->data[0][1] = $reformat;
}
return;
}
/**
* Glossary page has been saved to disk. Extract data for conf/explain.conf.
*
* Currently hardcoded to look for ':glossary' being saved.
*
* @param Doku_Event $event
* the DokuWiki event
* @param mixed $param
* not used
*/
public function handle_pagewrite_after(Doku_Event $event, $param)
{
// Bail out now if we're just writing page into attic.
if ( $event->data[3] ) return;
// Bail out if the page write failed.
if ( ! $event->result ) return;
$ns = $event->data[1];
$page = $event->data[2];
if ( $ns == $gloss_ns and $page == $gloss_page ) {
// Send the page to have explain.conf generated
$cmd = "cat <<EOF | "
. $this->service_program
. " -x \n"
. $event->data[0][1]
. "\nEOF\n";
$explain = shell_exec($cmd);
io_saveFile($this->explain_conf, $explain);
shell_exec("touch " . $this->local_conf);
}
return;
}
}