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
|
|
|
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder; |
11
|
|
|
|
12
|
|
|
if (!defined('DOKU_INC')) { |
13
|
|
|
die(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
class action_plugin_prosemirror_parser extends DokuWiki_Action_Plugin |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Registers a callback function for a given event |
21
|
|
|
* |
22
|
|
|
* @param Doku_Event_Handler $controller DokuWiki's event controller object |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function register(Doku_Event_Handler $controller) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_preprocess'); |
29
|
|
|
$controller->register_hook('DRAFT_SAVE', 'BEFORE', $this, 'handle_draft'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Triggered by: COMMON_DRAFT_SAVE |
34
|
|
|
* |
35
|
|
|
* @param Doku_Event $event |
36
|
|
|
* @param $param |
37
|
|
|
*/ |
38
|
|
|
public function handle_draft(Doku_Event $event, $param) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
global $INPUT; |
41
|
|
|
$unparsedJSON = $INPUT->post->str('prosemirror_json'); |
42
|
|
|
if (empty($unparsedJSON)) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** @var \helper_plugin_prosemirror $helper */ |
48
|
|
|
$helper = plugin_load('helper', 'prosemirror'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
try { |
51
|
|
|
$syntax = $helper->getSyntaxFromProsemirrorData($unparsedJSON); |
52
|
|
|
} catch (\Throwable $e) { |
53
|
|
|
$event->preventDefault(); |
54
|
|
|
$event->stopPropagation(); |
55
|
|
|
|
56
|
|
|
$errorMsg = $e->getMessage(); |
57
|
|
|
|
58
|
|
|
if ($helper->tryToLogErrorToSentry($e, ['json' => $unparsedJSON])) { |
59
|
|
|
$errorMsg .= ' -- The error has been logged to Sentry.'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$event->data['errors'][] = $errorMsg; |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$event->data['text'] = $syntax; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* [Custom event handler which performs action] |
71
|
|
|
* |
72
|
|
|
* Triggered by: ACTION_ACT_PREPROCESS |
73
|
|
|
* |
74
|
|
|
* @param Doku_Event $event event object by reference |
75
|
|
|
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this |
76
|
|
|
* handler was registered] |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function handle_preprocess(Doku_Event $event, $param) |
81
|
|
|
{ |
82
|
|
|
global $TEXT, $INPUT; |
83
|
|
|
if ($INPUT->server->str('REQUEST_METHOD') !== 'POST' |
84
|
|
|
|| !in_array($event->data, ['save', 'preview']) |
85
|
|
|
|| !$INPUT->post->has('prosemirror_json') |
86
|
|
|
) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$unparsedJSON = $INPUT->post->str('prosemirror_json'); |
91
|
|
|
|
92
|
|
|
/** @var \helper_plugin_prosemirror $helper */ |
93
|
|
|
$helper = plugin_load('helper', 'prosemirror'); |
|
|
|
|
94
|
|
|
try { |
95
|
|
|
$syntax = $helper->getSyntaxFromProsemirrorData($unparsedJSON); |
96
|
|
|
} catch (\Throwable $e) { |
97
|
|
|
$event->preventDefault(); |
98
|
|
|
$event->stopPropagation(); |
99
|
|
|
|
100
|
|
|
$errorMsg = $e->getMessage(); |
101
|
|
|
|
102
|
|
|
if ($helper->tryToLogErrorToSentry($e, ['json' => $unparsedJSON])) { |
103
|
|
|
$errorMsg .= ' -- The error has been logged to Sentry.'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
msg($errorMsg, -1); |
|
|
|
|
107
|
|
|
return; |
108
|
|
|
} |
109
|
|
|
if (!empty($syntax)) { |
110
|
|
|
$TEXT = $syntax; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// vim:ts=4:sw=4:et: |
117
|
|
|
|
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