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