source: trunk/www.guidonia.net/wp/wp-admin/includes/schema.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 17.5 KB
Line 
1<?php
2/**
3 * WordPress Administration Scheme API
4 *
5 * Here we keep the DB structure and option values.
6 *
7 * @package WordPress
8 * @subpackage Administration
9 */
10
11/**
12 * The database character collate.
13 * @var string
14 * @global string
15 * @name $charset_collate
16 */
17$charset_collate = '';
18
19// Declare these as global in case schema.php is included from a function.
20global $wpdb, $wp_queries;
21
22if ( $wpdb->has_cap( 'collation' ) ) {
23 if ( ! empty($wpdb->charset) )
24 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
25 if ( ! empty($wpdb->collate) )
26 $charset_collate .= " COLLATE $wpdb->collate";
27}
28
29/** Create WordPress database tables SQL */
30$wp_queries = "CREATE TABLE $wpdb->terms (
31 term_id bigint(20) unsigned NOT NULL auto_increment,
32 name varchar(200) NOT NULL default '',
33 slug varchar(200) NOT NULL default '',
34 term_group bigint(10) NOT NULL default 0,
35 PRIMARY KEY (term_id),
36 UNIQUE KEY slug (slug),
37 KEY name (name)
38) $charset_collate;
39CREATE TABLE $wpdb->term_taxonomy (
40 term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment,
41 term_id bigint(20) unsigned NOT NULL default 0,
42 taxonomy varchar(32) NOT NULL default '',
43 description longtext NOT NULL,
44 parent bigint(20) unsigned NOT NULL default 0,
45 count bigint(20) NOT NULL default 0,
46 PRIMARY KEY (term_taxonomy_id),
47 UNIQUE KEY term_id_taxonomy (term_id,taxonomy),
48 KEY taxonomy (taxonomy)
49) $charset_collate;
50CREATE TABLE $wpdb->term_relationships (
51 object_id bigint(20) unsigned NOT NULL default 0,
52 term_taxonomy_id bigint(20) unsigned NOT NULL default 0,
53 term_order int(11) NOT NULL default 0,
54 PRIMARY KEY (object_id,term_taxonomy_id),
55 KEY term_taxonomy_id (term_taxonomy_id)
56) $charset_collate;
57CREATE TABLE $wpdb->comments (
58 comment_ID bigint(20) unsigned NOT NULL auto_increment,
59 comment_post_ID bigint(20) unsigned NOT NULL default '0',
60 comment_author tinytext NOT NULL,
61 comment_author_email varchar(100) NOT NULL default '',
62 comment_author_url varchar(200) NOT NULL default '',
63 comment_author_IP varchar(100) NOT NULL default '',
64 comment_date datetime NOT NULL default '0000-00-00 00:00:00',
65 comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
66 comment_content text NOT NULL,
67 comment_karma int(11) NOT NULL default '0',
68 comment_approved varchar(20) NOT NULL default '1',
69 comment_agent varchar(255) NOT NULL default '',
70 comment_type varchar(20) NOT NULL default '',
71 comment_parent bigint(20) unsigned NOT NULL default '0',
72 user_id bigint(20) unsigned NOT NULL default '0',
73 PRIMARY KEY (comment_ID),
74 KEY comment_approved (comment_approved),
75 KEY comment_post_ID (comment_post_ID),
76 KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
77 KEY comment_date_gmt (comment_date_gmt)
78) $charset_collate;
79CREATE TABLE $wpdb->links (
80 link_id bigint(20) unsigned NOT NULL auto_increment,
81 link_url varchar(255) NOT NULL default '',
82 link_name varchar(255) NOT NULL default '',
83 link_image varchar(255) NOT NULL default '',
84 link_target varchar(25) NOT NULL default '',
85 link_description varchar(255) NOT NULL default '',
86 link_visible varchar(20) NOT NULL default 'Y',
87 link_owner bigint(20) unsigned NOT NULL default '1',
88 link_rating int(11) NOT NULL default '0',
89 link_updated datetime NOT NULL default '0000-00-00 00:00:00',
90 link_rel varchar(255) NOT NULL default '',
91 link_notes mediumtext NOT NULL,
92 link_rss varchar(255) NOT NULL default '',
93 PRIMARY KEY (link_id),
94 KEY link_visible (link_visible)
95) $charset_collate;
96CREATE TABLE $wpdb->options (
97 option_id bigint(20) unsigned NOT NULL auto_increment,
98 blog_id int(11) NOT NULL default '0',
99 option_name varchar(64) NOT NULL default '',
100 option_value longtext NOT NULL,
101 autoload varchar(20) NOT NULL default 'yes',
102 PRIMARY KEY (option_id,blog_id,option_name),
103 KEY option_name (option_name)
104) $charset_collate;
105CREATE TABLE $wpdb->postmeta (
106 meta_id bigint(20) unsigned NOT NULL auto_increment,
107 post_id bigint(20) unsigned NOT NULL default '0',
108 meta_key varchar(255) default NULL,
109 meta_value longtext,
110 PRIMARY KEY (meta_id),
111 KEY post_id (post_id),
112 KEY meta_key (meta_key)
113) $charset_collate;
114CREATE TABLE $wpdb->posts (
115 ID bigint(20) unsigned NOT NULL auto_increment,
116 post_author bigint(20) unsigned NOT NULL default '0',
117 post_date datetime NOT NULL default '0000-00-00 00:00:00',
118 post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
119 post_content longtext NOT NULL,
120 post_title text NOT NULL,
121 post_excerpt text NOT NULL,
122 post_status varchar(20) NOT NULL default 'publish',
123 comment_status varchar(20) NOT NULL default 'open',
124 ping_status varchar(20) NOT NULL default 'open',
125 post_password varchar(20) NOT NULL default '',
126 post_name varchar(200) NOT NULL default '',
127 to_ping text NOT NULL,
128 pinged text NOT NULL,
129 post_modified datetime NOT NULL default '0000-00-00 00:00:00',
130 post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
131 post_content_filtered text NOT NULL,
132 post_parent bigint(20) unsigned NOT NULL default '0',
133 guid varchar(255) NOT NULL default '',
134 menu_order int(11) NOT NULL default '0',
135 post_type varchar(20) NOT NULL default 'post',
136 post_mime_type varchar(100) NOT NULL default '',
137 comment_count bigint(20) NOT NULL default '0',
138 PRIMARY KEY (ID),
139 KEY post_name (post_name),
140 KEY type_status_date (post_type,post_status,post_date,ID),
141 KEY post_parent (post_parent)
142) $charset_collate;
143CREATE TABLE $wpdb->users (
144 ID bigint(20) unsigned NOT NULL auto_increment,
145 user_login varchar(60) NOT NULL default '',
146 user_pass varchar(64) NOT NULL default '',
147 user_nicename varchar(50) NOT NULL default '',
148 user_email varchar(100) NOT NULL default '',
149 user_url varchar(100) NOT NULL default '',
150 user_registered datetime NOT NULL default '0000-00-00 00:00:00',
151 user_activation_key varchar(60) NOT NULL default '',
152 user_status int(11) NOT NULL default '0',
153 display_name varchar(250) NOT NULL default '',
154 PRIMARY KEY (ID),
155 KEY user_login_key (user_login),
156 KEY user_nicename (user_nicename)
157) $charset_collate;
158CREATE TABLE $wpdb->usermeta (
159 umeta_id bigint(20) unsigned NOT NULL auto_increment,
160 user_id bigint(20) unsigned NOT NULL default '0',
161 meta_key varchar(255) default NULL,
162 meta_value longtext,
163 PRIMARY KEY (umeta_id),
164 KEY user_id (user_id),
165 KEY meta_key (meta_key)
166) $charset_collate;";
167
168/**
169 * Create WordPress options and set the default values.
170 *
171 * @since 1.5.0
172 * @uses $wpdb
173 * @uses $wp_db_version
174 */
175function populate_options() {
176 global $wpdb, $wp_db_version;
177
178 $guessurl = wp_guess_url();
179
180 do_action('populate_options');
181
182 if ( ini_get('safe_mode') ) {
183 // Safe mode screws up mkdir(), so we must use a flat structure.
184 $uploads_use_yearmonth_folders = 0;
185 $upload_path = WP_CONTENT_DIR;
186 } else {
187 $uploads_use_yearmonth_folders = 1;
188 $upload_path = WP_CONTENT_DIR . '/uploads';
189 }
190
191 $options = array(
192 'siteurl' => $guessurl,
193 'blogname' => __('My Blog'),
194 'blogdescription' => __('Just another WordPress weblog'),
195 'users_can_register' => 0,
196 'admin_email' => 'you@example.com',
197 'start_of_week' => 1,
198 'use_balanceTags' => 0,
199 'use_smilies' => 1,
200 'require_name_email' => 1,
201 'comments_notify' => 1,
202 'posts_per_rss' => 10,
203 'rss_excerpt_length' => 50,
204 'rss_use_excerpt' => 0,
205 'mailserver_url' => 'mail.example.com',
206 'mailserver_login' => 'login@example.com',
207 'mailserver_pass' => 'password',
208 'mailserver_port' => 110,
209 'default_category' => 1,
210 'default_comment_status' => 'open',
211 'default_ping_status' => 'open',
212 'default_pingback_flag' => 1,
213 'default_post_edit_rows' => 10,
214 'posts_per_page' => 10,
215 /* translators: default date format, see http://php.net/date */
216 'date_format' => __('F j, Y'),
217 /* translators: default time format, see http://php.net/date */
218 'time_format' => __('g:i a'),
219 /* translators: links last updated date format, see http://php.net/date */
220 'links_updated_date_format' => __('F j, Y g:i a'),
221 'links_recently_updated_prepend' => '<em>',
222 'links_recently_updated_append' => '</em>',
223 'links_recently_updated_time' => 120,
224 'comment_moderation' => 0,
225 'moderation_notify' => 1,
226 'permalink_structure' => '',
227 'gzipcompression' => 0,
228 'hack_file' => 0,
229 'blog_charset' => 'UTF-8',
230 'moderation_keys' => '',
231 'active_plugins' => array(),
232 'home' => $guessurl,
233 'category_base' => '',
234 'ping_sites' => 'http://rpc.pingomatic.com/',
235 'advanced_edit' => 0,
236 'comment_max_links' => 2,
237 'gmt_offset' => date('Z') / 3600,
238
239 // 1.5
240 'default_email_category' => 1,
241 'recently_edited' => '',
242 'use_linksupdate' => 0,
243 'template' => 'default',
244 'stylesheet' => 'default',
245 'comment_whitelist' => 1,
246 'blacklist_keys' => '',
247 'comment_registration' => 0,
248 'rss_language' => 'en',
249 'html_type' => 'text/html',
250
251 // 1.5.1
252 'use_trackback' => 0,
253
254 // 2.0
255 'default_role' => 'subscriber',
256 'db_version' => $wp_db_version,
257
258 // 2.0.1
259 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders,
260 'upload_path' => $upload_path,
261
262 // 2.0.3
263 'secret' => wp_generate_password(64),
264
265 // 2.1
266 'blog_public' => '1',
267 'default_link_category' => 2,
268 'show_on_front' => 'posts',
269
270 // 2.2
271 'tag_base' => '',
272
273 // 2.5
274 'show_avatars' => '1',
275 'avatar_rating' => 'G',
276 'upload_url_path' => '',
277 'thumbnail_size_w' => 150,
278 'thumbnail_size_h' => 150,
279 'thumbnail_crop' => 1,
280 'medium_size_w' => 300,
281 'medium_size_h' => 300,
282
283 // 2.6
284 'avatar_default' => 'mystery',
285 'enable_app' => 0,
286 'enable_xmlrpc' => 0,
287
288 // 2.7
289 'large_size_w' => 1024,
290 'large_size_h' => 1024,
291 'image_default_link_type' => 'file',
292 'image_default_size' => '',
293 'image_default_align' => '',
294 'close_comments_for_old_posts' => 0,
295 'close_comments_days_old' => 14,
296 'thread_comments' => 0,
297 'thread_comments_depth' => 5,
298 'page_comments' => 1,
299 'comments_per_page' => 50,
300 'default_comments_page' => 'newest',
301 'comment_order' => 'asc',
302 'sticky_posts' => array(),
303 'widget_categories' => array(),
304 'widget_text' => array(),
305 'widget_rss' => array(),
306
307 // 2.8
308 'timezone_string' => ''
309 );
310
311 // Set autoload to no for these options
312 $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
313
314 $existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
315
316 $insert = '';
317 foreach ( $options as $option => $value ) {
318 if ( in_array($option, $existing_options) )
319 continue;
320 if ( in_array($option, $fat_options) )
321 $autoload = 'no';
322 else
323 $autoload = 'yes';
324
325 $option = $wpdb->escape($option);
326 if ( is_array($value) )
327 $value = serialize($value);
328 $value = $wpdb->escape($value);
329 if ( !empty($insert) )
330 $insert .= ', ';
331 $insert .= "('$option', '$value', '$autoload')";
332 }
333
334 if ( !empty($insert) )
335 $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert);
336
337 // in case it is set, but blank, update "home"
338 if ( !__get_option('home') ) update_option('home', $guessurl);
339
340 // Delete unused options
341 $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins', 'can_compress_scripts',
342 'page_uris', 'rewrite_rules', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed');
343 foreach ($unusedoptions as $option)
344 delete_option($option);
345}
346
347/**
348 * Execute WordPress role creation for the various WordPress versions.
349 *
350 * @since 2.0.0
351 */
352function populate_roles() {
353 populate_roles_160();
354 populate_roles_210();
355 populate_roles_230();
356 populate_roles_250();
357 populate_roles_260();
358 populate_roles_270();
359 populate_roles_280();
360}
361
362/**
363 * Create the roles for WordPress 2.0
364 *
365 * @since 2.0.0
366 */
367function populate_roles_160() {
368 // Add roles
369
370 // Dummy gettext calls to get strings in the catalog.
371 /* translators: user role */
372 _x('Administrator', 'User role');
373 /* translators: user role */
374 _x('Editor', 'User role');
375 /* translators: user role */
376 _x('Author', 'User role');
377 /* translators: user role */
378 _x('Contributor', 'User role');
379 /* translators: user role */
380 _x('Subscriber', 'User role');
381
382 add_role('administrator', 'Administrator');
383 add_role('editor', 'Editor');
384 add_role('author', 'Author');
385 add_role('contributor', 'Contributor');
386 add_role('subscriber', 'Subscriber');
387
388 // Add caps for Administrator role
389 $role =& get_role('administrator');
390 $role->add_cap('switch_themes');
391 $role->add_cap('edit_themes');
392 $role->add_cap('activate_plugins');
393 $role->add_cap('edit_plugins');
394 $role->add_cap('edit_users');
395 $role->add_cap('edit_files');
396 $role->add_cap('manage_options');
397 $role->add_cap('moderate_comments');
398 $role->add_cap('manage_categories');
399 $role->add_cap('manage_links');
400 $role->add_cap('upload_files');
401 $role->add_cap('import');
402 $role->add_cap('unfiltered_html');
403 $role->add_cap('edit_posts');
404 $role->add_cap('edit_others_posts');
405 $role->add_cap('edit_published_posts');
406 $role->add_cap('publish_posts');
407 $role->add_cap('edit_pages');
408 $role->add_cap('read');
409 $role->add_cap('level_10');
410 $role->add_cap('level_9');
411 $role->add_cap('level_8');
412 $role->add_cap('level_7');
413 $role->add_cap('level_6');
414 $role->add_cap('level_5');
415 $role->add_cap('level_4');
416 $role->add_cap('level_3');
417 $role->add_cap('level_2');
418 $role->add_cap('level_1');
419 $role->add_cap('level_0');
420
421 // Add caps for Editor role
422 $role =& get_role('editor');
423 $role->add_cap('moderate_comments');
424 $role->add_cap('manage_categories');
425 $role->add_cap('manage_links');
426 $role->add_cap('upload_files');
427 $role->add_cap('unfiltered_html');
428 $role->add_cap('edit_posts');
429 $role->add_cap('edit_others_posts');
430 $role->add_cap('edit_published_posts');
431 $role->add_cap('publish_posts');
432 $role->add_cap('edit_pages');
433 $role->add_cap('read');
434 $role->add_cap('level_7');
435 $role->add_cap('level_6');
436 $role->add_cap('level_5');
437 $role->add_cap('level_4');
438 $role->add_cap('level_3');
439 $role->add_cap('level_2');
440 $role->add_cap('level_1');
441 $role->add_cap('level_0');
442
443 // Add caps for Author role
444 $role =& get_role('author');
445 $role->add_cap('upload_files');
446 $role->add_cap('edit_posts');
447 $role->add_cap('edit_published_posts');
448 $role->add_cap('publish_posts');
449 $role->add_cap('read');
450 $role->add_cap('level_2');
451 $role->add_cap('level_1');
452 $role->add_cap('level_0');
453
454 // Add caps for Contributor role
455 $role =& get_role('contributor');
456 $role->add_cap('edit_posts');
457 $role->add_cap('read');
458 $role->add_cap('level_1');
459 $role->add_cap('level_0');
460
461 // Add caps for Subscriber role
462 $role =& get_role('subscriber');
463 $role->add_cap('read');
464 $role->add_cap('level_0');
465}
466
467/**
468 * Create and modify WordPress roles for WordPress 2.1.
469 *
470 * @since 2.1.0
471 */
472function populate_roles_210() {
473 $roles = array('administrator', 'editor');
474 foreach ($roles as $role) {
475 $role =& get_role($role);
476 if ( empty($role) )
477 continue;
478
479 $role->add_cap('edit_others_pages');
480 $role->add_cap('edit_published_pages');
481 $role->add_cap('publish_pages');
482 $role->add_cap('delete_pages');
483 $role->add_cap('delete_others_pages');
484 $role->add_cap('delete_published_pages');
485 $role->add_cap('delete_posts');
486 $role->add_cap('delete_others_posts');
487 $role->add_cap('delete_published_posts');
488 $role->add_cap('delete_private_posts');
489 $role->add_cap('edit_private_posts');
490 $role->add_cap('read_private_posts');
491 $role->add_cap('delete_private_pages');
492 $role->add_cap('edit_private_pages');
493 $role->add_cap('read_private_pages');
494 }
495
496 $role =& get_role('administrator');
497 if ( ! empty($role) ) {
498 $role->add_cap('delete_users');
499 $role->add_cap('create_users');
500 }
501
502 $role =& get_role('author');
503 if ( ! empty($role) ) {
504 $role->add_cap('delete_posts');
505 $role->add_cap('delete_published_posts');
506 }
507
508 $role =& get_role('contributor');
509 if ( ! empty($role) ) {
510 $role->add_cap('delete_posts');
511 }
512}
513
514/**
515 * Create and modify WordPress roles for WordPress 2.3.
516 *
517 * @since 2.3.0
518 */
519function populate_roles_230() {
520 $role =& get_role( 'administrator' );
521
522 if ( !empty( $role ) ) {
523 $role->add_cap( 'unfiltered_upload' );
524 }
525}
526
527/**
528 * Create and modify WordPress roles for WordPress 2.5.
529 *
530 * @since 2.5.0
531 */
532function populate_roles_250() {
533 $role =& get_role( 'administrator' );
534
535 if ( !empty( $role ) ) {
536 $role->add_cap( 'edit_dashboard' );
537 }
538}
539
540/**
541 * Create and modify WordPress roles for WordPress 2.6.
542 *
543 * @since 2.6.0
544 */
545function populate_roles_260() {
546 $role =& get_role( 'administrator' );
547
548 if ( !empty( $role ) ) {
549 $role->add_cap( 'update_plugins' );
550 $role->add_cap( 'delete_plugins' );
551 }
552}
553
554/**
555 * Create and modify WordPress roles for WordPress 2.7.
556 *
557 * @since 2.7.0
558 */
559function populate_roles_270() {
560 $role =& get_role( 'administrator' );
561
562 if ( !empty( $role ) ) {
563 $role->add_cap( 'install_plugins' );
564 $role->add_cap( 'update_themes' );
565 }
566}
567
568/**
569 * Create and modify WordPress roles for WordPress 2.8.
570 *
571 * @since 2.8.0
572 */
573function populate_roles_280() {
574 $role =& get_role( 'administrator' );
575
576 if ( !empty( $role ) ) {
577 $role->add_cap( 'install_themes' );
578 }
579}
580
581?>
Note: See TracBrowser for help on using the repository browser.