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