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