[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace dokuwiki\Ui; 4 5 use dokuwiki\Draft; 6 use dokuwiki\Extension\Event; 7 use dokuwiki\Form\Form; 8 9 /** 10 * DokuWiki Page Editor 11 * 12 * @package dokuwiki\Ui 13 */ 14 class Editor extends Ui 15 { 16 /** 17 * Display the Edit Window 18 * preprocess edit form data 19 * 20 * @author Andreas Gohr <andi@splitbrain.org> 21 * 22 * @triggers EDIT_FORM_ADDTEXTAREA 23 * @return void 24 */ 25 public function show() 26 { 27 global $INPUT; 28 global $ID; 29 global $REV; 30 global $DATE; 31 global $PRE; 32 global $SUF; 33 global $INFO; 34 global $SUM; 35 global $lang; 36 global $conf; 37 global $TEXT; 38 39 global $license; 40 41 if ($INPUT->has('changecheck')) { 42 $check = $INPUT->str('changecheck'); 43 } elseif (!$INFO['exists']) { 44 // $TEXT has been loaded from page template 45 $check = md5(''); 46 } else { 47 $check = md5($TEXT); 48 } 49 $mod = (md5($TEXT) !== $check); 50 51 $wr = $INFO['writable'] && !$INFO['locked']; 52 53 // intro locale text (edit, rditrev, or read) 54 if ($wr) { 55 $intro = ($REV) ? 'editrev' : 'edit'; 56 } else { 57 // check pseudo action 'source' 58 if (!actionOK('source')) { 59 msg('Command disabled: source', -1); 60 return; 61 } 62 $intro = 'read'; 63 } 64 65 // create the Editor form 66 $form = new Form(['id' => 'dw__editform']); 67 $form->setHiddenField('id', $ID); 68 $form->setHiddenField('rev', $REV); 69 $form->setHiddenField('date', $DATE); 70 $form->setHiddenField('prefix', $PRE .'.'); 71 $form->setHiddenField('suffix', $SUF); 72 $form->setHiddenField('changecheck', $check); 73 74 // prepare data for EDIT_FORM_ALTERNATE event 75 $data = array( 76 'form' => $form, 77 'wr' => $wr, 78 'media_manager' => true, 79 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', 80 'intro_locale' => $intro, 81 ); 82 83 if ($data['target'] !== 'section') { 84 // Only emit event if page is writable, section edit data is valid and 85 // edit target is not section. 86 Event::createAndTrigger('EDIT_FORM_ADDTEXTAREA', $data, [$this,'addTextarea'], true); 87 } else { 88 $this->addTextarea($data); 89 } 90 91 $form->setHiddenField('target', $data['target']); 92 93 if ($INPUT->has('hid')) { 94 $form->setHiddenField('hid', $INPUT->str('hid')); 95 } 96 if ($INPUT->has('codeblockOffset')) { 97 $form->setHiddenField('codeblockOffset', $INPUT->str('codeblockOffset')); 98 } 99 100 $form->addTagOpen('div')->id('wiki__editbar')->addClass('editBar'); 101 102 $form->addTagOpen('div')->id('size__ctl'); 103 $form->addTagClose('div'); 104 105 if ($wr) { 106 // add edit buttons: save, preview, cancel 107 $form->addTagOpen('div')->addClass('editButtons'); 108 $form->addButton('do[save]', $lang['btn_save'])->attr('type', 'submit') 109 ->attrs(['accesskey' => 's', 'tabindex' => '4']) 110 ->id('edbtn__save'); 111 $form->addButton('do[preview]', $lang['btn_preview'])->attr('type', 'submit') 112 ->attrs(['accesskey' => 'p', 'tabindex' => '5']) 113 ->id('edbtn__preview'); 114 $form->addButton('do[cancel]', $lang['btn_cancel'])->attr('type', 'submit') 115 ->attrs(['tabindex' => '6']); 116 $form->addTagClose('div'); // close div editButtons class 117 118 // add a textbox for edit summary 119 $form->addTagOpen('div')->addClass('summary'); 120 $input = $form->addTextInput('summary', $lang['summary']) 121 ->attrs(['size' => '50', 'tabindex' => '2']) 122 ->id('edit__summary')->addClass('edit') 123 ->val($SUM); 124 $input->getLabel()->attr('class', 'nowrap'); 125 126 // adds a checkbox for minor edits for logged in users 127 if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 128 $form->addHTML(' '); 129 $form->addCheckbox('minor', $lang['minoredit'])->id('edit__minoredit')->addClass('nowrap')->val('1'); 130 } 131 $form->addTagClose('div'); // close div summary class 132 } 133 134 $form->addTagClose('div'); // close div editBar class 135 136 // license note 137 if ($wr && $conf['license']) { 138 $attr = array( 139 'href' => $license[$conf['license']]['url'], 140 'rel' => 'license', 141 'class' => 'urlextern', 142 'target' => $conf['target']['extern'] ?: '', 143 ); 144 $form->addTagOpen('div')->addClass('license'); 145 $form->addHTML($lang['licenseok'] 146 .' <a '.buildAttributes($attr, true).'>'.$license[$conf['license']]['name'].'</a>' 147 ); 148 $form->addTagClose('div'); 149 } 150 151 // start editor html output 152 if ($wr) { 153 // sets changed to true when previewed 154 echo '<script>/*<![CDATA[*/'.'textChanged = '. ($mod ? 'true' : 'false') .'/*!]]>*/</script>'; 155 } 156 157 // print intro locale text (edit, rditrev, or read.txt) 158 if (isset($data['intro_locale'])) { 159 echo p_locale_xhtml($data['intro_locale']); 160 } 161 162 echo '<div class="editBox" role="application">'; 163 164 echo '<div class="toolbar group">'; 165 echo '<div id="tool__bar" class="tool__bar">'; 166 if ($wr && $data['media_manager']) { 167 echo '<a href="'.DOKU_BASE.'lib/exe/mediamanager.php?ns='.$INFO['namespace'].'" target="_blank">'; 168 echo $lang['mediaselect']; 169 echo '</a>'; 170 } 171 echo '</div>'; 172 echo '</div>'; 173 174 echo '<div id="draft__status" class="draft__status">'; 175 $draft = new Draft($ID, $INFO['client']); 176 if ($draft->isDraftAvailable()) { 177 echo $draft->getDraftMessage(); 178 } 179 echo '</div>'; 180 181 echo $form->toHTML('Edit'); 182 183 echo '</div>'; // close div editBox class 184 } 185 186 /** 187 * Display the default edit form (textarea) 188 * 189 * the default action for EDIT_FORM_ADDTEXTAREA 190 * 191 * @param array{wr: bool, media_manager: bool, target: string, intro_locale: string, form: Form} $data 192 */ 193 public function addTextarea(&$data) 194 { 195 global $TEXT; 196 197 if ($data['target'] !== 'section') { 198 msg('No editor for edit target '. hsc($data['target']) .' found.', -1); 199 } 200 201 // set textarea attributes 202 $attr = array('tabindex' => '1'); 203 if (!$data['wr']) $attr['readonly'] = 'readonly'; 204 $attr['dir'] = 'auto'; 205 $attr['cols'] = '80'; 206 $attr['rows'] = '10'; 207 208 $data['form']->addTextarea('wikitext','')->attrs($attr)->val($TEXT) 209 ->id('wiki__text')->addClass('edit'); 210 } 211 212 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body