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