author | Dan |
Thu, 28 Jun 2007 15:26:40 -0400 | |
changeset 31 | dc8741857bde |
parent 21 | 663fcf528726 |
child 33 | 143d3ee32f3c |
permissions | -rwxr-xr-x |
0 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
5 |
* Version 1.0 (Banshee) |
0 | 6 |
* upgrade.php - upgrade script |
7 |
* Copyright (C) 2006-2007 Dan Fuhry |
|
8 |
* |
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 |
*/ |
|
15 |
||
16 |
define('IN_ENANO_INSTALL', 'true'); |
|
17 |
||
18 |
if(!defined('scriptPath')) { |
|
19 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
20 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
21 |
define('scriptPath', $sp); |
|
22 |
} |
|
23 |
||
24 |
if(!defined('contentPath')) { |
|
25 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
26 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
27 |
define('contentPath', $sp); |
|
28 |
} |
|
29 |
||
30 |
global $_starttime, $this_page, $sideinfo; |
|
31 |
$_starttime = microtime(true); |
|
32 |
||
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
33 |
// Determine directory (special case for development servers) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
34 |
if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') ) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
35 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
36 |
$filename = str_replace('/repo/', '/', __FILE__); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
37 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
38 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
39 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
40 |
$filename = __FILE__; |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
41 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
42 |
|
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
43 |
define('ENANO_ROOT', dirname($filename)); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
44 |
|
0 | 45 |
require(ENANO_ROOT.'/includes/constants.php'); |
46 |
||
47 |
if(defined('ENANO_DEBUG')) |
|
48 |
{ |
|
49 |
require_once(ENANO_ROOT.'/includes/debugger/debugConsole.php'); |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
function dc_here($m) { return false; } |
|
54 |
function dc_dump($a, $g) { return false; } |
|
55 |
function dc_watch($n) { return false; } |
|
56 |
function dc_start_timer($u) { return false; } |
|
57 |
function dc_stop_timer($m) { return false; } |
|
58 |
} |
|
59 |
||
60 |
// SCRIPT CONFIGURATION |
|
61 |
// Everything related to versions goes here! |
|
62 |
||
63 |
// Valid versions to upgrade from |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
64 |
$valid_versions = Array('1.0b1', '1.0b2', '1.0b3', '1.0b4', '1.0RC1', '1.0RC2', '1.0RC3'); |
0 | 65 |
|
66 |
// Basically a list of dependencies, which should be resolved automatically |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
67 |
// If, for example, upgrading from 1.0b1 to 1.0RC1 requires one extra query that would not |
0 | 68 |
// normally be required (for whatever reason) then you would add a custom version number to the array under key '1.0b1'. |
69 |
$deps_list = Array( |
|
70 |
'1.0b1' => Array('1.0b2'), |
|
71 |
'1.0b2' => Array('1.0b3'), |
|
72 |
'1.0b3' => Array('1.0b4'), |
|
73 |
'1.0b4' => Array('1.0RC1'), |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
74 |
'1.0RC1' => Array('1.0RC2'), |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
75 |
'1.0RC2' => Array('1.0RC3') |
0 | 76 |
); |
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
77 |
$this_version = '1.0'; |
0 | 78 |
$func_list = Array( |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
79 |
'1.0b4' => Array('u_1_0_RC1_update_user_ids', 'u_1_0_RC1_add_admins_to_group', 'u_1_0_RC1_alter_files_table', 'u_1_0_RC1_destroy_session_cookie', 'u_1_0_RC1_set_contact_email', 'u_1_0_RC1_update_page_text'), // , |
16
64e0d3d4cf14
Emergency version change to 1.0rc3 to fix XSS vulnerabilities
Dan
parents:
0
diff
changeset
|
80 |
// '1.0RC2' => Array('u_1_0_populate_userpage_comments') |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
81 |
'1.0RC3' => Array('u_1_0_RC3_make_users_extra') |
0 | 82 |
); |
83 |
||
84 |
if(!isset($_GET['mode'])) |
|
85 |
{ |
|
86 |
$_GET['mode'] = 'login'; |
|
87 |
} |
|
88 |
||
89 |
function err($t) |
|
90 |
{ |
|
91 |
global $template; |
|
92 |
echo $t; |
|
93 |
$template->footer(); |
|
94 |
exit; |
|
95 |
} |
|
96 |
||
97 |
require(ENANO_ROOT.'/includes/template.php'); |
|
98 |
||
99 |
// Initialize the session manager |
|
100 |
require(ENANO_ROOT.'/includes/functions.php'); |
|
101 |
require(ENANO_ROOT.'/includes/dbal.php'); |
|
102 |
require(ENANO_ROOT.'/includes/paths.php'); |
|
103 |
require(ENANO_ROOT.'/includes/sessions.php'); |
|
104 |
require(ENANO_ROOT.'/includes/plugins.php'); |
|
105 |
require(ENANO_ROOT.'/includes/rijndael.php'); |
|
106 |
require(ENANO_ROOT.'/includes/render.php'); |
|
107 |
$db = new mysql(); |
|
108 |
$db->connect(); |
|
109 |
||
110 |
$plugins = new pluginLoader(); |
|
111 |
||
112 |
if(!defined('ENANO_CONFIG_FETCHED')) |
|
113 |
{ |
|
114 |
// Select and fetch the site configuration |
|
115 |
$e = $db->sql_query('SELECT config_name, config_value FROM '.table_prefix.'config;'); |
|
116 |
if ( !$e ) |
|
117 |
{ |
|
118 |
$db->_die('Some critical configuration information could not be selected.'); |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
define('ENANO_CONFIG_FETCHED', ''); // Used in die_semicritical to figure out whether to call getConfig() or not |
|
123 |
} |
|
124 |
||
125 |
$enano_config = Array(); |
|
126 |
while($r = $db->fetchrow()) |
|
127 |
{ |
|
128 |
$enano_config[$r['config_name']] = $r['config_value']; |
|
129 |
} |
|
130 |
$db->free_result(); |
|
131 |
} |
|
132 |
||
133 |
$v = enano_version(); |
|
134 |
if(in_array($v, Array(false, '', '1.0b3', '1.0b4'))) |
|
135 |
{ |
|
136 |
$ul_admin = 2; |
|
137 |
$ul_mod = 1; |
|
138 |
$ul_member = 0; |
|
139 |
$ul_guest = -1; |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
$ul_admin = USER_LEVEL_ADMIN; |
|
144 |
$ul_mod = USER_LEVEL_MOD; |
|
145 |
$ul_member = USER_LEVEL_MEMBER; |
|
146 |
$ul_guest = USER_LEVEL_GUEST; |
|
147 |
} |
|
148 |
||
149 |
$_GET['title'] = 'unset'; |
|
150 |
||
151 |
$session = new sessionManager(); |
|
152 |
$paths = new pathManager(); |
|
153 |
$session->start(); |
|
154 |
||
155 |
$template = new template_nodb(); |
|
156 |
$template->load_theme('oxygen', 'bleu', false); |
|
157 |
||
158 |
$modestrings = Array( |
|
159 |
'login' => 'Administrative login', |
|
160 |
'welcome' => 'Welcome', |
|
161 |
'setversion' => 'Select Enano version', |
|
162 |
'confirm' => 'Confirm upgrade', |
|
163 |
'upgrade' => 'Database installation', |
|
164 |
'finish' => 'Upgrade complete' |
|
165 |
); |
|
166 |
||
167 |
$sideinfo = ''; |
|
168 |
$vars = $template->extract_vars('elements.tpl'); |
|
169 |
$p = $template->makeParserText($vars['sidebar_button']); |
|
170 |
foreach ( $modestrings as $id => $str ) |
|
171 |
{ |
|
172 |
if ( $_GET['mode'] == $id ) |
|
173 |
{ |
|
174 |
$flags = 'style="font-weight: bold; text-decoration: underline;"'; |
|
175 |
$this_page = $str; |
|
176 |
} |
|
177 |
else |
|
178 |
{ |
|
179 |
$flags = ''; |
|
180 |
} |
|
181 |
$p->assign_vars(Array( |
|
182 |
'HREF' => '#', |
|
183 |
'FLAGS' => $flags . ' onclick="return false;"', |
|
184 |
'TEXT' => $str |
|
185 |
)); |
|
186 |
$sideinfo .= $p->run(); |
|
187 |
} |
|
188 |
||
189 |
$template->init_vars(); |
|
190 |
||
191 |
function upg_assign_vars($schema) |
|
192 |
{ |
|
193 |
$schema = str_replace('{{SITE_NAME}}', mysql_real_escape_string(getConfig('site_name')), $schema); |
|
194 |
$schema = str_replace('{{SITE_DESC}}', mysql_real_escape_string(getConfig('site_desc')), $schema); |
|
195 |
$schema = str_replace('{{COPYRIGHT}}', mysql_real_escape_string(getConfig('copyright_notice')), $schema); |
|
196 |
$schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema); |
|
197 |
if(getConfig('wiki_mode')=='1') $schema = str_replace('{{WIKI_MODE}}', '1', $schema); |
|
198 |
else $schema = str_replace('{{WIKI_MODE}}', '0', $schema); |
|
199 |
return $schema; |
|
200 |
} |
|
201 |
||
202 |
/* Version-specific functions */ |
|
203 |
||
204 |
function u_1_0_RC1_update_user_ids() |
|
205 |
{ |
|
206 |
global $db; |
|
207 |
// First, make sure this hasn't already been done |
|
208 |
$q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE user_id=1;'); |
|
209 |
if ( !$q ) |
|
210 |
$db->_die(); |
|
211 |
$row = $db->fetchrow(); |
|
212 |
if ( $row['username'] == 'Anonymous' ) |
|
213 |
return true; |
|
214 |
// Find the first unused user ID |
|
215 |
$used = Array(); |
|
216 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users'); |
|
217 |
if ( !$q ) |
|
218 |
$db->_die(); |
|
219 |
$c = false; |
|
220 |
while ( $row = $db->fetchrow() ) |
|
221 |
{ |
|
222 |
$i = intval($row['user_id']); |
|
223 |
$used[$i] = true; |
|
224 |
if ( !isset($used[$i - 1]) && $c ) |
|
225 |
{ |
|
226 |
$id = $i - 1; |
|
227 |
break; |
|
228 |
} |
|
229 |
$c = true; |
|
230 |
} |
|
231 |
if ( !isset($id) ) |
|
232 |
$id = $i + 1; |
|
233 |
$db->free_result(); |
|
234 |
||
235 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=' . $id . ' WHERE user_id=1;'); |
|
236 |
if(!$q) |
|
237 |
$db->_die(); |
|
238 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=1 WHERE user_id=-1 AND username=\'Anonymous\';'); |
|
239 |
if(!$q) |
|
240 |
$db->_die(); |
|
241 |
||
242 |
} |
|
243 |
||
244 |
function u_1_0_RC1_add_admins_to_group() |
|
245 |
{ |
|
246 |
global $db; |
|
247 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_level=' . USER_LEVEL_ADMIN . ';'); |
|
248 |
if ( !$q ) |
|
249 |
$db->_die(); |
|
250 |
$base = 'INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES'; |
|
251 |
$blocks = Array(); |
|
252 |
while ( $row = $db->fetchrow($q) ) |
|
253 |
{ |
|
254 |
$blocks[] = '(2,' . $row['user_id'] . ')'; |
|
255 |
} |
|
256 |
$blocks = implode(',', $blocks); |
|
257 |
$sql = $base . $blocks . ';'; |
|
258 |
if(!$db->sql_query($sql)) |
|
259 |
$db->_die(); |
|
260 |
} |
|
261 |
||
262 |
function u_1_0_RC1_alter_files_table() |
|
263 |
{ |
|
264 |
global $db; |
|
265 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
266 |
@mkdir(ENANO_ROOT . '/files'); |
|
267 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
268 |
die('ERROR: Couldn\'t create files directory'); |
|
269 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
270 |
if(!$q) $db->_die(); |
|
271 |
while ( $row = $db->fetchrow() ) |
|
272 |
{ |
|
273 |
$file_data = base64_decode($row['data']); |
|
274 |
$path = ENANO_ROOT . '/files/' . md5( $row['filename'] . '_' . $file_data ) . '_' . $row['time_id'] . $row['file_extension']; |
|
275 |
@unlink($path); |
|
276 |
$handle = @fopen($path, 'w'); |
|
277 |
if(!$handle) |
|
278 |
die('fopen failed'); |
|
279 |
fwrite($handle, $file_data); |
|
280 |
fclose($handle); |
|
281 |
||
282 |
} |
|
283 |
||
284 |
$q = $db->sql_query('ALTER TABLE '.table_prefix.'files DROP PRIMARY KEY, ADD COLUMN file_id int(12) NOT NULL auto_increment FIRST, ADD PRIMARY KEY (file_id), ADD COLUMN file_key varchar(32) NOT NULL;'); |
|
285 |
if(!$q) $db->_die(); |
|
286 |
||
287 |
$list = Array(); |
|
288 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
289 |
if(!$q) $db->_die(); |
|
290 |
while ( $row = $db->fetchrow($q) ) |
|
291 |
{ |
|
292 |
$file_data = base64_decode($row['data']); |
|
293 |
$key = md5( $row['filename'] . '_' . $file_data ); |
|
294 |
$list[] = 'UPDATE '.table_prefix.'files SET file_key=\'' . $key . '\' WHERE file_id=' . $row['file_id'] . ';'; |
|
295 |
} |
|
296 |
||
297 |
foreach ( $list as $sql ) |
|
298 |
{ |
|
299 |
if(!$db->sql_query($sql)) $db->_die(); |
|
300 |
} |
|
301 |
||
302 |
if(!$db->sql_query('ALTER TABLE '.table_prefix.'files DROP data')) $db->_die(); |
|
303 |
||
304 |
} |
|
305 |
||
306 |
function u_1_0_RC1_destroy_session_cookie() |
|
307 |
{ |
|
308 |
unset($_COOKIE['sid']); |
|
309 |
setcookie('sid', '', time()-3600*24, scriptPath); |
|
310 |
setcookie('sid', '', time()-3600*24, scriptPath.'/'); |
|
311 |
} |
|
312 |
||
313 |
function u_1_0_RC1_set_contact_email() |
|
314 |
{ |
|
315 |
global $db; |
|
316 |
$q = $db->sql_query('SELECT email FROM '.table_prefix.'users WHERE user_level='.USER_LEVEL_ADMIN.' ORDER BY user_level ASC LIMIT 1;'); |
|
317 |
if(!$q) |
|
318 |
$db->_die(); |
|
319 |
$row = $db->fetchrow(); |
|
320 |
setConfig('contact_email', $row['email']); |
|
321 |
} |
|
322 |
||
323 |
function u_1_0_RC1_update_page_text() |
|
324 |
{ |
|
325 |
global $db; |
|
326 |
$q = $db->sql_unbuffered_query('SELECT page_id,namespace,page_text,char_tag FROM '.table_prefix.'page_text'); |
|
327 |
if (!$q) |
|
328 |
$db->_die(); |
|
329 |
||
330 |
$qs = array(); |
|
331 |
||
332 |
while ( $row = $db->fetchrow($q) ) |
|
333 |
{ |
|
334 |
$row['page_text'] = str_replace(Array( |
|
335 |
"{QUOT:{$row['char_tag']}}", |
|
336 |
"{APOS:{$row['char_tag']}}", |
|
337 |
"{SLASH:{$row['char_tag']}}" |
|
338 |
), Array( |
|
339 |
'"', "'", '\\' |
|
340 |
), $row['page_text']); |
|
341 |
$qs[] = 'UPDATE '.table_prefix.'page_text SET page_text=\'' . mysql_real_escape_string($row['page_text']) . '\' |
|
342 |
WHERE page_id=\'' . mysql_real_escape_string($row['page_id']) . '\' AND |
|
343 |
namespace=\'' . mysql_real_escape_string($row['namespace']) . '\';'; |
|
344 |
} |
|
345 |
||
346 |
foreach($qs as $query) |
|
347 |
{ |
|
348 |
if(!$db->sql_query($query)) |
|
349 |
$db->_die(); |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
function u_1_0_populate_userpage_comments() |
|
354 |
{ |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
355 |
// |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
356 |
// UNFINISHED... |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
357 |
// |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
358 |
|
16
64e0d3d4cf14
Emergency version change to 1.0rc3 to fix XSS vulnerabilities
Dan
parents:
0
diff
changeset
|
359 |
/* |
0 | 360 |
global $db; |
361 |
$q = $db->sql_query('SELECT COUNT(c.comment_id) AS num_comments...'); |
|
362 |
if ( !$q ) |
|
363 |
$db->_die(); |
|
364 |
||
365 |
while ( $row = $db->fetchrow() ) |
|
366 |
{ |
|
367 |
||
368 |
} |
|
16
64e0d3d4cf14
Emergency version change to 1.0rc3 to fix XSS vulnerabilities
Dan
parents:
0
diff
changeset
|
369 |
*/ |
0 | 370 |
} |
371 |
||
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
372 |
function u_1_0_RC3_make_users_extra() |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
373 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
374 |
global $db; |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
375 |
$q = $db->sql_query('SELECT user_id FROM users WHERE user_id > 1;'); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
376 |
if ( !$q ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
377 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
378 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
379 |
$ids = array(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
380 |
while ( $row = $db->fetchrow() ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
381 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
382 |
$ids[] = intval($row['user_id']); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
383 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
384 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
385 |
$ids = '(' . implode('),(', $ids) . ')'; |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
386 |
$sql = "INSERT INTO " . table_prefix . "users_extra(user_id) VALUES$ids;"; |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
387 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
388 |
if ( !$db->sql_query($sql) ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
389 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
390 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
391 |
|
0 | 392 |
switch($_GET['mode']) |
393 |
{ |
|
394 |
case "login": |
|
395 |
if($session->user_logged_in && $session->user_level >= $ul_admin) |
|
396 |
{ |
|
397 |
if(isset($_POST['login'])) |
|
398 |
{ |
|
399 |
$session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_admin); |
|
400 |
if($session->sid_super) |
|
401 |
{ |
|
402 |
header('Location: upgrade.php?mode=welcome&auth='.$session->sid_super); |
|
403 |
exit; |
|
404 |
} |
|
405 |
} |
|
406 |
$template->header(); |
|
407 |
?> |
|
408 |
<form action="upgrade.php?mode=login" method="post"> |
|
409 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
410 |
<tr> |
|
411 |
<th colspan="2">You must re-authenticate to perform this upgrade.</th> |
|
412 |
</tr> |
|
413 |
<?php |
|
414 |
if(isset($_POST['login'])) |
|
415 |
{ |
|
416 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
417 |
} |
|
418 |
?> |
|
419 |
<tr> |
|
420 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
421 |
</tr> |
|
422 |
<tr> |
|
423 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
424 |
</tr> |
|
425 |
<tr> |
|
426 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
427 |
</tr> |
|
428 |
</table> |
|
429 |
</form> |
|
430 |
<?php |
|
431 |
} |
|
432 |
else |
|
433 |
{ |
|
434 |
if(isset($_POST['login'])) |
|
435 |
{ |
|
436 |
$result = $session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_member); |
|
437 |
if($result == 'success') |
|
438 |
{ |
|
439 |
header('Location: upgrade.php'); |
|
440 |
exit; |
|
441 |
} |
|
442 |
} |
|
443 |
$template->header(); |
|
444 |
?> |
|
445 |
<form action="upgrade.php?mode=login" method="post"> |
|
446 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
447 |
<tr> |
|
448 |
<th colspan="2">Please log in to continue with this upgrade.</th> |
|
449 |
</tr> |
|
450 |
<?php |
|
451 |
if(isset($_POST['login'])) |
|
452 |
{ |
|
453 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
454 |
} |
|
455 |
?> |
|
456 |
<tr> |
|
457 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
458 |
</tr> |
|
459 |
<tr> |
|
460 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
461 |
</tr> |
|
462 |
<tr> |
|
463 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
464 |
</tr> |
|
465 |
</table> |
|
466 |
</form> |
|
467 |
<?php |
|
468 |
} |
|
469 |
break; |
|
470 |
case "welcome": |
|
471 |
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
472 |
||
473 |
// Just show a simple welcome page to display version information |
|
474 |
$template->header(); |
|
475 |
require('config.php'); |
|
476 |
||
477 |
?> |
|
478 |
||
479 |
<div style="text-align: center; margin-top: 10px;"> |
|
480 |
<img alt="[ Enano CMS Project logo ]" src="images/enano-artwork/installer-greeting-blue.png" style="display: block; margin: 0 auto; padding-left: 134px;" /> |
|
481 |
<h2>Welcome to the Enano upgrade wizard</h2> |
|
482 |
<?php |
|
483 |
if ( file_exists('./_nightly.php') ) |
|
484 |
{ |
|
485 |
echo '<div class="warning-box" style="text-align: left; margin: 10px auto; display: table; width: 60%;"><b>You are about to upgrade to a NIGHTLY BUILD of Enano.</b><br />Nightly builds CANNOT be re-upgraded to the final release. They may also contain serious flaws, security problems, or extraneous debugging information. Continuing this process on a production site is NOT recommended.</div>'; |
|
486 |
} |
|
487 |
?> |
|
488 |
</div> |
|
489 |
<div style="display: table; margin: 0 auto;"> |
|
490 |
<p>You are about to upgrade Enano to version <b><?php echo $this_version; ?></b>. Before you continue, please ensure that:</p> |
|
491 |
<ul> |
|
492 |
<li>You have completely backed up your database (<b><?php echo "$dbhost:$dbname"; ?></b>)</li> |
|
493 |
<li>You have backed up the entire Enano directory (<b><?php echo ENANO_ROOT; ?></b>)</li> |
|
494 |
<li>You have reviewed the release notes for this version, and you<br />are comfortable with any known bugs or issues</li> |
|
495 |
</ul> |
|
496 |
</div> |
|
497 |
<div style="text-align: center; margin-top: 10px;"> |
|
498 |
<form action="upgrade.php?mode=setversion&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
499 |
<input type="submit" value="Continue with upgrade" /> |
|
500 |
</form> |
|
501 |
</div> |
|
502 |
||
503 |
<?php |
|
504 |
||
505 |
break; |
|
506 |
case "setversion": |
|
507 |
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
508 |
$v = ( function_exists('enano_version') ) ? enano_version() : ''; |
|
509 |
if(!in_array($v, $valid_versions) && $v != '') |
|
510 |
{ |
|
511 |
$template->header(); |
|
512 |
?> |
|
513 |
<p>Your version of Enano (<?php echo $v; ?>) can't be upgraded to this version (<?php echo $this_version; ?>).</p> |
|
514 |
<?php |
|
515 |
break; |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
516 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
517 |
else if($v == '') |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
518 |
{ |
0 | 519 |
// OK, we don't know which version he's running. So we'll cheat ;-) |
520 |
$template->header(); |
|
521 |
echo "<form action='upgrade.php?mode=confirm&auth={$session->sid_super}' method='post'>"; |
|
522 |
?> |
|
523 |
<p>Sorry, we couldn't detect which version of Enano you're running on your server. Please select which version of Enano you have below, and make absolutely sure that you're correct.</p> |
|
524 |
<p><select name="version"><?php |
|
525 |
foreach($valid_versions as $c) |
|
526 |
{ |
|
527 |
echo "<option value='{$c}'>{$c}</option>"; |
|
528 |
} |
|
529 |
?></select></p> |
|
530 |
<p> |
|
531 |
<input type="submit" value="Continue" /> |
|
532 |
</p> |
|
533 |
<?php |
|
534 |
echo `</form>`; |
|
535 |
break; |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
536 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
537 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
538 |
{ |
0 | 539 |
header('Location: upgrade.php?mode=confirm&auth='.$session->sid_super); |
540 |
} |
|
541 |
break; |
|
542 |
case "confirm": |
|
543 |
$enano_version = ( isset($_POST['version']) ) ? $_POST['version'] : enano_version(); |
|
544 |
||
545 |
$template->header(); |
|
546 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
547 |
?> |
|
548 |
<form action="upgrade.php?mode=upgrade&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
549 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
550 |
<tr> |
|
551 |
<td colspan="2"><p><b>Are you sure you want to perform this upgrade?</b></p><p>You can still cancel the upgrade process now. If<br />the upgrade fails, you will need to roll back<br />any actions made using manual SQL queries.</p><p><b>Please clear your browser cache or<br />shift-reload after the upgrade.</b><br />If you fail to do so, some page elements may<br />be broken.</td> |
|
552 |
</tr> |
|
553 |
<tr> |
|
554 |
<td colspan="2" style="text-align: center;"> |
|
555 |
<input type="hidden" name="enano_version" value="<?php echo $enano_version; ?>" /> |
|
556 |
<input type="submit" name="doit" value="Upgrade Enano!" /> |
|
557 |
</td> |
|
558 |
</tr> |
|
559 |
</table> |
|
560 |
</form> |
|
561 |
<?php |
|
562 |
break; |
|
563 |
case "upgrade": |
|
564 |
$template->header(); |
|
565 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
566 |
if(!isset($_POST['enano_version'])) { echo '<p>Can\'t find the version information on the POST query, are you trying to do this upgrade directly? Please <a href="upgrade.php">restart the upgrade</a>.</p>'; break; } |
|
567 |
$enano_version = $_POST['enano_version']; |
|
568 |
echo '<p>Preparing for schema execution...'; |
|
569 |
// Build an array of queries |
|
570 |
$schema = file_get_contents('upgrade.sql'); |
|
571 |
||
572 |
// Strip out and process version blocks |
|
573 |
preg_match_all('#---BEGIN ([0-9A-z\.\-]*?)---'."\n".'(.*?)'."\n".'---END \\1---#is', $schema, $matches); |
|
574 |
||
575 |
$from_list =& $matches[1]; |
|
576 |
$query_list =& $matches[2]; |
|
577 |
||
578 |
foreach($matches[0] as $m) |
|
579 |
{ |
|
580 |
$schema = str_replace($m, '', $schema); |
|
581 |
} |
|
582 |
$schema = explode("\n", $schema); |
|
583 |
foreach($schema as $k => $q) |
|
584 |
{ |
|
585 |
if(substr($q, 0, 2) == '--' || $q == '') |
|
586 |
{ |
|
587 |
unset($schema[$k]); |
|
588 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
589 |
} |
|
590 |
else |
|
591 |
{ |
|
592 |
$schema[$k] = upg_assign_vars($schema[$k]); |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
foreach($query_list as $k => $q) |
|
597 |
{ |
|
598 |
$query_list[$k] = explode("\n", $query_list[$k]); |
|
599 |
foreach($query_list[$k] as $i => $s) |
|
600 |
{ |
|
601 |
$tq =& $query_list[$k][$i]; |
|
602 |
if(substr($s, 0, 2) == '--' || $s == '') |
|
603 |
{ |
|
604 |
unset($query_list[$k][$i]); |
|
605 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
606 |
} |
|
607 |
else |
|
608 |
{ |
|
609 |
$query_list[$k][$i] = upg_assign_vars($query_list[$k][$i]); |
|
610 |
} |
|
611 |
} |
|
612 |
$query_list[$k] = array_values($query_list[$k]); |
|
613 |
} |
|
614 |
||
615 |
$assoc_list = Array(); |
|
616 |
||
617 |
foreach($from_list as $i => $v) |
|
618 |
{ |
|
619 |
$assoc_list[$v] = $query_list[$i]; |
|
620 |
} |
|
621 |
||
622 |
$schema = array_values($schema); |
|
623 |
||
624 |
$deps_resolved = false; |
|
625 |
$installing_versions = Array($enano_version); |
|
626 |
||
627 |
while(true) |
|
628 |
{ |
|
629 |
$v = array_keys($deps_list); |
|
630 |
foreach($v as $i => $ver) |
|
631 |
{ |
|
632 |
if(in_array($ver, $installing_versions)) |
|
633 |
{ |
|
634 |
// $ver is on the list of versions to be installed. Add its dependencies to the list of versions to install. |
|
635 |
foreach($deps_list[$ver] as $dep) |
|
636 |
{ |
|
637 |
if(!in_array($dep, $installing_versions)) |
|
638 |
{ |
|
639 |
$installing_versions[] = $dep; |
|
640 |
} |
|
641 |
} |
|
642 |
} |
|
643 |
if($i == count($deps_list) - 1) |
|
644 |
{ |
|
645 |
break 2; |
|
646 |
} |
|
647 |
} |
|
648 |
} |
|
649 |
||
650 |
foreach($installing_versions as $this_ver) |
|
651 |
{ |
|
652 |
$schema = array_merge($schema, $assoc_list[$this_ver]); |
|
653 |
} |
|
654 |
||
655 |
// Time for some proper SQL syntax! |
|
656 |
// Also check queries for so-called injection attempts to make |
|
657 |
// sure that it doesn't fail during the upgrade process and |
|
658 |
// leave the user with a half-upgraded database |
|
659 |
foreach($schema as $s => $q) |
|
660 |
{ |
|
661 |
if(substr($q, strlen($q)-1, 1) != ';') |
|
662 |
{ |
|
663 |
$schema[$s] .= ';'; |
|
664 |
} |
|
665 |
if ( !$db->check_query($schema[$s]) ) |
|
666 |
{ |
|
667 |
// Uh-oh, the check failed, bail out |
|
668 |
// The DBAL runs sanity checks on all queries for safety, |
|
669 |
// so if the check fails in mid-upgrade we are in deep |
|
670 |
// dodo doo-doo. |
|
671 |
echo 'Query failed sanity check, this should never happen and is a bug.</p><p>Query was:</p><pre>'.$schema[$s].'</pre>'; |
|
672 |
break 2; |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
$schema = array_values($schema); |
|
677 |
||
678 |
// Used extensively for debugging |
|
679 |
// echo '<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'; |
|
680 |
// break; |
|
681 |
||
682 |
echo 'done!<br />Executing upgrade schema...'; |
|
683 |
||
684 |
// OK, do the loop, baby!!! |
|
685 |
foreach($schema as $q) |
|
686 |
{ |
|
687 |
$r = $db->sql_query($q); |
|
688 |
if(!$r) |
|
689 |
{ |
|
690 |
echo $db->get_error(); |
|
691 |
break 2; |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
// Call any custom functions |
|
696 |
foreach ( $installing_versions as $ver ) |
|
697 |
{ |
|
698 |
if ( isset($func_list[$ver]) ) |
|
699 |
{ |
|
700 |
foreach($func_list[$ver] as $function) |
|
701 |
{ |
|
702 |
@call_user_func($function); |
|
703 |
} |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
echo 'done!</p>'; |
|
708 |
echo '<p>You will be redirected shortly. If you aren\'t redirected, <a href="index.php">click here</a>.</p> |
|
709 |
<script type="text/javascript">setTimeout("window.location=\'index.php\'", 2000)</script>'; |
|
710 |
break; |
|
711 |
} |
|
712 |
$template->footer(); |
|
713 |
||
714 |
?> |