1<?php
2/**
3 * DokuWiki Action component of EnforceSummary Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author  Matthias Schulte <dokuwiki@lupo49.de>
7 * @author  Sahara Satoshi <sahara.satoshi@gmail.com>
8 */
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'action.php');
14
15/**
16 * All DokuWiki plugins to interfere with the event system
17 * need to inherit from this class
18 */
19class action_plugin_enforcesummary extends DokuWiki_Action_Plugin {
20
21    // register hook
22    function register(Doku_Event_Handler $controller) {
23        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, '_exportToJSINFO');
24        $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, '_append_edit_guide');
25    }
26
27    /**
28     * Exports configuration settings to $JSINFO
29     */
30    function _exportToJSINFO(&$event) {
31
32        global $JSINFO;
33
34        $JSINFO['plugin_enforcesummary'] = array(
35                'enforce_summary'    => $this->getConf('enforce_summary'),
36                'default_minoredit'  => $this->getConf('default_minoredit'),
37                'enforce_preview'    => $this->getConf('enforce_preview'),
38            );
39    }
40
41    /**
42     * Append Edit Guide in the Edit Window (below save button)
43     */
44    function _append_edit_guide(&$event) {
45        $pos = $event->data->findElementByAttribute('class', 'editButtons');
46        if (!$pos) return; // no editButtons
47        $guidance = $this->locale_xhtml('edit_guide');
48        $html = '<div id="plugin_enforcesummary_wrapper">'.$guidance.'</div>';
49        $event->data->addElement($html);
50    }
51}
52