root/tags/1.3/wp-admin/includes/schema.php

Revision 1139, 17.2 kB (checked in by donncha, 7 months ago)

Merge with WordPress? 2.3.1

Line 
1 <?php
2 // Here we keep the DB structure and option values
3
4 global $wp_queries;
5 $charset_collate = '';
6
7 if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
8     if ( ! empty($wpdb->charset) )
9         $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
10     if ( ! empty($wpdb->collate) )
11         $charset_collate .= " COLLATE $wpdb->collate";
12 }
13
14 $wp_queries="CREATE TABLE $wpdb->terms (
15  term_id bigint(20) NOT NULL auto_increment,
16  name varchar(55) NOT NULL default '',
17  slug varchar(200) NOT NULL default '',
18  term_group bigint(10) NOT NULL default 0,
19  PRIMARY KEY  (term_id),
20  UNIQUE KEY slug (slug)
21 ) $charset_collate;
22 CREATE TABLE $wpdb->term_taxonomy (
23  term_taxonomy_id bigint(20) NOT NULL auto_increment,
24  term_id bigint(20) NOT NULL default 0,
25  taxonomy varchar(32) NOT NULL default '',
26  description longtext NOT NULL,
27  parent bigint(20) NOT NULL default 0,
28  count bigint(20) NOT NULL default 0,
29  PRIMARY KEY  (term_taxonomy_id),
30  UNIQUE KEY term_id_taxonomy (term_id,taxonomy)
31 ) $charset_collate;
32 CREATE TABLE $wpdb->term_relationships (
33  object_id bigint(20) NOT NULL default 0,
34  term_taxonomy_id bigint(20) NOT NULL default 0,
35  PRIMARY KEY  (object_id,term_taxonomy_id),
36  KEY term_taxonomy_id (term_taxonomy_id)
37 ) $charset_collate;
38 CREATE TABLE $wpdb->comments (
39   comment_ID bigint(20) unsigned NOT NULL auto_increment,
40   comment_post_ID int(11) NOT NULL default '0',
41   comment_author tinytext NOT NULL,
42   comment_author_email varchar(100) NOT NULL default '',
43   comment_author_url varchar(200) NOT NULL default '',
44   comment_author_IP varchar(100) NOT NULL default '',
45   comment_date datetime NOT NULL default '0000-00-00 00:00:00',
46   comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
47   comment_content text NOT NULL,
48   comment_karma int(11) NOT NULL default '0',
49   comment_approved enum('0','1','spam') NOT NULL default '1',
50   comment_agent varchar(255) NOT NULL default '',
51   comment_type varchar(20) NOT NULL default '',
52   comment_parent bigint(20) NOT NULL default '0',
53   user_id bigint(20) NOT NULL default '0',
54   PRIMARY KEY  (comment_ID),
55   KEY comment_approved (comment_approved),
56   KEY comment_post_ID (comment_post_ID)
57 ) $charset_collate;
58 CREATE TABLE $wpdb->links (
59   link_id bigint(20) NOT NULL auto_increment,
60   link_url varchar(255) NOT NULL default '',
61   link_name varchar(255) NOT NULL default '',
62   link_image varchar(255) NOT NULL default '',
63   link_target varchar(25) NOT NULL default '',
64   link_category bigint(20) NOT NULL default '0',
65   link_description varchar(255) NOT NULL default '',
66   link_visible enum('Y','N') NOT NULL default 'Y',
67   link_owner int(11) NOT NULL default '1',
68   link_rating int(11) NOT NULL default '0',
69   link_updated datetime NOT NULL default '0000-00-00 00:00:00',
70   link_rel varchar(255) NOT NULL default '',
71   link_notes mediumtext NOT NULL,
72   link_rss varchar(255) NOT NULL default '',
73   PRIMARY KEY  (link_id),
74   KEY link_category (link_category),
75   KEY link_visible (link_visible)
76 ) $charset_collate;
77 CREATE TABLE $wpdb->options (
78   option_id bigint(20) NOT NULL auto_increment,
79   blog_id int(11) NOT NULL default '0',
80   option_name varchar(64) NOT NULL default '',
81   option_value longtext NOT NULL,
82   autoload enum('yes','no') NOT NULL default 'yes',
83   PRIMARY KEY  (option_id,blog_id,option_name),
84   KEY option_name (option_name)
85 ) $charset_collate;
86 CREATE TABLE $wpdb->postmeta (
87   meta_id bigint(20) NOT NULL auto_increment,
88   post_id bigint(20) NOT NULL default '0',
89   meta_key varchar(255) default NULL,
90   meta_value longtext,
91   PRIMARY KEY  (meta_id),
92   KEY post_id (post_id),
93   KEY meta_key (meta_key)
94 ) $charset_collate;
95 CREATE TABLE $wpdb->posts (
96   ID bigint(20) unsigned NOT NULL auto_increment,
97   post_author bigint(20) NOT NULL default '0',
98   post_date datetime NOT NULL default '0000-00-00 00:00:00',
99   post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
100   post_content longtext NOT NULL,
101   post_title text NOT NULL,
102   post_category int(4) NOT NULL default '0',
103   post_excerpt text NOT NULL,
104   post_status enum('publish','draft','private','static','object','attachment','inherit','future', 'pending') NOT NULL default 'publish',
105   comment_status enum('open','closed','registered_only') NOT NULL default 'open',
106   ping_status enum('open','closed') NOT NULL default 'open',
107   post_password varchar(20) NOT NULL default '',
108   post_name varchar(200) NOT NULL default '',
109   to_ping text NOT NULL,
110   pinged text NOT NULL,
111   post_modified datetime NOT NULL default '0000-00-00 00:00:00',
112   post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
113   post_content_filtered text NOT NULL,
114   post_parent bigint(20) NOT NULL default '0',
115   guid varchar(255) NOT NULL default '',
116   menu_order int(11) NOT NULL default '0',
117   post_type varchar(20) NOT NULL default 'post',
118   post_mime_type varchar(100) NOT NULL default '',
119   comment_count bigint(20) NOT NULL default '0',
120   PRIMARY KEY  (ID),
121   KEY post_name (post_name),
122   KEY type_status_date (post_type,post_status,post_date,ID)
123 ) $charset_collate;
124 CREATE TABLE IF NOT EXISTS $wpdb->users (
125   ID bigint(20) unsigned NOT NULL auto_increment,
126   user_login varchar(60) NOT NULL default '',
127   user_pass varchar(64) NOT NULL default '',
128   user_nicename varchar(50) NOT NULL default '',
129   user_email varchar(100) NOT NULL default '',
130   user_url varchar(100) NOT NULL default '',
131   user_registered datetime NOT NULL default '0000-00-00 00:00:00',
132   user_activation_key varchar(60) NOT NULL default '',
133   user_status int(11) NOT NULL default '0',
134   display_name varchar(250) NOT NULL default '',
135   spam tinyint(2) NOT NULL default '0',
136   deleted tinyint(2) NOT NULL default '0',
137   PRIMARY KEY  (ID),
138   KEY user_login_key (user_login),
139   KEY user_nicename (user_nicename)
140 ) $charset_collate;
141 CREATE TABLE IF NOT EXISTS $wpdb->usermeta (
142   umeta_id bigint(20) NOT NULL auto_increment,
143   user_id bigint(20) NOT NULL default '0',
144   meta_key varchar(255) default NULL,
145   meta_value longtext,
146   PRIMARY KEY  (umeta_id),
147   KEY user_id (user_id),
148   KEY meta_key (meta_key)
149 ) $charset_collate;
150 CREATE TABLE IF NOT EXISTS $wpdb->blogs (
151   blog_id bigint(20) NOT NULL auto_increment,
152   site_id bigint(20) NOT NULL default '0',
153   domain varchar(200) NOT NULL default '',
154   path varchar(100) NOT NULL default '',
155   registered datetime NOT NULL default '0000-00-00 00:00:00',
156   last_updated datetime NOT NULL default '0000-00-00 00:00:00',
157   public tinyint(2) NOT NULL default '1',
158   archived enum('0','1') NOT NULL default '0',
159   mature tinyint(2) NOT NULL default '0',
160   spam tinyint(2) NOT NULL default '0',
161   deleted tinyint(2) NOT NULL default '0',
162   lang_id int(11) NOT NULL default '0',
163   PRIMARY KEY  (blog_id),
164   KEY domain (domain(50),path(5)),
165   KEY lang_id (lang_id)
166 ) $charset_collate;
167 CREATE TABLE IF NOT EXISTS $wpdb->blog_versions (
168   blog_id bigint(20) NOT NULL default '0',
169   db_version varchar(20) NOT NULL default '',
170   last_updated datetime NOT NULL default '0000-00-00 00:00:00',
171   PRIMARY KEY  (blog_id),
172   KEY db_version (db_version)
173 ) $charset_collate;
174 CREATE TABLE IF NOT EXISTS $wpdb->registration_log (
175   ID bigint(20) NOT NULL auto_increment,
176   email varchar(255) NOT NULL default '',
177   IP varchar(30) NOT NULL default '',
178   blog_id bigint(20) NOT NULL default '0',
179   date_registered datetime NOT NULL default '0000-00-00 00:00:00',
180   PRIMARY KEY  (ID),
181   KEY IP (IP)
182 ) $charset_collate;
183 CREATE TABLE $wpdb->site (
184   id bigint(20) NOT NULL auto_increment,
185   domain varchar(200) NOT NULL default '',
186   path varchar(100) NOT NULL default '',
187   PRIMARY KEY  (id),
188   KEY domain (domain,path)
189 ) $charset_collate;
190 CREATE TABLE IF NOT EXISTS $wpdb->sitemeta (
191   meta_id bigint(20) NOT NULL auto_increment,
192   site_id bigint(20) NOT NULL default '0',
193   meta_key varchar(255) default NULL,
194   meta_value longtext,
195   PRIMARY KEY  (meta_id),
196   KEY meta_key (meta_key),
197   KEY site_id (site_id)
198 ) $charset_collate;
199 CREATE TABLE IF NOT EXISTS $wpdb->sitecategories (
200   cat_ID bigint(20) NOT NULL auto_increment,
201   cat_name varchar(55) NOT NULL default '',
202   category_nicename varchar(200) NOT NULL default '',
203   last_updated timestamp NOT NULL,
204   PRIMARY KEY  (cat_ID),
205   KEY category_nicename (category_nicename),
206   KEY last_updated (last_updated)
207 ) $charset_collate;
208 CREATE TABLE IF NOT EXISTS $wpdb->signups (
209   domain varchar(200) NOT NULL default '',
210   path varchar(100) NOT NULL default '',
211   title longtext NOT NULL,
212   user_login varchar(60) NOT NULL default '',
213   user_email varchar(100) NOT NULL default '',
214   registered datetime NOT NULL default '0000-00-00 00:00:00',
215   activated datetime NOT NULL default '0000-00-00 00:00:00',
216   active tinyint(1) NOT NULL default '0',
217   activation_key varchar(50) NOT NULL default '',
218   meta longtext,
219   KEY activation_key (activation_key),
220   KEY domain (domain)
221 ) $charset_collate;
222 ";
223
224 function populate_options() {
225     global $wpdb, $wp_db_version, $wpblog, $current_site;
226
227     $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
228     $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
229     add_option('siteurl', $guessurl);
230     add_option('blogname', __('My Blog'));
231     add_option('blogdescription', __('Just another ' . $current_site->site_name . ' weblog'), __('Short tagline'));
232     add_option('new_users_can_blog', 0);
233     add_option('users_can_register', 0);
234     add_option('admin_email', 'you@example.com');
235     add_option('start_of_week', 1);
236     add_option('use_balanceTags', 0);
237     add_option('use_smilies', 1);
238     add_option('require_name_email', 1);
239     add_option('comments_notify', 1);
240     add_option('posts_per_rss', 10);
241     add_option('rss_excerpt_length', 50);
242     add_option('rss_use_excerpt', 0);
243     add_option('mailserver_url', 'mail.example.com');
244     add_option('mailserver_login', 'login@example.com');
245     add_option('mailserver_pass', 'password');
246     add_option('mailserver_port', 110);
247     add_option('default_category', 1);
248     add_option('default_comment_status', 'open');
249     add_option('default_ping_status', 'open');
250     add_option('default_pingback_flag', 1);
251     add_option('default_post_edit_rows', 10);
252     add_option('posts_per_page', 10);
253     add_option('what_to_show', 'posts');
254     add_option('date_format', __('F j, Y'));
255     add_option('time_format', __('g:i a'));
256     add_option('links_updated_date_format', __('F j, Y g:i a'));
257     add_option('links_recently_updated_prepend', '<em>');
258     add_option('links_recently_updated_append', '</em>');
259     add_option('links_recently_updated_time', 120);
260     add_option('comment_moderation', 0);
261     add_option('moderation_notify', 1);
262     add_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
263     add_option('gzipcompression', 0);
264     add_option('hack_file', 0);
265     add_option('blog_charset', 'UTF-8');
266     add_option('moderation_keys');
267     add_option('active_plugins');
268     add_option('home', $guessurl);
269     // in case it is set, but blank, update "home"
270     if ( !__get_option('home') ) update_option('home', $guessurl);
271     add_option('category_base');
272     add_option('ping_sites', 'http://rpc.pingomatic.com/');
273     add_option('advanced_edit', 0);
274     add_option('comment_max_links', 2);
275     add_option('gmt_offset', date('Z') / 3600);
276     // 1.5
277     add_option('default_email_category', 1);
278     add_option('recently_edited');
279     add_option('use_linksupdate', 0);
280     add_option('template', 'default');
281     add_option('stylesheet', 'default');
282     add_option('comment_whitelist', 1);
283     add_option('page_uris');
284     add_option('blacklist_keys');
285     add_option('comment_registration', 0);
286     add_option('rss_language', 'en');
287     add_option('html_type', 'text/html');
288     // 1.5.1
289     add_option('use_trackback', 0);
290     // 2.0
291     add_option('default_role', 'subscriber');
292     add_option('db_version', $wp_db_version);
293     // 2.0.1
294     if ( ini_get('safe_mode') ) {
295         // Safe mode screws up mkdir(), so we must use a flat structure.
296         add_option('uploads_use_yearmonth_folders', 0);
297         add_option('upload_path', 'wp-content');
298     } else {
299         add_option('uploads_use_yearmonth_folders', 1);
300         add_option('upload_path', 'wp-content/uploads');
301     }
302
303     // 2.0.3
304     add_option('secret', md5(uniqid(microtime())));
305
306     // 2.1
307     add_option('blog_public', '1');
308     add_option('default_link_category', 2);
309     add_option('show_on_front', 'posts');
310
311     // 2.2
312     add_option('tag_base');
313
314     // Delete unused options
315     $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');
316     foreach ($unusedoptions as $option) :
317         delete_option($option);
318     endforeach;
319
320     // Set up a few options not to load by default
321     $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
322     foreach ($fatoptions as $fatoption) :
323         $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
324     endforeach;
325 }
326
327 function populate_roles() {
328     populate_roles_160();
329     populate_roles_210();
330     populate_roles_230();
331 }
332
333 function populate_roles_160() {
334     global $wp_roles;
335
336     // Add roles
337     add_role('administrator', __('Administrator'));
338     add_role('editor', __('Editor'));
339     add_role('author', __('Author'));
340     add_role('contributor', __('Contributor'));
341     add_role('subscriber', __('Subscriber'));
342
343     // Add caps for Administrator role
344     $role = get_role('administrator');
345     $role->add_cap('switch_themes');
346     $role->add_cap('edit_themes');
347     $role->add_cap('activate_plugins');
348     $role->add_cap('edit_plugins');
349     $role->add_cap('edit_users');
350     $role->add_cap('edit_files');
351     $role->add_cap('manage_options');
352     $role->add_cap('moderate_comments');
353     $role->add_cap('manage_categories');
354     $role->add_cap('manage_links');
355     $role->add_cap('upload_files');
356     $role->add_cap('import');
357     $role->add_cap('unfiltered_html');
358     $role->add_cap('edit_posts');
359     $role->add_cap('edit_others_posts');
360     $role->add_cap('edit_published_posts');
361     $role->add_cap('publish_posts');
362     $role->add_cap('edit_pages');
363     $role->add_cap('read');
364     $role->add_cap('level_10');
365     $role->add_cap('level_9');
366     $role->add_cap('level_8');
367     $role->add_cap('level_7');
368     $role->add_cap('level_6');
369     $role->add_cap('level_5');
370     $role->add_cap('level_4');
371     $role->add_cap('level_3');
372     $role->add_cap('level_2');
373     $role->add_cap('level_1');
374     $role->add_cap('level_0');
375
376     // Add caps for Editor role
377     $role = get_role('editor');
378     $role->add_cap('moderate_comments');
379     $role->add_cap('manage_categories');
380     $role->add_cap('manage_links');
381     $role->add_cap('upload_files');
382     $role->add_cap('unfiltered_html');
383     $role->add_cap('edit_posts');
384     $role->add_cap('edit_others_posts');
385     $role->add_cap('edit_published_posts');
386     $role->add_cap('publish_posts');
387     $role->add_cap('edit_pages');
388     $role->add_cap('read');
389     $role->add_cap('level_7');
390     $role->add_cap('level_6');
391     $role->add_cap('level_5');
392     $role->add_cap('level_4');
393     $role->add_cap('level_3');
394     $role->add_cap('level_2');
395     $role->add_cap('level_1');
396     $role->add_cap('level_0');
397
398     // Add caps for Author role
399     $role = get_role('author');
400     $role->add_cap('upload_files');
401     $role->add_cap('edit_posts');
402     $role->add_cap('edit_published_posts');
403     $role->add_cap('publish_posts');
404     $role->add_cap('read');
405     $role->add_cap('level_2');
406     $role->add_cap('level_1');
407     $role->add_cap('level_0');
408
409     // Add caps for Contributor role
410     $role = get_role('contributor');
411     $role->add_cap('edit_posts');
412     $role->add_cap('read');
413     $role->add_cap('level_1');
414     $role->add_cap('level_0');
415
416     // Add caps for Subscriber role
417     $role = get_role('subscriber');
418     $role->add_cap('read');
419     $role->add_cap('level_0');
420 }
421
422 function populate_roles_210() {
423     $roles = array('administrator', 'editor');
424     foreach ($roles as $role) {
425         $role = get_role($role);
426         if ( empty($role) )
427             continue;
428
429         $role->add_cap('edit_others_pages');
430         $role->add_cap('edit_published_pages');
431         $role->add_cap('publish_pages');
432         $role->add_cap('delete_pages');
433         $role->add_cap('delete_others_pages');
434         $role->add_cap('delete_published_pages');
435         $role->add_cap('delete_posts');
436         $role->add_cap('delete_others_posts');
437         $role->add_cap('delete_published_posts');
438         $role->add_cap('delete_private_posts');
439         $role->add_cap('edit_private_posts');
440         $role->add_cap('read_private_posts');
441         $role->add_cap('delete_private_pages');
442         $role->add_cap('edit_private_pages');
443         $role->add_cap('read_private_pages');
444     }
445
446     $role = get_role('administrator');
447     if ( ! empty($role) ) {
448         $role->add_cap('delete_users');
449         $role->add_cap('create_users');
450     }
451
452     $role = get_role('author');
453     if ( ! empty($role) ) {
454         $role->add_cap('delete_posts');
455         $role->add_cap('delete_published_posts');
456     }
457
458     $role = get_role('contributor');
459     if ( ! empty($role) ) {
460         $role->add_cap('delete_posts');
461     }
462 }
463
464 function populate_roles_230() {
465     /*
466     $role = get_role( 'administrator' );
467
468     if ( !empty( $role ) ) {
469         $role->add_cap( 'unfiltered_upload' );
470     }
471     */
472 }
473
474 ?>
475
Note: See TracBrowser for help on using the browser.