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