forked from lupo49/plugin-enforcesummary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
56 lines (50 loc) · 1.95 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* DokuWiki Action component of EnforceSummary Plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Matthias Schulte <dokuwiki@lupo49.de>
* @author Sahara Satoshi <sahara.satoshi@gmail.com>
*/
class action_plugin_enforcesummary extends DokuWiki_Action_Plugin
{
// register hook
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'exportToJSINFO');
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'appendEditGuide');
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'appendEditGuide');
}
/**
* Exports configuration settings to $JSINFO
*/
public function exportToJSINFO(Doku_Event $event)
{
global $JSINFO;
$JSINFO['plugin_enforcesummary'] = array(
'enforce_summary' => $this->getConf('enforce_summary'),
'default_minoredit' => $this->getConf('default_minoredit'),
'enforce_preview' => $this->getConf('enforce_preview'),
);
}
/**
* Append Edit Guide in the Edit Window (below save button)
*/
public function appendEditGuide(Doku_Event $event)
{
$guidance = $this->locale_xhtml('edit_guide');
$html = '<div id="plugin_enforcesummary_wrapper">'.$guidance.'</div>';
$form =& $event->data;
if (($event->name == 'FORM_EDIT_OUTPUT')
&& (($pos = $form->findPositionByAttribute('id', 'edit__minoredit')) !== false)
) {
// applicable to development snapshot 2020-10-13 or later
// insert the edit guide after minor edit checkbox
$form->addHTML($html, ++$pos);
} elseif ($event->name == 'HTML_EDITFORM_OUTPUT') {
$pos = $form->findElementByAttribute('class', 'editButtons');
if (!$pos) return; // no editButtons
$form->addElement($html);
}
}
}