Wordpress 3.0.6
[autoinstalls/wordpress.git] / wp-admin / includes / update-core.php
1 <?php
2 /**
3  * WordPress core upgrade functionality.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 2.7.0
8  */
9
10 /**
11  * Stores files to be deleted.
12  *
13  * @since 2.7.0
14  * @global array $_old_files
15  * @var array
16  * @name $_old_files
17  */
18 global $_old_files;
19
20 $_old_files = array(
21 'wp-admin/bookmarklet.php',
22 'wp-admin/css/upload.css',
23 'wp-admin/css/upload-rtl.css',
24 'wp-admin/css/press-this-ie.css',
25 'wp-admin/css/press-this-ie-rtl.css',
26 'wp-admin/edit-form.php',
27 'wp-admin/link-import.php',
28 'wp-admin/images/box-bg-left.gif',
29 'wp-admin/images/box-bg-right.gif',
30 'wp-admin/images/box-bg.gif',
31 'wp-admin/images/box-butt-left.gif',
32 'wp-admin/images/box-butt-right.gif',
33 'wp-admin/images/box-butt.gif',
34 'wp-admin/images/box-head-left.gif',
35 'wp-admin/images/box-head-right.gif',
36 'wp-admin/images/box-head.gif',
37 'wp-admin/images/heading-bg.gif',
38 'wp-admin/images/login-bkg-bottom.gif',
39 'wp-admin/images/login-bkg-tile.gif',
40 'wp-admin/images/notice.gif',
41 'wp-admin/images/toggle.gif',
42 'wp-admin/images/comment-stalk-classic.gif',
43 'wp-admin/images/comment-stalk-fresh.gif',
44 'wp-admin/images/comment-stalk-rtl.gif',
45 'wp-admin/images/comment-pill.gif',
46 'wp-admin/images/del.png',
47 'wp-admin/images/media-button-gallery.gif',
48 'wp-admin/images/media-buttons.gif',
49 'wp-admin/images/tail.gif',
50 'wp-admin/images/gear.png',
51 'wp-admin/images/tab.png',
52 'wp-admin/images/postbox-bg.gif',
53 'wp-admin/includes/upload.php',
54 'wp-admin/js/dbx-admin-key.js',
55 'wp-admin/js/link-cat.js',
56 'wp-admin/js/forms.js',
57 'wp-admin/js/upload.js',
58 'wp-admin/js/set-post-thumbnail-handler.js',
59 'wp-admin/js/set-post-thumbnail-handler.dev.js',
60 'wp-admin/js/page.js',
61 'wp-admin/js/page.dev.js',
62 'wp-admin/js/slug.js',
63 'wp-admin/js/slug.dev.js',
64 'wp-admin/profile-update.php',
65 'wp-admin/templates.php',
66 'wp-includes/images/audio.png',
67 'wp-includes/images/css.png',
68 'wp-includes/images/default.png',
69 'wp-includes/images/doc.png',
70 'wp-includes/images/exe.png',
71 'wp-includes/images/html.png',
72 'wp-includes/images/js.png',
73 'wp-includes/images/pdf.png',
74 'wp-includes/images/swf.png',
75 'wp-includes/images/tar.png',
76 'wp-includes/images/text.png',
77 'wp-includes/images/video.png',
78 'wp-includes/images/zip.png',
79 'wp-includes/js/dbx.js',
80 'wp-includes/js/fat.js',
81 'wp-includes/js/list-manipulation.js',
82 'wp-includes/js/jquery/jquery.dimensions.min.js',
83 'wp-includes/js/tinymce/langs/en.js',
84 'wp-includes/js/tinymce/plugins/autosave/editor_plugin_src.js',
85 'wp-includes/js/tinymce/plugins/autosave/langs',
86 'wp-includes/js/tinymce/plugins/directionality/images',
87 'wp-includes/js/tinymce/plugins/directionality/langs',
88 'wp-includes/js/tinymce/plugins/inlinepopups/css',
89 'wp-includes/js/tinymce/plugins/inlinepopups/images',
90 'wp-includes/js/tinymce/plugins/inlinepopups/jscripts',
91 'wp-includes/js/tinymce/plugins/paste/images',
92 'wp-includes/js/tinymce/plugins/paste/jscripts',
93 'wp-includes/js/tinymce/plugins/paste/langs',
94 'wp-includes/js/tinymce/plugins/spellchecker/classes/HttpClient.class.php',
95 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php',
96 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspell.class.php',
97 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspellShell.class.php',
98 'wp-includes/js/tinymce/plugins/spellchecker/css/spellchecker.css',
99 'wp-includes/js/tinymce/plugins/spellchecker/images',
100 'wp-includes/js/tinymce/plugins/spellchecker/langs',
101 'wp-includes/js/tinymce/plugins/spellchecker/tinyspell.php',
102 'wp-includes/js/tinymce/plugins/wordpress/images',
103 'wp-includes/js/tinymce/plugins/wordpress/langs',
104 'wp-includes/js/tinymce/plugins/wordpress/popups.css',
105 'wp-includes/js/tinymce/plugins/wordpress/wordpress.css',
106 'wp-includes/js/tinymce/plugins/wphelp',
107 'wp-includes/js/tinymce/themes/advanced/css',
108 'wp-includes/js/tinymce/themes/advanced/images',
109 'wp-includes/js/tinymce/themes/advanced/jscripts',
110 'wp-includes/js/tinymce/themes/advanced/langs',
111 'wp-includes/js/tinymce/tiny_mce_gzip.php',
112 'wp-includes/js/wp-ajax.js',
113 'wp-admin/admin-db.php',
114 'wp-admin/cat.js',
115 'wp-admin/categories.js',
116 'wp-admin/custom-fields.js',
117 'wp-admin/dbx-admin-key.js',
118 'wp-admin/edit-comments.js',
119 'wp-admin/install-rtl.css',
120 'wp-admin/install.css',
121 'wp-admin/upgrade-schema.php',
122 'wp-admin/upload-functions.php',
123 'wp-admin/upload-rtl.css',
124 'wp-admin/upload.css',
125 'wp-admin/upload.js',
126 'wp-admin/users.js',
127 'wp-admin/widgets-rtl.css',
128 'wp-admin/widgets.css',
129 'wp-admin/xfn.js',
130 'wp-includes/js/tinymce/license.html',
131 'wp-admin/cat-js.php',
132 'wp-admin/edit-form-ajax-cat.php',
133 'wp-admin/execute-pings.php',
134 'wp-admin/import/b2.php',
135 'wp-admin/import/btt.php',
136 'wp-admin/import/jkw.php',
137 'wp-admin/inline-uploading.php',
138 'wp-admin/link-categories.php',
139 'wp-admin/list-manipulation.js',
140 'wp-admin/list-manipulation.php',
141 'wp-includes/comment-functions.php',
142 'wp-includes/feed-functions.php',
143 'wp-includes/functions-compat.php',
144 'wp-includes/functions-formatting.php',
145 'wp-includes/functions-post.php',
146 'wp-includes/js/dbx-key.js',
147 'wp-includes/js/tinymce/plugins/autosave/langs/cs.js',
148 'wp-includes/js/tinymce/plugins/autosave/langs/sv.js',
149 'wp-includes/js/tinymce/themes/advanced/editor_template_src.js',
150 'wp-includes/links.php',
151 'wp-includes/pluggable-functions.php',
152 'wp-includes/template-functions-author.php',
153 'wp-includes/template-functions-category.php',
154 'wp-includes/template-functions-general.php',
155 'wp-includes/template-functions-links.php',
156 'wp-includes/template-functions-post.php',
157 'wp-includes/wp-l10n.php',
158 'wp-admin/import-b2.php',
159 'wp-admin/import-blogger.php',
160 'wp-admin/import-greymatter.php',
161 'wp-admin/import-livejournal.php',
162 'wp-admin/import-mt.php',
163 'wp-admin/import-rss.php',
164 'wp-admin/import-textpattern.php',
165 'wp-admin/quicktags.js',
166 'wp-images/fade-butt.png',
167 'wp-images/get-firefox.png',
168 'wp-images/header-shadow.png',
169 'wp-images/smilies',
170 'wp-images/wp-small.png',
171 'wp-images/wpminilogo.png',
172 'wp.php',
173 'wp-includes/gettext.php',
174 'wp-includes/streams.php',
175 // MU
176 'wp-admin/wpmu-admin.php',
177 'wp-admin/wpmu-blogs.php',
178 'wp-admin/wpmu-edit.php',
179 'wp-admin/wpmu-options.php',
180 'wp-admin/wpmu-themes.php',
181 'wp-admin/wpmu-upgrade-site.php',
182 'wp-admin/wpmu-users.php',
183 'wp-includes/wpmu-default-filters.php',
184 'wp-includes/wpmu-functions.php',
185 'wpmu-settings.php',
186 'index-install.php',
187 'README.txt',
188 'htaccess.dist',
189 'wp-admin/css/mu-rtl.css',
190 'wp-admin/css/mu.css',
191 'wp-admin/images/site-admin.png',
192 'wp-admin/includes/mu.php',
193 'wp-includes/images/wordpress-mu.png',
194 // 3.0
195 'wp-admin/categories.php',
196 'wp-admin/edit-category-form.php',
197 'wp-admin/edit-page-form.php',
198 'wp-admin/edit-pages.php',
199 'wp-admin/images/wp-logo.gif',
200 'wp-admin/js/wp-gears.dev.js',
201 'wp-admin/js/wp-gears.js',
202 'wp-admin/options-misc.php',
203 'wp-admin/page-new.php',
204 'wp-admin/page.php',
205 'wp-admin/rtl.css',
206 'wp-admin/rtl.dev.css',
207 'wp-admin/update-links.php',
208 'wp-admin/wp-admin.css',
209 'wp-admin/wp-admin.dev.css',
210 'wp-includes/js/codepress',
211 'wp-includes/js/jquery/autocomplete.dev.js',
212 'wp-includes/js/jquery/interface.js',
213 'wp-includes/js/jquery/autocomplete.js',
214 'wp-includes/js/scriptaculous/prototype.js',
215 'wp-includes/js/tinymce/wp-tinymce.js',
216 'wp-content/themes/twentyten/searchform.php',
217 'wp-admin/import',
218 'wp-admin/images/ico-edit.png',
219 'wp-admin/images/fav-top.png',
220 'wp-admin/images/ico-close.png',
221 'wp-admin/images/admin-header-footer.png',
222 'wp-admin/images/screen-options-left.gif',
223 'wp-admin/images/ico-add.png',
224 'wp-admin/images/browse-happy.gif',
225 'wp-admin/images/ico-viewpage.png',
226 );
227
228 /**
229  * Upgrade the core of WordPress.
230  *
231  * This will create a .maintenance file at the base of the WordPress directory
232  * to ensure that people can not access the web site, when the files are being
233  * copied to their locations.
234  *
235  * The files in the {@link $_old_files} list will be removed and the new files
236  * copied from the zip file after the database is upgraded.
237  *
238  * The steps for the upgrader for after the new release is downloaded and
239  * unzipped is:
240  *   1. Test unzipped location for select files to ensure that unzipped worked.
241  *   2. Create the .maintenance file in current WordPress base.
242  *   3. Copy new WordPress directory over old WordPress files.
243  *   4. Upgrade WordPress to new version.
244  *   5. Delete new WordPress directory path.
245  *   6. Delete .maintenance file.
246  *   7. Remove old files.
247  *   8. Delete 'update_core' option.
248  *
249  * There are several areas of failure. For instance if PHP times out before step
250  * 6, then you will not be able to access any portion of your site. Also, since
251  * the upgrade will not continue where it left off, you will not be able to
252  * automatically remove old files and remove the 'update_core' option. This
253  * isn't that bad.
254  *
255  * If the copy of the new WordPress over the old fails, then the worse is that
256  * the new WordPress directory will remain.
257  *
258  * If it is assumed that every file will be copied over, including plugins and
259  * themes, then if you edit the default theme, you should rename it, so that
260  * your changes remain.
261  *
262  * @since 2.7.0
263  *
264  * @param string $from New release unzipped path.
265  * @param string $to Path to old WordPress installation.
266  * @return WP_Error|null WP_Error on failure, null on success.
267  */
268 function update_core($from, $to) {
269         global $wp_filesystem, $_old_files, $wpdb;
270
271         @set_time_limit( 300 );
272
273         $php_version    = phpversion();
274         $mysql_version  = $wpdb->db_version();
275         $required_php_version = '4.3';
276         $required_mysql_version = '4.1.2';
277         $wp_version = '3.0.6';
278         $php_compat     = version_compare( $php_version, $required_php_version, '>=' );
279         $mysql_compat   = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
280
281         if ( !$mysql_compat || !$php_compat )
282                 $wp_filesystem->delete($from, true);
283
284         if ( !$mysql_compat && !$php_compat )
285                 return new WP_Error( 'php_mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) );
286         elseif ( !$php_compat )
287                 return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) );
288         elseif ( !$mysql_compat )
289                 return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );
290
291         // Sanity check the unzipped distribution
292         apply_filters('update_feedback', __('Verifying the unpacked files&#8230;'));
293         $distro = '';
294         $roots = array( '/wordpress', '/wordpress-mu' );
295         foreach( $roots as $root ) {
296                 if ( $wp_filesystem->exists($from . $root . '/wp-settings.php') && $wp_filesystem->exists($from . $root . '/wp-admin/admin.php') &&
297                         $wp_filesystem->exists($from . $root . '/wp-includes/functions.php') ) {
298                         $distro = $root;
299                         break;
300                 }
301         }
302         if ( !$distro ) {
303                 $wp_filesystem->delete($from, true);
304                 return new WP_Error('insane_distro', __('The update could not be unpacked') );
305         }
306
307         apply_filters('update_feedback', __('Installing the latest version&#8230;'));
308
309         // Create maintenance file to signal that we are upgrading
310         $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
311         $maintenance_file = $to . '.maintenance';
312         $wp_filesystem->delete($maintenance_file);
313         $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
314
315         // Copy new versions of WP files into place.
316         $result = copy_dir($from . $distro, $to);
317         if ( is_wp_error($result) ) {
318                 $wp_filesystem->delete($maintenance_file);
319                 $wp_filesystem->delete($from, true);
320                 return $result;
321         }
322
323         // Remove old files
324         foreach ( $_old_files as $old_file ) {
325                 $old_file = $to . $old_file;
326                 if ( !$wp_filesystem->exists($old_file) )
327                         continue;
328                 $wp_filesystem->delete($old_file, true);
329         }
330
331         // Upgrade DB with separate request
332         apply_filters('update_feedback', __('Upgrading database&#8230;'));
333         $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
334         wp_remote_post($db_upgrade_url, array('timeout' => 60));
335
336         // Remove working directory
337         $wp_filesystem->delete($from, true);
338
339         // Force refresh of update information
340         if ( function_exists('delete_site_transient') )
341                 delete_site_transient('update_core');
342         else
343                 delete_option('update_core');
344
345         // Remove maintenance file, we're done.
346         $wp_filesystem->delete($maintenance_file);
347 }
348
349 ?>