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