author | Dan |
Wed, 28 Nov 2007 15:24:23 -0500 | |
changeset 300 | c9e192a059c1 |
parent 297 | ee1fc84f12a8 |
child 304 | e2cb5f1432c8 |
child 306 | 8e898ab809b5 |
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 |
|
166
d53cc29308f4
Rebrand as 1.1.1; everything should now be bumped to "unstable" status
Dan
parents:
153
diff
changeset
|
5 |
* Version 1.1.1 |
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 |
||
289
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
16 |
define('IN_ENANO_INSTALL', 'true'); |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
17 |
define('IN_ENANO_UPGRADE', 'true'); |
0 | 18 |
|
19 |
if(!defined('scriptPath')) { |
|
20 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
21 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
22 |
define('scriptPath', $sp); |
|
23 |
} |
|
24 |
||
25 |
if(!defined('contentPath')) { |
|
26 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
27 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
28 |
define('contentPath', $sp); |
|
29 |
} |
|
30 |
||
289
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
31 |
global $this_page, $sideinfo; |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
32 |
|
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
33 |
function microtime_float() |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
34 |
{ |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
35 |
list($usec, $sec) = explode(" ", microtime()); |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
36 |
return ((float)$usec + (float)$sec); |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
37 |
} |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
38 |
|
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
39 |
global $_starttime; |
2b60c89dc27f
Fixed a few major bugs with the upgrade script and the config file not getting loaded properly due to IN_ENANO_INSTALL
Dan
parents:
272
diff
changeset
|
40 |
$_starttime = microtime_float(); |
0 | 41 |
|
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
|
42 |
// 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
|
43 |
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
|
44 |
{ |
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
|
45 |
$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
|
46 |
} |
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
|
47 |
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
|
48 |
{ |
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
|
49 |
$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
|
50 |
} |
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
|
51 |
|
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
|
52 |
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
|
53 |
|
0 | 54 |
require(ENANO_ROOT.'/includes/constants.php'); |
55 |
||
56 |
if(defined('ENANO_DEBUG')) |
|
57 |
{ |
|
58 |
require_once(ENANO_ROOT.'/includes/debugger/debugConsole.php'); |
|
59 |
} |
|
60 |
else |
|
61 |
{ |
|
62 |
function dc_here($m) { return false; } |
|
63 |
function dc_dump($a, $g) { return false; } |
|
64 |
function dc_watch($n) { return false; } |
|
65 |
function dc_start_timer($u) { return false; } |
|
66 |
function dc_stop_timer($m) { return false; } |
|
67 |
} |
|
68 |
||
69 |
// SCRIPT CONFIGURATION |
|
70 |
// Everything related to versions goes here! |
|
71 |
||
72 |
// Valid versions to upgrade from |
|
149 | 73 |
$valid_versions = Array('1.0b1', '1.0b2', '1.0b3', '1.0b4', '1.0RC1', '1.0RC2', '1.0RC3', '1.0', '1.0.1', '1.0.1.1', '1.0.2b1'); |
0 | 74 |
|
75 |
// 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
|
76 |
// If, for example, upgrading from 1.0b1 to 1.0RC1 requires one extra query that would not |
0 | 77 |
// normally be required (for whatever reason) then you would add a custom version number to the array under key '1.0b1'. |
78 |
$deps_list = Array( |
|
79 |
'1.0b1' => Array('1.0b2'), |
|
80 |
'1.0b2' => Array('1.0b3'), |
|
81 |
'1.0b3' => Array('1.0b4'), |
|
82 |
'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
|
83 |
'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
|
84 |
'1.0RC2' => Array('1.0RC3'), |
129
0b5244001799
Rebranded as 1.0.1.1; fixed category page drawing bug; updated link to GPL in the about page to the GPLv2
Dan
parents:
113
diff
changeset
|
85 |
'1.0RC3' => Array('1.0'), |
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
129
diff
changeset
|
86 |
'1.0' => Array('1.0.1'), |
149 | 87 |
'1.0.1' => Array('1.0.1.1'), |
88 |
'1.0.1.1' => Array('1.0.2b1') |
|
0 | 89 |
); |
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
129
diff
changeset
|
90 |
$this_version = '1.0.2'; |
0 | 91 |
$func_list = Array( |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
92 |
'1.0' => Array('u_1_0_1_update_del_votes'), |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
93 |
'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
|
94 |
// '1.0RC2' => Array('u_1_0_populate_userpage_comments') |
290
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
95 |
'1.0RC3' => Array('u_1_0_RC3_make_users_extra'), |
297
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
96 |
'1.0.2b1' => Array('u_1_0_2_nuke_template_cache', 'u_1_0_2_rebuild_search_index') |
0 | 97 |
); |
98 |
||
99 |
if(!isset($_GET['mode'])) |
|
100 |
{ |
|
101 |
$_GET['mode'] = 'login'; |
|
102 |
} |
|
103 |
||
104 |
function err($t) |
|
105 |
{ |
|
106 |
global $template; |
|
107 |
echo $t; |
|
108 |
$template->footer(); |
|
109 |
exit; |
|
110 |
} |
|
111 |
||
112 |
require(ENANO_ROOT.'/includes/template.php'); |
|
113 |
||
114 |
// Initialize the session manager |
|
115 |
require(ENANO_ROOT.'/includes/functions.php'); |
|
116 |
require(ENANO_ROOT.'/includes/dbal.php'); |
|
117 |
require(ENANO_ROOT.'/includes/paths.php'); |
|
118 |
require(ENANO_ROOT.'/includes/sessions.php'); |
|
119 |
require(ENANO_ROOT.'/includes/plugins.php'); |
|
120 |
require(ENANO_ROOT.'/includes/rijndael.php'); |
|
121 |
require(ENANO_ROOT.'/includes/render.php'); |
|
122 |
$db = new mysql(); |
|
123 |
$db->connect(); |
|
124 |
||
125 |
$plugins = new pluginLoader(); |
|
126 |
||
127 |
if(!defined('ENANO_CONFIG_FETCHED')) |
|
128 |
{ |
|
129 |
// Select and fetch the site configuration |
|
130 |
$e = $db->sql_query('SELECT config_name, config_value FROM '.table_prefix.'config;'); |
|
131 |
if ( !$e ) |
|
132 |
{ |
|
133 |
$db->_die('Some critical configuration information could not be selected.'); |
|
134 |
} |
|
135 |
else |
|
136 |
{ |
|
137 |
define('ENANO_CONFIG_FETCHED', ''); // Used in die_semicritical to figure out whether to call getConfig() or not |
|
138 |
} |
|
139 |
||
140 |
$enano_config = Array(); |
|
141 |
while($r = $db->fetchrow()) |
|
142 |
{ |
|
143 |
$enano_config[$r['config_name']] = $r['config_value']; |
|
144 |
} |
|
145 |
$db->free_result(); |
|
146 |
} |
|
147 |
||
148 |
$v = enano_version(); |
|
149 |
if(in_array($v, Array(false, '', '1.0b3', '1.0b4'))) |
|
150 |
{ |
|
151 |
$ul_admin = 2; |
|
152 |
$ul_mod = 1; |
|
153 |
$ul_member = 0; |
|
154 |
$ul_guest = -1; |
|
155 |
} |
|
156 |
else |
|
157 |
{ |
|
158 |
$ul_admin = USER_LEVEL_ADMIN; |
|
159 |
$ul_mod = USER_LEVEL_MOD; |
|
160 |
$ul_member = USER_LEVEL_MEMBER; |
|
161 |
$ul_guest = USER_LEVEL_GUEST; |
|
162 |
} |
|
163 |
||
164 |
$_GET['title'] = 'unset'; |
|
165 |
||
166 |
$session = new sessionManager(); |
|
167 |
$paths = new pathManager(); |
|
168 |
$session->start(); |
|
169 |
||
170 |
$template = new template_nodb(); |
|
171 |
$template->load_theme('oxygen', 'bleu', false); |
|
172 |
||
173 |
$modestrings = Array( |
|
174 |
'login' => 'Administrative login', |
|
175 |
'welcome' => 'Welcome', |
|
176 |
'setversion' => 'Select Enano version', |
|
177 |
'confirm' => 'Confirm upgrade', |
|
178 |
'upgrade' => 'Database installation', |
|
179 |
'finish' => 'Upgrade complete' |
|
180 |
); |
|
181 |
||
182 |
$sideinfo = ''; |
|
183 |
$vars = $template->extract_vars('elements.tpl'); |
|
184 |
$p = $template->makeParserText($vars['sidebar_button']); |
|
185 |
foreach ( $modestrings as $id => $str ) |
|
186 |
{ |
|
187 |
if ( $_GET['mode'] == $id ) |
|
188 |
{ |
|
189 |
$flags = 'style="font-weight: bold; text-decoration: underline;"'; |
|
190 |
$this_page = $str; |
|
191 |
} |
|
192 |
else |
|
193 |
{ |
|
194 |
$flags = ''; |
|
195 |
} |
|
196 |
$p->assign_vars(Array( |
|
197 |
'HREF' => '#', |
|
198 |
'FLAGS' => $flags . ' onclick="return false;"', |
|
199 |
'TEXT' => $str |
|
200 |
)); |
|
201 |
$sideinfo .= $p->run(); |
|
202 |
} |
|
203 |
||
204 |
$template->init_vars(); |
|
205 |
||
206 |
function upg_assign_vars($schema) |
|
207 |
{ |
|
208 |
$schema = str_replace('{{SITE_NAME}}', mysql_real_escape_string(getConfig('site_name')), $schema); |
|
209 |
$schema = str_replace('{{SITE_DESC}}', mysql_real_escape_string(getConfig('site_desc')), $schema); |
|
210 |
$schema = str_replace('{{COPYRIGHT}}', mysql_real_escape_string(getConfig('copyright_notice')), $schema); |
|
211 |
$schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema); |
|
212 |
if(getConfig('wiki_mode')=='1') $schema = str_replace('{{WIKI_MODE}}', '1', $schema); |
|
213 |
else $schema = str_replace('{{WIKI_MODE}}', '0', $schema); |
|
214 |
return $schema; |
|
215 |
} |
|
216 |
||
217 |
/* Version-specific functions */ |
|
218 |
||
219 |
function u_1_0_RC1_update_user_ids() |
|
220 |
{ |
|
221 |
global $db; |
|
222 |
// First, make sure this hasn't already been done |
|
223 |
$q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE user_id=1;'); |
|
224 |
if ( !$q ) |
|
225 |
$db->_die(); |
|
226 |
$row = $db->fetchrow(); |
|
227 |
if ( $row['username'] == 'Anonymous' ) |
|
228 |
return true; |
|
229 |
// Find the first unused user ID |
|
230 |
$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
|
231 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users;'); |
0 | 232 |
if ( !$q ) |
233 |
$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
|
234 |
$notfirst = false; |
0 | 235 |
while ( $row = $db->fetchrow() ) |
236 |
{ |
|
237 |
$i = intval($row['user_id']); |
|
238 |
$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
|
239 |
if ( !isset($used[$i - 1]) && $notfirst ) |
0 | 240 |
{ |
241 |
$id = $i - 1; |
|
242 |
break; |
|
243 |
} |
|
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
|
244 |
$notfirst = true; |
0 | 245 |
} |
246 |
if ( !isset($id) ) |
|
247 |
$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
|
248 |
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
|
249 |
$id = 2; |
0 | 250 |
$db->free_result(); |
251 |
||
252 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=' . $id . ' WHERE user_id=1;'); |
|
253 |
if(!$q) |
|
254 |
$db->_die(); |
|
255 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=1 WHERE user_id=-1 AND username=\'Anonymous\';'); |
|
256 |
if(!$q) |
|
257 |
$db->_die(); |
|
258 |
||
259 |
} |
|
260 |
||
261 |
function u_1_0_RC1_add_admins_to_group() |
|
262 |
{ |
|
263 |
global $db; |
|
264 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_level=' . USER_LEVEL_ADMIN . ';'); |
|
265 |
if ( !$q ) |
|
266 |
$db->_die(); |
|
267 |
$base = 'INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES'; |
|
268 |
$blocks = Array(); |
|
269 |
while ( $row = $db->fetchrow($q) ) |
|
270 |
{ |
|
271 |
$blocks[] = '(2,' . $row['user_id'] . ')'; |
|
272 |
} |
|
273 |
$blocks = implode(',', $blocks); |
|
274 |
$sql = $base . $blocks . ';'; |
|
275 |
if(!$db->sql_query($sql)) |
|
276 |
$db->_die(); |
|
277 |
} |
|
278 |
||
279 |
function u_1_0_RC1_alter_files_table() |
|
280 |
{ |
|
281 |
global $db; |
|
282 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
283 |
@mkdir(ENANO_ROOT . '/files'); |
|
284 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
285 |
die('ERROR: Couldn\'t create files directory'); |
|
286 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
287 |
if(!$q) $db->_die(); |
|
288 |
while ( $row = $db->fetchrow() ) |
|
289 |
{ |
|
290 |
$file_data = base64_decode($row['data']); |
|
291 |
$path = ENANO_ROOT . '/files/' . md5( $row['filename'] . '_' . $file_data ) . '_' . $row['time_id'] . $row['file_extension']; |
|
292 |
@unlink($path); |
|
293 |
$handle = @fopen($path, 'w'); |
|
294 |
if(!$handle) |
|
295 |
die('fopen failed'); |
|
296 |
fwrite($handle, $file_data); |
|
297 |
fclose($handle); |
|
298 |
||
299 |
} |
|
300 |
||
301 |
$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;'); |
|
302 |
if(!$q) $db->_die(); |
|
303 |
||
304 |
$list = Array(); |
|
305 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
306 |
if(!$q) $db->_die(); |
|
307 |
while ( $row = $db->fetchrow($q) ) |
|
308 |
{ |
|
309 |
$file_data = base64_decode($row['data']); |
|
310 |
$key = md5( $row['filename'] . '_' . $file_data ); |
|
311 |
$list[] = 'UPDATE '.table_prefix.'files SET file_key=\'' . $key . '\' WHERE file_id=' . $row['file_id'] . ';'; |
|
312 |
} |
|
313 |
||
314 |
foreach ( $list as $sql ) |
|
315 |
{ |
|
316 |
if(!$db->sql_query($sql)) $db->_die(); |
|
317 |
} |
|
318 |
||
319 |
if(!$db->sql_query('ALTER TABLE '.table_prefix.'files DROP data')) $db->_die(); |
|
320 |
||
321 |
} |
|
322 |
||
323 |
function u_1_0_RC1_destroy_session_cookie() |
|
324 |
{ |
|
325 |
unset($_COOKIE['sid']); |
|
326 |
setcookie('sid', '', time()-3600*24, scriptPath); |
|
327 |
setcookie('sid', '', time()-3600*24, scriptPath.'/'); |
|
328 |
} |
|
329 |
||
330 |
function u_1_0_RC1_set_contact_email() |
|
331 |
{ |
|
332 |
global $db; |
|
333 |
$q = $db->sql_query('SELECT email FROM '.table_prefix.'users WHERE user_level='.USER_LEVEL_ADMIN.' ORDER BY user_level ASC LIMIT 1;'); |
|
334 |
if(!$q) |
|
335 |
$db->_die(); |
|
336 |
$row = $db->fetchrow(); |
|
337 |
setConfig('contact_email', $row['email']); |
|
338 |
} |
|
339 |
||
340 |
function u_1_0_RC1_update_page_text() |
|
341 |
{ |
|
342 |
global $db; |
|
343 |
$q = $db->sql_unbuffered_query('SELECT page_id,namespace,page_text,char_tag FROM '.table_prefix.'page_text'); |
|
344 |
if (!$q) |
|
345 |
$db->_die(); |
|
346 |
||
347 |
$qs = array(); |
|
348 |
||
349 |
while ( $row = $db->fetchrow($q) ) |
|
350 |
{ |
|
351 |
$row['page_text'] = str_replace(Array( |
|
352 |
"{QUOT:{$row['char_tag']}}", |
|
353 |
"{APOS:{$row['char_tag']}}", |
|
354 |
"{SLASH:{$row['char_tag']}}" |
|
355 |
), Array( |
|
356 |
'"', "'", '\\' |
|
357 |
), $row['page_text']); |
|
358 |
$qs[] = 'UPDATE '.table_prefix.'page_text SET page_text=\'' . mysql_real_escape_string($row['page_text']) . '\' |
|
359 |
WHERE page_id=\'' . mysql_real_escape_string($row['page_id']) . '\' AND |
|
360 |
namespace=\'' . mysql_real_escape_string($row['namespace']) . '\';'; |
|
361 |
} |
|
362 |
||
363 |
foreach($qs as $query) |
|
364 |
{ |
|
365 |
if(!$db->sql_query($query)) |
|
366 |
$db->_die(); |
|
367 |
} |
|
368 |
} |
|
369 |
||
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
370 |
function u_1_0_1_update_del_votes() |
0 | 371 |
{ |
372 |
global $db; |
|
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
373 |
$q = $db->sql_query('SELECT urlname, namespace, delvote_ips FROM '.table_prefix.'pages;'); |
0 | 374 |
if ( !$q ) |
375 |
$db->_die(); |
|
376 |
||
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
377 |
while ( $row = $db->fetchrow($q) ) |
0 | 378 |
{ |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
379 |
$ips = strval($row['delvote_ips']); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
380 |
if ( is_array( @unserialize($ips) ) ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
381 |
continue; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
382 |
$ips = explode('|', $ips); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
383 |
$new = array( |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
384 |
'ip' => array(), |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
385 |
'u' => array() |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
386 |
); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
387 |
$i = 0; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
388 |
$prev = ''; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
389 |
$prev_is_ip = false; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
390 |
foreach ( $ips as $ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
391 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
392 |
$i++; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
393 |
$current_is_ip = is_valid_ip($ip); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
394 |
if ( $current_is_ip && $prev_is_ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
395 |
{ |
113
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
396 |
$i++; |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
397 |
$new['u'][] = $prev; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
398 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
399 |
if ( $current_is_ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
400 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
401 |
$new['ip'][] = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
402 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
403 |
else |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
404 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
405 |
$new['u'][] = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
406 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
407 |
$prev = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
408 |
$prev_is_ip = $current_is_ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
409 |
} |
113
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
410 |
if ( $i % 2 == 1 && $prev_is_ip ) |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
411 |
{ |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
412 |
$new['u'][] = $ip; |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
413 |
} |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
414 |
$new = serialize($new); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
415 |
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET delvote_ips=\'' . $db->escape($new) . '\' WHERE urlname=\'' . $db->escape($row['urlname']) . '\' AND namespace=\'' . $db->escape($row['namespace']) . '\';'); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
416 |
if ( !$e ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
417 |
$db->_die(); |
0 | 418 |
} |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
419 |
$db->free_result($q); |
0 | 420 |
} |
421 |
||
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
422 |
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
|
423 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
424 |
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
|
425 |
$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
|
426 |
if ( !$q ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
427 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
428 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
429 |
$ids = array(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
430 |
while ( $row = $db->fetchrow() ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
431 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
432 |
$ids[] = intval($row['user_id']); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
433 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
434 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
435 |
$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
|
436 |
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
|
437 |
return false; |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
438 |
$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
|
439 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
440 |
if ( !$db->sql_query($sql) ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
441 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
442 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
443 |
|
290
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
444 |
function u_1_0_2_nuke_template_cache() |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
445 |
{ |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
446 |
$dir = @opendir(ENANO_ROOT . '/cache'); |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
447 |
if ( !$dir ) |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
448 |
{ |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
449 |
return false; |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
450 |
} |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
451 |
while ( ($fname = @readdir($dir)) ) |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
452 |
{ |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
453 |
if ( preg_match('/\.tpl\.php$/', $fname) ) |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
454 |
{ |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
455 |
unlink( ENANO_ROOT . '/cache/' . $fname ); |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
456 |
} |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
457 |
} |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
458 |
} |
1201c9412cb6
The template-cache incompatibility bug has finally been isolated, so a function to clear the template cache was added into the upgrade script for 1.0.2
Dan
parents:
289
diff
changeset
|
459 |
|
297
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
460 |
function u_1_0_2_rebuild_search_index() |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
461 |
{ |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
462 |
global $paths; |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
463 |
@set_time_limit(0); |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
464 |
$paths->rebuild_search_index(); |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
465 |
} |
ee1fc84f12a8
SECURITY: Tighten default allowed file types; make sure search index rebuild is performed on upgrade
Dan
parents:
290
diff
changeset
|
466 |
|
0 | 467 |
switch($_GET['mode']) |
468 |
{ |
|
469 |
case "login": |
|
110 | 470 |
if ( $session->user_logged_in && $session->user_level < $ul_admin ) |
471 |
{ |
|
472 |
$template->header(); |
|
473 |
echo '<p>Your user account does not have permission to perform an upgrade of Enano. Return to the <a href="index.php">index page</a>.</p>'; |
|
474 |
$template->footer(); |
|
475 |
exit; |
|
476 |
} |
|
0 | 477 |
if($session->user_logged_in && $session->user_level >= $ul_admin) |
478 |
{ |
|
479 |
if(isset($_POST['login'])) |
|
480 |
{ |
|
481 |
$session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_admin); |
|
482 |
if($session->sid_super) |
|
483 |
{ |
|
484 |
header('Location: upgrade.php?mode=welcome&auth='.$session->sid_super); |
|
485 |
exit; |
|
486 |
} |
|
487 |
} |
|
488 |
$template->header(); |
|
489 |
?> |
|
490 |
<form action="upgrade.php?mode=login" method="post"> |
|
491 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
492 |
<tr> |
|
493 |
<th colspan="2">You must re-authenticate to perform this upgrade.</th> |
|
494 |
</tr> |
|
495 |
<?php |
|
496 |
if(isset($_POST['login'])) |
|
497 |
{ |
|
498 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
499 |
} |
|
500 |
?> |
|
501 |
<tr> |
|
502 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
503 |
</tr> |
|
504 |
<tr> |
|
505 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
506 |
</tr> |
|
507 |
<tr> |
|
508 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
509 |
</tr> |
|
510 |
</table> |
|
511 |
</form> |
|
512 |
<?php |
|
513 |
} |
|
514 |
else |
|
515 |
{ |
|
516 |
if(isset($_POST['login'])) |
|
517 |
{ |
|
518 |
$result = $session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_member); |
|
519 |
if($result == 'success') |
|
520 |
{ |
|
521 |
header('Location: upgrade.php'); |
|
522 |
exit; |
|
523 |
} |
|
524 |
} |
|
525 |
$template->header(); |
|
526 |
?> |
|
527 |
<form action="upgrade.php?mode=login" method="post"> |
|
528 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
529 |
<tr> |
|
530 |
<th colspan="2">Please log in to continue with this upgrade.</th> |
|
531 |
</tr> |
|
532 |
<?php |
|
533 |
if(isset($_POST['login'])) |
|
534 |
{ |
|
535 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
536 |
} |
|
537 |
?> |
|
538 |
<tr> |
|
539 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
540 |
</tr> |
|
541 |
<tr> |
|
542 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
543 |
</tr> |
|
544 |
<tr> |
|
545 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
546 |
</tr> |
|
547 |
</table> |
|
548 |
</form> |
|
549 |
<?php |
|
550 |
} |
|
551 |
break; |
|
552 |
case "welcome": |
|
553 |
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; } |
|
554 |
||
555 |
// Just show a simple welcome page to display version information |
|
556 |
$template->header(); |
|
557 |
require('config.php'); |
|
558 |
||
559 |
?> |
|
560 |
||
561 |
<div style="text-align: center; margin-top: 10px;"> |
|
562 |
<img alt="[ Enano CMS Project logo ]" src="images/enano-artwork/installer-greeting-blue.png" style="display: block; margin: 0 auto; padding-left: 134px;" /> |
|
563 |
<h2>Welcome to the Enano upgrade wizard</h2> |
|
564 |
<?php |
|
565 |
if ( file_exists('./_nightly.php') ) |
|
566 |
{ |
|
567 |
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>'; |
|
568 |
} |
|
569 |
?> |
|
570 |
</div> |
|
571 |
<div style="display: table; margin: 0 auto;"> |
|
572 |
<p>You are about to upgrade Enano to version <b><?php echo $this_version; ?></b>. Before you continue, please ensure that:</p> |
|
573 |
<ul> |
|
574 |
<li>You have completely backed up your database (<b><?php echo "$dbhost:$dbname"; ?></b>)</li> |
|
575 |
<li>You have backed up the entire Enano directory (<b><?php echo ENANO_ROOT; ?></b>)</li> |
|
576 |
<li>You have reviewed the release notes for this version, and you<br />are comfortable with any known bugs or issues</li> |
|
91 | 577 |
<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 | 578 |
</ul> |
579 |
</div> |
|
580 |
<div style="text-align: center; margin-top: 10px;"> |
|
581 |
<form action="upgrade.php?mode=setversion&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
582 |
<input type="submit" value="Continue with upgrade" /> |
|
583 |
</form> |
|
584 |
</div> |
|
585 |
||
586 |
<?php |
|
587 |
||
588 |
break; |
|
589 |
case "setversion": |
|
590 |
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; } |
|
591 |
$v = ( function_exists('enano_version') ) ? enano_version() : ''; |
|
592 |
if(!in_array($v, $valid_versions) && $v != '') |
|
593 |
{ |
|
594 |
$template->header(); |
|
595 |
?> |
|
596 |
<p>Your version of Enano (<?php echo $v; ?>) can't be upgraded to this version (<?php echo $this_version; ?>).</p> |
|
597 |
<?php |
|
598 |
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
|
599 |
} |
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
|
600 |
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
|
601 |
{ |
0 | 602 |
// OK, we don't know which version he's running. So we'll cheat ;-) |
603 |
$template->header(); |
|
604 |
echo "<form action='upgrade.php?mode=confirm&auth={$session->sid_super}' method='post'>"; |
|
605 |
?> |
|
606 |
<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> |
|
607 |
<p><select name="version"><?php |
|
608 |
foreach($valid_versions as $c) |
|
609 |
{ |
|
610 |
echo "<option value='{$c}'>{$c}</option>"; |
|
611 |
} |
|
612 |
?></select></p> |
|
613 |
<p> |
|
614 |
<input type="submit" value="Continue" /> |
|
615 |
</p> |
|
616 |
<?php |
|
617 |
echo `</form>`; |
|
618 |
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
|
619 |
} |
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
|
620 |
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
|
621 |
{ |
0 | 622 |
header('Location: upgrade.php?mode=confirm&auth='.$session->sid_super); |
623 |
} |
|
624 |
break; |
|
625 |
case "confirm": |
|
626 |
$enano_version = ( isset($_POST['version']) ) ? $_POST['version'] : enano_version(); |
|
627 |
||
628 |
$template->header(); |
|
629 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
630 |
?> |
|
631 |
<form action="upgrade.php?mode=upgrade&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
632 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
633 |
<tr> |
|
634 |
<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> |
|
635 |
</tr> |
|
636 |
<tr> |
|
637 |
<td colspan="2" style="text-align: center;"> |
|
638 |
<input type="hidden" name="enano_version" value="<?php echo $enano_version; ?>" /> |
|
639 |
<input type="submit" name="doit" value="Upgrade Enano!" /> |
|
640 |
</td> |
|
641 |
</tr> |
|
642 |
</table> |
|
643 |
</form> |
|
644 |
<?php |
|
645 |
break; |
|
646 |
case "upgrade": |
|
647 |
$template->header(); |
|
648 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
649 |
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; } |
|
650 |
$enano_version = $_POST['enano_version']; |
|
651 |
echo '<p>Preparing for schema execution...'; |
|
652 |
// Build an array of queries |
|
653 |
$schema = file_get_contents('upgrade.sql'); |
|
654 |
||
655 |
// Strip out and process version blocks |
|
149 | 656 |
preg_match_all('#---BEGIN ([0-9A-z\.\-]*?)---'."\n".'((.*?)'."\n)?".'---END \\1---#is', $schema, $matches); |
0 | 657 |
|
658 |
$from_list =& $matches[1]; |
|
149 | 659 |
$query_list =& $matches[3]; |
0 | 660 |
|
661 |
foreach($matches[0] as $m) |
|
662 |
{ |
|
663 |
$schema = str_replace($m, '', $schema); |
|
664 |
} |
|
665 |
$schema = explode("\n", $schema); |
|
666 |
foreach($schema as $k => $q) |
|
667 |
{ |
|
668 |
if(substr($q, 0, 2) == '--' || $q == '') |
|
669 |
{ |
|
670 |
unset($schema[$k]); |
|
671 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
672 |
} |
|
673 |
else |
|
674 |
{ |
|
675 |
$schema[$k] = upg_assign_vars($schema[$k]); |
|
676 |
} |
|
677 |
} |
|
678 |
||
679 |
foreach($query_list as $k => $q) |
|
680 |
{ |
|
681 |
$query_list[$k] = explode("\n", $query_list[$k]); |
|
682 |
foreach($query_list[$k] as $i => $s) |
|
683 |
{ |
|
684 |
$tq =& $query_list[$k][$i]; |
|
685 |
if(substr($s, 0, 2) == '--' || $s == '') |
|
686 |
{ |
|
687 |
unset($query_list[$k][$i]); |
|
688 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
689 |
} |
|
690 |
else |
|
691 |
{ |
|
692 |
$query_list[$k][$i] = upg_assign_vars($query_list[$k][$i]); |
|
693 |
} |
|
694 |
} |
|
695 |
$query_list[$k] = array_values($query_list[$k]); |
|
696 |
} |
|
697 |
||
698 |
$assoc_list = Array(); |
|
699 |
||
700 |
foreach($from_list as $i => $v) |
|
701 |
{ |
|
702 |
$assoc_list[$v] = $query_list[$i]; |
|
703 |
} |
|
704 |
||
705 |
$schema = array_values($schema); |
|
706 |
||
707 |
$deps_resolved = false; |
|
708 |
$installing_versions = Array($enano_version); |
|
709 |
||
710 |
while(true) |
|
711 |
{ |
|
712 |
$v = array_keys($deps_list); |
|
713 |
foreach($v as $i => $ver) |
|
714 |
{ |
|
715 |
if(in_array($ver, $installing_versions)) |
|
716 |
{ |
|
717 |
// $ver is on the list of versions to be installed. Add its dependencies to the list of versions to install. |
|
718 |
foreach($deps_list[$ver] as $dep) |
|
719 |
{ |
|
720 |
if(!in_array($dep, $installing_versions)) |
|
721 |
{ |
|
722 |
$installing_versions[] = $dep; |
|
723 |
} |
|
724 |
} |
|
725 |
} |
|
726 |
if($i == count($deps_list) - 1) |
|
727 |
{ |
|
728 |
break 2; |
|
729 |
} |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
foreach($installing_versions as $this_ver) |
|
734 |
{ |
|
735 |
$schema = array_merge($schema, $assoc_list[$this_ver]); |
|
736 |
} |
|
737 |
||
738 |
// Time for some proper SQL syntax! |
|
739 |
// Also check queries for so-called injection attempts to make |
|
740 |
// sure that it doesn't fail during the upgrade process and |
|
741 |
// leave the user with a half-upgraded database |
|
742 |
foreach($schema as $s => $q) |
|
743 |
{ |
|
744 |
if(substr($q, strlen($q)-1, 1) != ';') |
|
745 |
{ |
|
746 |
$schema[$s] .= ';'; |
|
747 |
} |
|
748 |
if ( !$db->check_query($schema[$s]) ) |
|
749 |
{ |
|
750 |
// Uh-oh, the check failed, bail out |
|
751 |
// The DBAL runs sanity checks on all queries for safety, |
|
752 |
// so if the check fails in mid-upgrade we are in deep |
|
753 |
// dodo doo-doo. |
|
754 |
echo 'Query failed sanity check, this should never happen and is a bug.</p><p>Query was:</p><pre>'.$schema[$s].'</pre>'; |
|
755 |
break 2; |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
$schema = array_values($schema); |
|
760 |
||
761 |
// Used extensively for debugging |
|
762 |
// echo '<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'; |
|
763 |
// break; |
|
764 |
||
765 |
echo 'done!<br />Executing upgrade schema...'; |
|
766 |
||
767 |
// OK, do the loop, baby!!! |
|
768 |
foreach($schema as $q) |
|
769 |
{ |
|
272
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
770 |
if ( substr($q, 0, 1) == '@' ) |
0 | 771 |
{ |
272
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
772 |
// if the first character is @, don't fail on error |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
773 |
$db->sql_query(substr($q, 1)); |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
774 |
} |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
775 |
else |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
776 |
{ |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
777 |
if ( !$db->sql_query($q) ) |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
778 |
{ |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
779 |
echo $db->get_error(); |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
780 |
break 2; |
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents:
196
diff
changeset
|
781 |
} |
0 | 782 |
} |
783 |
} |
|
784 |
||
785 |
// Call any custom functions |
|
786 |
foreach ( $installing_versions as $ver ) |
|
787 |
{ |
|
788 |
if ( isset($func_list[$ver]) ) |
|
789 |
{ |
|
790 |
foreach($func_list[$ver] as $function) |
|
791 |
{ |
|
792 |
@call_user_func($function); |
|
793 |
} |
|
794 |
} |
|
795 |
} |
|
796 |
||
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
73
diff
changeset
|
797 |
// Log the upgrade |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
73
diff
changeset
|
798 |
$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
|
799 |
|
0 | 800 |
echo 'done!</p>'; |
801 |
echo '<p>You will be redirected shortly. If you aren\'t redirected, <a href="index.php">click here</a>.</p> |
|
802 |
<script type="text/javascript">setTimeout("window.location=\'index.php\'", 2000)</script>'; |
|
803 |
break; |
|
804 |
} |
|
805 |
$template->footer(); |
|
806 |
||
807 |
?> |