Skip to content

Commit de8ede3

Browse files
michituxgithub-actions[bot]
authored andcommitted
🤖 Automatic code style fixes
1 parent bfe59b5 commit de8ede3

File tree

1 file changed

+70
-65
lines changed

1 file changed

+70
-65
lines changed

action.php

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
3+
use dokuwiki\Extension\ActionPlugin;
4+
use dokuwiki\Extension\EventHandler;
5+
use dokuwiki\Extension\Event;
6+
27
/**
38
* DokuWiki Plugin saveandedit (Action Component)
49
*
@@ -12,21 +17,23 @@
1217
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
1318
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
1419

15-
class action_plugin_saveandedit extends DokuWiki_Action_Plugin {
16-
20+
class action_plugin_saveandedit extends ActionPlugin
21+
{
1722
/** The action that has been handled before the current action */
18-
private $previous_act = null;
23+
private $previous_act;
1924

20-
public function register(Doku_Event_Handler $controller) {
25+
public function register(EventHandler $controller)
26+
{
2127
// try to register our handler at a late position so e.g. the edittable plugin has a possibility to process its data
22-
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', null, 1000);
23-
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_html_editform_output');
28+
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', null, 1000);
29+
$controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_html_editform_output');
2430
}
2531

2632
/**
2733
* Clean the environment after saving for the next edit.
2834
*/
29-
private function clean_after_save() {
35+
private function clean_after_save()
36+
{
3037
global $ID, $INFO, $REV, $RANGE, $TEXT, $PRE, $SUF;
3138
$REV = ''; // now we are working on the current revision
3239
// Handle section edits
@@ -43,78 +50,75 @@ private function clean_after_save() {
4350
// Reset the change check
4451
unset($_REQUEST['changecheck']);
4552
// Force rendering of the metadata in order to ensure metadata is correct
46-
p_set_metadata($ID, array(), true);
53+
p_set_metadata($ID, [], true);
4754
$INFO = pageinfo(); // reset pageinfo to new data (e.g. if the page exists)
4855
}
4956

50-
public function handle_action_act_preprocess(Doku_Event $event, $param) {
57+
public function handle_action_act_preprocess(Event $event, $param)
58+
{
5159
global $INPUT;
5260

5361
if (!$INPUT->bool('saveandedit')) {
5462
return;
5563
}
5664

5765
// check if the action was given as array key
58-
if(is_array($event->data)){
59-
list($act) = array_keys($event->data);
66+
if (is_array($event->data)) {
67+
[$act] = array_keys($event->data);
6068
} else {
6169
$act = $event->data;
6270
}
6371

6472
// Greebo and above
6573
if (class_exists('\\dokuwiki\\ActionRouter', false)) {
66-
/*
67-
The ACTION_ACT_PREPROCESS event is triggered several
68-
times, once for every action. After the save has been
69-
executed, the next event is 'draftdel'. We intercept
70-
the 'draftdel' action and replace it by 'edit'. As this
71-
is a logical place where other plugins may want to save
72-
data (e.g. blogtng), we try to be handled relatively
73-
late. To fix plugins that want to handle the 'edit'
74-
action, we trigger a new event for the 'edit' action.
75-
*/
74+
/*
75+
The ACTION_ACT_PREPROCESS event is triggered several
76+
times, once for every action. After the save has been
77+
executed, the next event is 'draftdel'. We intercept
78+
the 'draftdel' action and replace it by 'edit'. As this
79+
is a logical place where other plugins may want to save
80+
data (e.g. blogtng), we try to be handled relatively
81+
late. To fix plugins that want to handle the 'edit'
82+
action, we trigger a new event for the 'edit' action.
83+
*/
7684
if ($this->previous_act === 'save' && $act === 'draftdel') {
7785
$this->clean_after_save();
7886
$event->data = 'edit';
7987

80-
/*
81-
The edittable plugin would restore $TEXT from the
82-
edittable_data post data on each
83-
ACTION_ACT_PREPROCESS call. This breaks the
84-
automatic restore of the prefix and suffix
85-
data. Stop it from doing this by unsetting its
86-
data.
87-
*/
88-
$INPUT->post->remove('edittable_data');
89-
90-
/*
91-
Stop propagation of the event. All subsequent event
92-
handlers will be called anyway again by the event
93-
triggered below.
94-
*/
95-
$event->stopPropagation();
96-
97-
/*
98-
Trigger a new event for the edit action.
99-
This ensures that all event handlers for the edit
100-
action are called. However, we only advise the
101-
before handlers and re-use the default action and
102-
the after handling of the original event.
103-
*/
104-
$new_evt = new \Doku_Event('ACTION_ACT_PREPROCESS', $event->data);
105-
// prevent the default action of the original event
106-
if (!$new_evt->advise_before()) {
107-
$event->preventDefault();
108-
}
109-
88+
/*
89+
The edittable plugin would restore $TEXT from the
90+
edittable_data post data on each
91+
ACTION_ACT_PREPROCESS call. This breaks the
92+
automatic restore of the prefix and suffix
93+
data. Stop it from doing this by unsetting its
94+
data.
95+
*/
96+
$INPUT->post->remove('edittable_data');
97+
98+
/*
99+
Stop propagation of the event. All subsequent event
100+
handlers will be called anyway again by the event
101+
triggered below.
102+
*/
103+
$event->stopPropagation();
104+
105+
/*
106+
Trigger a new event for the edit action.
107+
This ensures that all event handlers for the edit
108+
action are called. However, we only advise the
109+
before handlers and re-use the default action and
110+
the after handling of the original event.
111+
*/
112+
$new_evt = new Event('ACTION_ACT_PREPROCESS', $event->data);
113+
// prevent the default action of the original event
114+
if (!$new_evt->advise_before()) {
115+
$event->preventDefault();
116+
}
110117
}
111-
112118
$this->previous_act = $act;
113-
114-
// pre-Greebo compatibility
115-
} else if ($act === 'save' && actionOK($act) && act_permcheck($act) == 'save' && checkSecurityToken()) {
119+
// pre-Greebo compatibility
120+
} elseif ($act === 'save' && actionOK($act) && act_permcheck($act) == 'save' && checkSecurityToken()) {
116121
$event->data = act_save($act);
117-
118122
if ($event->data === 'show') {
119123
$event->data = 'edit';
120124
$this->clean_after_save();
@@ -126,20 +130,21 @@ public function handle_action_act_preprocess(Doku_Event $event, $param) {
126130
}
127131
}
128132

129-
public function handle_html_editform_output(Doku_Event $event, $param) {
133+
public function handle_html_editform_output(Event $event, $param)
134+
{
130135
global $INPUT;
131136

132-
$form = $event->data;
133-
$pos = $form->findPositionByAttribute('type','submit');
137+
$form = $event->data;
138+
$pos = $form->findPositionByAttribute('type', 'submit');
134139

135-
if(!$pos) return; // no submit button found, source view
136-
$pos -= 1;
140+
if (!$pos) return; // no submit button found, source view
141+
--$pos;
137142

138-
$form->addTagOpen('div', $pos++);
139-
$attrs = $INPUT->bool('saveandedit') ? array('checked' => 'checked') : array();
143+
$form->addTagOpen('div', $pos++);
144+
$attrs = $INPUT->bool('saveandedit') ? ['checked' => 'checked'] : [];
140145

141-
$cb = $form->addCheckBox('saveandedit', $this->getLang('btn_saveandedit'), $pos++);
142-
$cb->attrs = $attrs;
146+
$cb = $form->addCheckBox('saveandedit', $this->getLang('btn_saveandedit'), $pos++);
147+
$cb->attrs = $attrs;
143148
$form->addtagClose('div', $pos++);
144149
}
145150
}

0 commit comments

Comments
 (0)