1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* DokuWiki Plugin prosemirror (Action Component) |
4
|
|
|
* |
5
|
|
|
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html |
6
|
|
|
* @author Andreas Gohr <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// must be run within Dokuwiki |
10
|
|
|
if (!defined('DOKU_INC')) { |
11
|
|
|
die(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
class action_plugin_prosemirror_editor extends DokuWiki_Action_Plugin |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Registers a callback function for a given event |
18
|
|
|
* |
19
|
|
|
* @param Doku_Event_Handler $controller DokuWiki's event controller object |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function register(Doku_Event_Handler $controller) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'output_editor'); |
26
|
|
|
$controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'addAddtionalForms'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* [Custom event handler which performs action] |
31
|
|
|
* |
32
|
|
|
* Triggered by event: HTML_EDITFORM_OUTPUT |
33
|
|
|
* |
34
|
|
|
* @param Doku_Event $event event object |
35
|
|
|
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this |
36
|
|
|
* handler was registered] |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function output_editor(Doku_Event $event, $param) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
if (!$this->allowWYSIWYG()) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** @var Doku_Form $form */ |
48
|
|
|
$form =& $event->data; |
49
|
|
|
$useWYSIWYG = get_doku_pref('plugin_prosemirror_useWYSIWYG', false); |
|
|
|
|
50
|
|
|
|
51
|
|
|
if (!$useWYSIWYG) { |
52
|
|
|
$attr = [ |
53
|
|
|
'class' => 'button plugin_prosemirror_useWYSIWYG' |
54
|
|
|
]; |
55
|
|
|
$form->addElement(form_makeButton('submit', 'preview', 'Preview and use WYSIWYG-Editor', $attr)); |
|
|
|
|
56
|
|
|
return; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
global $TEXT; |
60
|
|
|
$instructions = p_get_instructions($TEXT); |
|
|
|
|
61
|
|
|
try { |
62
|
|
|
$prosemirrorJSON = p_render('prosemirror', $instructions, $info); |
|
|
|
|
63
|
|
|
} catch (Throwable $e) { |
64
|
|
|
$errorMsg = 'Rendering the page\'s syntax for the WYSIWYG editor failed'; |
65
|
|
|
|
66
|
|
|
/** @var helper_plugin_sentry $sentry */ |
67
|
|
|
$sentry = plugin_load('helper', 'sentry'); |
|
|
|
|
68
|
|
|
if ($sentry) { |
|
|
|
|
69
|
|
|
$sentry->logException($e); |
70
|
|
|
$errorMsg .= ' Error has been logged to Sentry.'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
msg($errorMsg, -1); |
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$event->stopPropagation(); |
78
|
|
|
$event->preventDefault(); |
79
|
|
|
|
80
|
|
|
$attr = [ |
81
|
|
|
'class' => 'button plugin_prosemirror_useWYSIWYG' |
82
|
|
|
]; |
83
|
|
|
$form->addElement(form_makeButton('submit', 'preview', 'Preview and use Syntax-Editor', $attr)); |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
// output data and editor field |
87
|
|
|
$form->addHidden('prosemirror_json',$prosemirrorJSON); |
88
|
|
|
$form->insertElement(1, '<div id="prosemirror__editor"></div>'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function allowWYSIWYG() |
92
|
|
|
{ |
93
|
|
|
global $INPUT; |
94
|
|
|
return !$INPUT->has('target') || $INPUT->str('target') === 'section'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function addAddtionalForms(Doku_Event $event) |
98
|
|
|
{ |
99
|
|
|
if (!$this->allowWYSIWYG()) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (!in_array($event->data, ['edit', 'preview'])) { |
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$linkForm = new dokuwiki\Form\Form([ |
|
|
|
|
108
|
|
|
'class' => 'plugin_prosemirror_linkform', |
109
|
|
|
'id' => 'prosemirror-linkform', |
110
|
|
|
'style' => 'display: none;', |
111
|
|
|
]); |
112
|
|
|
$linkForm->addFieldsetOpen('Links')->addClass('js-link-fieldset');; |
113
|
|
|
$iwOptions = array_keys(getInterwiki()); |
|
|
|
|
114
|
|
|
$linkForm->addDropdown('iwshortcut', $iwOptions, 'InterWiki')->attr('required', 'required'); |
115
|
|
|
$linkForm->addTextInput('linktarget', 'Link target')->attrs( |
116
|
|
|
[ |
117
|
|
|
'required'=> 'required', |
118
|
|
|
'autofocus' => 'autofocus', |
119
|
|
|
] |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$linkForm->addTagOpen('div')->addClass('radio-wrapper'); |
123
|
|
|
$linkForm->addTagOpen('fieldset'); |
124
|
|
|
$linkForm->addTagOpen('legend'); |
125
|
|
|
$linkForm->addHTML('Link Type'); |
126
|
|
|
$linkForm->addTagClose('legend'); |
127
|
|
|
$linkForm->addRadioButton('linktype', 'Wiki page')->val('internallink'); |
128
|
|
|
$linkForm->addRadioButton('linktype', 'Interwiki')->val('interwikilink'); |
129
|
|
|
$linkForm->addRadioButton('linktype', 'email')->val('emaillink'); |
130
|
|
|
$linkForm->addRadioButton('linktype', 'external')->val('externallink')->attr('checked', 'checked'); |
131
|
|
|
$linkForm->addRadioButton('linktype', 'Other')->val('other'); |
132
|
|
|
$linkForm->addTagClose('fieldset'); |
133
|
|
|
$linkForm->addTagClose('div'); |
134
|
|
|
|
135
|
|
|
$linkForm->addTagOpen('div')->addClass('radio-wrapper'); |
136
|
|
|
$linkForm->addTagOpen('fieldset'); |
137
|
|
|
$linkForm->addTagOpen('legend'); |
138
|
|
|
$linkForm->addHTML('Link Name Type'); |
139
|
|
|
$linkForm->addTagClose('legend'); |
140
|
|
|
$linkForm->addRadioButton('nametype', 'automatic')->val('automatic')->attr('checked', 'checked'); |
141
|
|
|
$linkForm->addRadioButton('nametype', 'custom')->val('custom'); |
142
|
|
|
$linkForm->addRadioButton('nametype', 'image')->val('image'); |
143
|
|
|
$linkForm->addTextInput('linkname', 'Link name')->attr('placeholder', '(automatic)'); |
144
|
|
|
$linkForm->addTagOpen('div')->addClass('js-media-wrapper'); |
145
|
|
|
$linkForm->addTagClose('div'); |
146
|
|
|
$linkForm->addTagClose('fieldset'); |
147
|
|
|
$linkForm->addTagClose('div'); |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
$linkForm->addFieldsetClose(); |
151
|
|
|
$linkForm->addButton('ok-button', 'OK')->attr('type', 'submit'); |
152
|
|
|
$linkForm->addButton('cancel-button', 'Cancel')->attr('type', 'button'); |
153
|
|
|
|
154
|
|
|
echo $linkForm->toHTML(); |
155
|
|
|
|
156
|
|
|
$mediaForm = new dokuwiki\Form\Form([ |
157
|
|
|
'class' => 'plugin_prosemirror_mediaform', |
158
|
|
|
'id' => 'prosemirror-mediaform', |
159
|
|
|
'style' => 'display: none;', |
160
|
|
|
]); |
161
|
|
|
$mediaForm->addFieldsetOpen('Media')->addClass('js-media-fieldset'); |
162
|
|
|
$mediaForm->addTextInput('mediatarget', 'Media')->attrs( |
163
|
|
|
[ |
164
|
|
|
'required'=> 'required', |
165
|
|
|
'autofocus' => 'autofocus', |
166
|
|
|
] |
167
|
|
|
); |
168
|
|
|
$mediaForm->addTextInput('mediacaption', 'Caption'); |
169
|
|
|
$mediaForm->addTextInput('width', 'Width (px)')->attr('type', 'number'); |
170
|
|
|
$mediaForm->addTextInput('height', 'Height (px)')->attr('type', 'number'); |
171
|
|
|
|
172
|
|
|
$mediaForm->addTagOpen('div')->addClass('radio-wrapper'); |
173
|
|
|
$mediaForm->addTagOpen('fieldset'); |
174
|
|
|
$mediaForm->addTagOpen('legend'); |
175
|
|
|
$mediaForm->addHTML('Alignment'); |
176
|
|
|
$mediaForm->addTagClose('legend'); |
177
|
|
|
$mediaForm->addRadioButton('alignment', 'default')->val('')->attr('checked', 'checked'); |
178
|
|
|
$mediaForm->addRadioButton('alignment', 'float left')->val('left'); |
179
|
|
|
$mediaForm->addRadioButton('alignment', 'center')->val('center'); |
180
|
|
|
$mediaForm->addRadioButton('alignment', 'float right')->val('right'); |
181
|
|
|
$mediaForm->addTagClose('fieldset'); |
182
|
|
|
$mediaForm->addTagClose('div'); |
183
|
|
|
|
184
|
|
|
$mediaForm->addTagOpen('div')->addClass('radio-wrapper'); |
185
|
|
|
$mediaForm->addTagOpen('fieldset'); |
186
|
|
|
$mediaForm->addTagOpen('legend'); |
187
|
|
|
$mediaForm->addHTML('Linking'); |
188
|
|
|
$mediaForm->addTagClose('legend'); |
189
|
|
|
$mediaForm->addRadioButton('linking', 'default')->val('details')->attr('checked', 'checked'); |
190
|
|
|
$mediaForm->addRadioButton('linking', 'direct')->val('direct'); |
191
|
|
|
$mediaForm->addRadioButton('linking', 'nolink')->val('nolink'); |
192
|
|
|
$mediaForm->addRadioButton('linking', 'linkonly')->val('linkonly'); |
193
|
|
|
$mediaForm->addTagClose('fieldset'); |
194
|
|
|
$mediaForm->addTagClose('div'); |
195
|
|
|
|
196
|
|
|
$mediaForm->addTagOpen('div')->addClass('radio-wrapper'); |
197
|
|
|
$mediaForm->addTagOpen('fieldset'); |
198
|
|
|
$mediaForm->addTagOpen('legend'); |
199
|
|
|
$mediaForm->addHTML('Caching'); |
200
|
|
|
$mediaForm->addTagClose('legend'); |
201
|
|
|
$mediaForm->addRadioButton('caching', 'default')->val('')->attr('checked', 'checked'); |
202
|
|
|
$mediaForm->addRadioButton('caching', 'recache')->val('recache'); |
203
|
|
|
$mediaForm->addRadioButton('caching', 'nocache')->val('nocache'); |
204
|
|
|
$mediaForm->addTagClose('fieldset'); |
205
|
|
|
$mediaForm->addTagClose('div'); |
206
|
|
|
|
207
|
|
|
$mediaForm->addFieldsetClose(); |
208
|
|
|
$mediaForm->addButton('ok-button', 'OK')->attr('type', 'submit'); |
209
|
|
|
$mediaForm->addButton('cancel-button', 'Cancel')->attr('type', 'button'); |
210
|
|
|
|
211
|
|
|
// dynamic image hack? https://www.dokuwiki.org/images#dynamic_images |
212
|
|
|
|
213
|
|
|
echo $mediaForm->toHTML(); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// vim:ts=4:sw=4:et: |
218
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths