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