-
Notifications
You must be signed in to change notification settings - Fork 7
/
admin.php
164 lines (133 loc) · 4.42 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
* Plugin BatchEdit
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Mykola Ostrovskyy <dwpforge@gmail.com>
*/
require_once(DOKU_PLUGIN . 'batchedit/config.php');
require_once(DOKU_PLUGIN . 'batchedit/engine.php');
require_once(DOKU_PLUGIN . 'batchedit/interface.php');
require_once(DOKU_PLUGIN . 'batchedit/request.php');
class admin_plugin_batchedit extends DokuWiki_Admin_Plugin {
private static $instance = NULL;
private $command;
private $config;
private $session;
public static function getInstance() {
return self::$instance;
}
public function __construct() {
$this->command = BatcheditRequest::COMMAND_WELCOME;
$this->config = new BatcheditConfig();
$this->session = new BatcheditSession($this->getConf('sessionexp'));
self::$instance = $this;
}
/**
*
*/
public function getConfig() {
return $this->config;
}
/**
* Handle user request
*/
public function handle() {
try {
$this->handleRequest();
}
catch (BatcheditException $error) {
$this->session->setError($error);
$this->session->expire();
}
}
/**
* Output appropriate html
*/
public function html() {
$interface = new BatcheditInterface($this);
$interface->configure($this->config);
$interface->printBeginning($this->session->getId());
$interface->printMessages($this->session->getMessages());
if ($this->session->getMatchCount() > 0) {
$interface->printTotalStats($this->command, $this->session->getMatchCount(),
$this->session->getPageCount(), $this->session->getEditCount());
$interface->printMatches($this->session->getPages());
}
$interface->printMainForm($this->session->getMatchCount() > 0);
$interface->printEnding();
}
/**
*
*/
private function handleRequest() {
$request = new BatcheditRequest($this->config);
$this->command = $request->getCommand();
switch ($this->command) {
case BatcheditRequest::COMMAND_PREVIEW:
$this->handlePreview($request);
break;
case BatcheditRequest::COMMAND_APPLY:
$this->handleApply($request);
break;
}
}
/**
*
*/
private function handlePreview($request) {
$engine = $this->createEngine();
$this->session->setId($request->getSessionId());
$this->findMatches($engine, $request);
$this->markMatches($engine, $request);
$this->session->save($request, $this->config);
}
/**
*
*/
private function handleApply($request) {
$engine = $this->createEngine();
if (!$this->session->load($request, $this->config)) {
$this->findMatches($engine, $request);
}
$this->applyMatches($engine, $request);
$this->session->save($request, $this->config);
}
/**
*
*/
private function createEngine() {
if ($this->getConf('timelimit') > 0) {
set_time_limit($this->getConf('timelimit'));
}
return new BatcheditEngine($this->session);
}
/**
*
*/
private function findMatches($engine, $request) {
$engine->findMatches($request->getNamespace(), $request->getRegexp(), $request->getReplacement(),
$this->config->getConf('searchlimit') ? $this->config->getConf('searchmax') : -1,
$this->config->getConf('matchctx') ? $this->config->getConf('ctxchars') : 0,
$this->config->getConf('ctxlines'), $this->config->getConf('tplpatterns'));
}
/**
*
*/
private function markMatches($engine, $request) {
if (!$this->config->getConf('keepmarks') || $this->session->getMatchCount() == 0 || empty($request->getAppliedMatches())) {
return;
}
$engine->markRequestedMatches($request->getAppliedMatches(), $this->config->getConf('markpolicy'));
}
/**
*
*/
private function applyMatches($engine, $request) {
if ($this->session->getMatchCount() == 0 || empty($request->getAppliedMatches())) {
return;
}
$engine->markRequestedMatches($request->getAppliedMatches());
$engine->applyMatches($request->getSummary(), $request->getMinorEdit());
}
}