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