-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathadmin.php
204 lines (181 loc) · 5.86 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* DokuWiki Plugin upgrade (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
require_once __DIR__ . '/vendor/autoload.php';
class admin_plugin_upgrade extends DokuWiki_Admin_Plugin
{
protected $haderrors = false;
/** @var helper_plugin_upgrade */
protected $helper;
/**
* initialize helper
*/
public function __construct()
{
$this->helper = plugin_load('helper', 'upgrade');
$this->helper->setLogger($this);
}
/** @inheritDoc */
public function getMenuSort()
{
return 555;
}
/** @inheritDoc */
public function handle()
{
if (!empty($_REQUEST['step']) && !checkSecurityToken()) {
unset($_REQUEST['step']);
}
}
public function html()
{
$abrt = false;
$next = false;
$ok = true;
echo '<h1>' . $this->getLang('menu') . '</h1>';
echo '<div id="plugin__upgrade">';
// enable auto scroll
?>
<script type="text/javascript">
var plugin_upgrade = window.setInterval(function () {
var obj = document.getElementById('plugin__upgrade');
if (obj) obj.scrollTop = obj.scrollHeight;
}, 25);
</script>
<?php
// handle current step
$this->nextStep($abrt, $next, $ok);
// disable auto scroll
?>
<script type="text/javascript">
window.setTimeout(function () {
window.clearInterval(plugin_upgrade);
}, 50);
</script>
<?php
echo '</div>';
$careful = '';
if (!$ok) {
echo '<div id="plugin__upgrade_careful">' . $this->getLang('careful') . '</div>';
$careful = 'careful';
}
$action = script();
echo '<form action="' . $action . '" method="post" id="plugin__upgrade_form">';
echo '<input type="hidden" name="do" value="admin" />';
echo '<input type="hidden" name="page" value="upgrade" />';
echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
if ($next) {
echo '<button type="submit"
name="step[' . $next . ']"
value="1"
class="button continue ' . $careful . '">' .
$this->getLang('btn_continue') .
' ➡</button>';
}
if ($abrt) {
echo '<button type="submit"
name="step[cancel]"
value="1"
class="button abort">✖ ' .
$this->getLang('btn_abort') .
'</button>';
}
echo '</form>';
$this->displayProgressBar($next);
}
/**
* Display a progress bar of all steps
*
* @param string $next the next step
*/
private function displayProgressBar($next)
{
$steps = ['version', 'download', 'unpack', 'check', 'upgrade'];
$active = true;
$count = 0;
echo '<div id="plugin__upgrade_meter"><ol>';
foreach ($steps as $step) {
$count++;
if ($step == $next) $active = false;
if ($active) {
echo '<li class="active">';
echo '<span class="step">✔</span>';
} else {
echo '<li>';
echo '<span class="step">' . $count . '</span>';
}
echo '<span class="stage">' . $this->getLang('step_' . $step) . '</span>';
echo '</li>';
}
echo '</ol></div>';
}
/**
* Decides the current step and executes it
*
* @param bool $abrt
* @param bool $next
* @param bool $ok
*/
private function nextStep(&$abrt, &$next, &$ok)
{
if (isset($_REQUEST['step']) && is_array($_REQUEST['step'])) {
$keys = array_keys($_REQUEST['step']);
$step = array_shift($keys);
} else {
$step = '';
}
if ($step == 'cancel' || $step == 'done') {
$ok = $this->helper->cleanup();
if ($step == 'cancel') $step = '';
}
if ($step) {
$abrt = true;
$next = false;
if ($step == 'version') {
$ok = $this->helper->checkVersions();
$next = 'download';
} elseif ($step == 'done') {
echo $this->locale_xhtml('final');
$next = '';
$abrt = '';
} elseif (!file_exists($this->helper->tgzfile)) {
if ($ok = $this->helper->downloadTarball()) $next = 'unpack';
} elseif (!is_dir($this->helper->tgzdir)) {
if ($ok = $this->helper->extractTarball()) $next = 'check';
} elseif ($step != 'upgrade') {
if ($ok = $this->helper->checkPermissions()) $next = 'upgrade';
} elseif ($step == 'upgrade') {
if ($ok = $this->helper->copyFiles()) {
$ok = $this->helper->deleteObsoleteFiles();
$this->helper->cleanup();
$next = 'done';
$abrt = '';
}
} else {
echo 'uhm. what happened? where am I? This should not happen';
}
} else {
# first time run, show intro
echo $this->locale_xhtml('step0');
$this->helper->cleanup(); // make sure we start clean
$abrt = false;
$next = 'version';
}
}
/**
* Print the given message and flush buffers
*
* @param string $level
* @param string $message
*/
public function log($level, $message)
{
echo '<div class="log-' . $level . '">' . $message . '</div>';
flush();
ob_flush();
}
}