Log in with username/password: lyceum/lyceum

root/trunk/src/lib/wp-admin/upgrade-schema.php

Revision 616, 15.3 kB (checked in by jjb, 4 years ago)

Subdomains!

Most of the pieces in order to use subdomains. The way that cookies are set needs to be adapted to this system. As it is now, users have to keep re-logging-in when they switch from one domain to another.

Many thanks to coffelius of http://bloggear.net for help and code.

ticket:326

Line 
1 <?php
2 // Here we keep the DB structure and option values
3
4 $wp_queries="CREATE TABLE $wpdb->categories (
5     cat_ID int unsigned NOT NULL auto_increment,
6     cat_name varchar(55) NOT NULL default '',
7     category_nicename varchar(200) NOT NULL default '',
8     category_description longtext NOT NULL,
9     category_parent int NOT NULL default '0',
10     category_count int NOT NULL default '0',
11     blog int unsigned NOT NULL default '0',
12     KEY blog (blog),
13     PRIMARY KEY     (cat_ID),
14     KEY category_nicename (category_nicename)
15 ) ENGINE = InnoDB;
16 CREATE TABLE $wpdb->comments (
17     comment_ID int unsigned NOT NULL auto_increment,
18     comment_post_ID int unsigned NOT NULL default '0',
19     comment_author tinytext NOT NULL,
20     comment_author_email varchar(100) NOT NULL default '',
21     comment_author_url varchar(200) NOT NULL default '',
22     comment_author_IP varchar(100) NOT NULL default '',
23     comment_date datetime NOT NULL default '0000-00-00 00:00:00',
24     comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
25     comment_content text NOT NULL,
26     comment_karma int(11) NOT NULL default '0',
27     comment_approved enum('0','1','spam') NOT NULL default '1',
28     comment_agent varchar(255) NOT NULL default '',
29     comment_type varchar(20) NOT NULL default '',
30     comment_parent int NOT NULL default '0',
31     user_id int NOT NULL default '0',
32     PRIMARY KEY     (comment_ID),
33     KEY comment_approved (comment_approved),
34     KEY comment_post_ID (comment_post_ID)
35 ) ENGINE = InnoDB;
36 CREATE TABLE $wpdb->linkcategories (
37     cat_id int unsigned NOT NULL auto_increment,
38     cat_name tinytext NOT NULL,
39     auto_toggle enum('Y','N') NOT NULL default 'N',
40     show_images enum('Y','N') NOT NULL default 'Y',
41     show_description enum('Y','N') NOT NULL default 'N',
42     show_rating enum('Y','N') NOT NULL default 'Y',
43     show_updated enum('Y','N') NOT NULL default 'Y',
44     sort_order varchar(64) NOT NULL default 'rand',
45     sort_desc enum('Y','N') NOT NULL default 'N',
46     text_before_link varchar(128) NOT NULL default '<li>',
47     text_after_link varchar(128) NOT NULL default '<br />',
48     text_after_all varchar(128) NOT NULL default '</li>',
49     list_limit int(11) NOT NULL default '-1',
50     blog mediumint(8) unsigned NOT NULL default '0',
51     KEY blog (blog),
52     PRIMARY KEY     (cat_id)
53 ) ENGINE = InnoDB;
54 CREATE TABLE $wpdb->links (
55     link_id mediumint unsigned NOT NULL auto_increment,
56     link_url varchar(255) NOT NULL default '',
57     link_name varchar(255) NOT NULL default '',
58     link_image varchar(255) NOT NULL default '',
59     link_target varchar(25) NOT NULL default '',
60     link_category mediumint NOT NULL default '0',
61     link_description varchar(255) NOT NULL default '',
62     link_visible enum('Y','N') NOT NULL default 'Y',
63     link_owner int(11) NOT NULL default '1',
64     link_rating int(11) NOT NULL default '0',
65     link_updated datetime NOT NULL default '0000-00-00 00:00:00',
66     link_rel varchar(255) NOT NULL default '',
67     link_notes mediumtext NOT NULL,
68     link_rss varchar(255) NOT NULL default '',
69     PRIMARY KEY     (link_id),
70     KEY link_category (link_category),
71     KEY link_visible (link_visible)
72 ) ENGINE = InnoDB;
73 CREATE TABLE $wpdb->options (
74     option_id mediumint unsigned NOT NULL auto_increment,
75     blog_id int unsigned NOT NULL default '0',
76     option_name varchar(64) NOT NULL default '',
77     option_can_override enum('Y','N') NOT NULL default 'Y',
78     option_type int(11) NOT NULL default '1',
79     option_value longtext NOT NULL,
80     option_width int(11) NOT NULL default '20',
81     option_height int(11) NOT NULL default '8',
82     option_description tinytext NOT NULL,
83     option_admin_level int(11) NOT NULL default '1',
84     autoload enum('yes','no') NOT NULL default 'yes',
85     option_domain enum('system','blog') NOT NULL default 'blog',
86     blog mediumint unsigned,
87     KEY blog (blog),
88     PRIMARY KEY     (option_id,blog_id,option_name),
89     KEY option_name (option_name)
90 ) ENGINE = InnoDB;
91 CREATE TABLE $wpdb->post2cat (
92     rel_id int unsigned NOT NULL auto_increment,
93     post_id int unsigned NOT NULL default '0',
94     category_id int unsigned NOT NULL default '0',
95     PRIMARY KEY     (rel_id),
96     KEY post_id (post_id,category_id)
97 ) ENGINE = InnoDB;
98 CREATE TABLE $wpdb->postmeta (
99     meta_id int unsigned NOT NULL auto_increment,
100     post_id int unsigned NOT NULL default '0',
101     meta_key varchar(255) default NULL,
102     meta_value longtext,
103     PRIMARY KEY     (meta_id),
104     KEY post_id (post_id),
105     KEY meta_key (meta_key)
106 ) ENGINE = InnoDB;
107 CREATE TABLE $wpdb->posts (
108     ID int unsigned NOT NULL auto_increment,
109     post_author mediumint unsigned NOT NULL default '0',
110     post_date datetime NOT NULL default '0000-00-00 00:00:00',
111     post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
112     post_content longtext NOT NULL,
113     post_title text NOT NULL,
114     post_category int(4) NOT NULL default '0',
115     post_excerpt text NOT NULL,
116     post_status enum('publish','draft','private','static','object','attachment') NOT NULL default 'publish',
117     comment_status enum('open','closed','registered_only') NOT NULL default 'open',
118     ping_status enum('open','closed') NOT NULL default 'open',
119     post_password varchar(20) NOT NULL default '',
120     post_name varchar(200) NOT NULL default '',
121     to_ping text NOT NULL,
122     pinged text NOT NULL,
123     post_modified datetime NOT NULL default '0000-00-00 00:00:00',
124     post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
125     post_content_filtered text NOT NULL,
126     post_parent int NOT NULL default '0',
127     guid varchar(255) NOT NULL default '',
128     menu_order int(11) NOT NULL default '0',
129     post_type varchar(100) NOT NULL default '',
130     post_mime_type varchar(100) NOT NULL default '',
131     comment_count int NOT NULL default '0',
132     page_blog mediumint unsigned default NULL,
133     KEY page_blog (page_blog),
134     KEY post_parent (post_parent),
135     PRIMARY KEY     (ID),
136     KEY post_name (post_name)
137 ) ENGINE = InnoDB;
138 CREATE TABLE $wpdb->users (
139     ID mediumint unsigned NOT NULL auto_increment,
140     user_locked enum('0','1') NOT NULL default '0',
141     user_admin enum('0','1') NOT NULL default '0',
142     user_login varchar(60) unique NOT NULL default '',
143     user_pass varchar(64) NOT NULL default '',
144     user_nicename varchar(50) NOT NULL default '',
145     user_email varchar(100) NOT NULL default '',
146     user_url varchar(100) NOT NULL default '',
147     user_registered datetime NOT NULL default '0000-00-00 00:00:00',
148     user_activation_key varchar(60) NOT NULL default '',
149     user_status int(11) NOT NULL default '0',
150     display_name varchar(250) NOT NULL default '',
151     PRIMARY KEY     (ID),
152     KEY user_login_key (user_login)
153 ) ENGINE = InnoDB;
154 CREATE TABLE $wpdb->usermeta (
155     umeta_id mediumint unsigned NOT NULL auto_increment,
156     user_id int unsigned NOT NULL default '0',
157     meta_key varchar(255) default NULL,
158     meta_value longtext,
159     meta_domain enum('system','blog') NOT NULL default 'blog',
160     blog mediumint(8) unsigned default NULL,
161     KEY blog (blog),
162     PRIMARY KEY     (umeta_id),
163     KEY user_id (user_id),
164     KEY meta_key  (meta_key)
165 ) ENGINE = InnoDB;
166 CREATE TABLE $wpdb->blogs (
167     `id` int unsigned NOT NULL auto_increment,
168     `slug` varchar(60) unique default NULL,
169     `created` datetime NOT NULL default '0000-00-00 00:00:00',
170     `status` enum('active','deleted') NOT NULL default 'active',
171     PRIMARY KEY     (`id`),
172     KEY (`slug`)
173 ) ENGINE = InnoDB;
174 CREATE TABLE $wpdb->postsearch (
175     `id` int unsigned NOT NULL auto_increment,
176     `post_id` int unsigned,
177     `object_id` int unsigned default NULL,
178     `component` enum('title', 'content','comment'),
179     `textdata` text,
180     PRIMARY KEY     (`id`),
181     KEY (`post_id`),
182     FULLTEXT (`textdata`)
183 ) ENGINE = MyIsam;
184 CREATE TABLE $wpdb->sessions (
185     id varchar(32) NOT NULL,
186     access int(10) unsigned,
187     data text,
188     PRIMARY KEY  (id)
189 ) ENGINE = InnoDB;
190 ";
191
192 function populate_options() {
193     global $wpdb;
194     global $blog;
195     assert(isset($blog));
196     
197     $old_umask = umask(0);
198
199     $wpcontent = get_option('wp-content_file_path')."$blog/";
200
201     //add_option('themes_file_path', $wpcontent."themes/");
202     //add_option('themes_web_path', get_option('siteurl')."/wp-content/$blog/themes/");
203     //add_option('plugins_file_path', $wpcontent."plugins/");
204     add_option('uploads_file_path', $wpcontent."uploads/");
205     add_option('uploads_web_path', get_option('fileupload_base_url')."/$blog/uploads/");
206
207     $stat = stat(get_option('wp-content_file_path'));
208     $mode = $stat['mode'] & 0000777// Get the permission bits.
209 /*    $mode = '0777';////////// this used to be necessary
210     $mode = octdec($mode);/// no more!!
211 */
212     mkdir($wpcontent);
213     chmod($wpcontent, $mode);
214
215     //mkdir(get_option('themes_file_path'));
216     //chmod(get_option('themes_file_path'), $mode);
217
218     //mkdir(get_option('plugins_file_path'));
219     //chmod(get_option('plugins_file_path'), $mode);
220
221     mkdir(get_option('uploads_file_path'));
222     chmod(get_option('uploads_file_path'), $mode);
223
224     umask($old_umask);
225
226     $slug = $wpdb->get_var("SELECT slug FROM $wpdb->blogs WHERE id = '$blog'");
227     if (SUBDOMAINS)
228         $home = 'http://' . $slug . '.' . MAINDOMAIN;
229     else
230         $home = get_option('siteurl') . '/' . $slug;
231     add_option('home', $home);
232     add_option('blogname', __('My Weblog'), __('Blog title'));
233     add_option('blogdescription', __('Just another Lyceum weblog'), __('Short tagline'));
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');
248     add_option('default_link_category', 0);
249     add_option('default_comment_status', 'open');
250     add_option('default_ping_status', 'open');
251     add_option('default_pingback_flag', 1);
252     add_option('default_post_edit_rows', 10);
253     add_option('posts_per_page', 10);
254     add_option('what_to_show', 'posts');
255     add_option('date_format', __('F j, Y'));
256     add_option('time_format', __('g:i a'));
257     add_option('links_updated_date_format', __('F j, Y g:i a'));
258     add_option('links_recently_updated_prepend', '<em>');
259     add_option('links_recently_updated_append', '</em>');
260     add_option('links_recently_updated_time', 120);
261     add_option('comment_moderation', 0);
262     add_option('moderation_notify', 1);
263     add_option('hack_file', 0);
264     add_option('blog_charset', 'UTF-8');
265     add_option('moderation_keys');
266     add_option('active_plugins');
267     add_option('category_base');
268     add_option('ping_sites', '');
269     add_option('advanced_edit', 0);
270     add_option('comment_max_links', 2);
271     add_option('gmt_offset', date('Z') / 3600);
272     // 1.5
273     add_option('default_email_category', 1, __('Posts by email go to this category'));
274     add_option('recently_edited');
275     add_option('use_linksupdate', 0);
276     add_option('template', 'default');
277     add_option('stylesheet', 'default');
278     add_option('comment_whitelist', 1);
279     add_option('page_uris');
280     add_option('blacklist_keys');
281     add_option('comment_registration', 0);
282     add_option('comment_priviliges', 0);
283     add_option('open_proxy_check', 1);
284     add_option('rss_language', 'en');
285     add_option('html_type', 'text/html');
286     // 1.5.1
287     add_option('use_trackback', 0);
288     // 2.0
289     add_option('default_role', 'subscriber');
290     add_option('rich_editing', 'true');
291     // 2.0.1
292     if ( ini_get('safe_mode') ) {
293         // Safe mode screws up mkdir(), so we must use a flat structure.
294         add_option('uploads_use_yearmonth_folders', 0);
295         add_option('upload_path', 'wp-content');
296     } else {
297         add_option('uploads_use_yearmonth_folders', 1);
298         add_option('upload_path', 'wp-content/uploads');
299     }
300
301 //    populate_roles();
302
303     // Set up a few options not to load by default
304     $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
305     foreach ($fatoptions as $fatoption) :
306         $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE blog='$blog' AND option_name = '$fatoption'");
307     endforeach;
308 }
309
310 function populate_system_options(){
311     global $optiondomain, $wp_db_version, $wp_rewrite;
312     $optiondomain = 'system';
313
314     $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
315     $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
316     $guessurl .= '/';
317
318     add_option('siteurl', $guessurl, __('Lyceum web address'));
319
320     add_option('new_users_can_blog', 0);
321     add_option('users_can_register', 1);
322     add_option('gzipcompression', 0);
323     add_option('db_version', $wp_db_version);
324     add_option('permalink_structure', DEFAULT_PS);
325     add_option('wp-content_file_path', ABSPATH . "wp-content/blogs/");//lyceum administrator is responsible for creating this directory, and setting its permissions. the permissions of all subdirectories and files will mimick it.
326     add_option('fileupload_base_url', get_option('siteurl') . '/wp-content/blogs/');
327     add_option('email_structure', "/.*/");
328     add_option('admin_ip', '127.0.0.1');
329     add_option('admin_ip', $_SERVER['REMOTE_ADDR']);
330     add_option('restrict_admin_ip', 0);
331     add_option('active_system_plugins');
332     add_option('blog_charset', 'UTF-8');
333     
334     //// this is a little ugly
335     $home_path = get_home_path();
336     $wp_rewrite->permalink_structure = DEFAULT_PS;
337     $rules = explode("\n", $wp_rewrite->mod_rewrite_rules());
338     insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
339     //////////////
340 }
341
342 function populate_roles() {
343     populate_roles_160();   
344 }
345
346 function populate_roles_160() {
347     global $wp_roles;
348     // Add roles
349     add_role('administrator', __('Administrator'));
350     add_role('editor', __('Editor'));
351     add_role('author', __('Author'));
352     add_role('contributor', __('Contributor'));
353     add_role('subscriber', __('Subscriber'));
354     
355     // Add caps for Administrator role
356     $role = get_role('administrator');
357     $role->add_cap('switch_themes');
358     $role->add_cap('edit_themes');
359     $role->add_cap('activate_plugins');
360     $role->add_cap('edit_plugins');
361     $role->add_cap('edit_users');
362     $role->add_cap('edit_files');
363     $role->add_cap('manage_options');
364     $role->add_cap('moderate_comments');
365     $role->add_cap('manage_categories');
366     $role->add_cap('manage_links');
367     $role->add_cap('upload_files');
368     $role->add_cap('import');
369     $role->add_cap('unfiltered_html');
370     $role->add_cap('edit_posts');
371     $role->add_cap('edit_others_posts');
372     $role->add_cap('edit_published_posts');
373     $role->add_cap('publish_posts');
374     $role->add_cap('edit_pages');
375     $role->add_cap('read');
376     $role->add_cap('level_10');
377     $role->add_cap('level_9');
378     $role->add_cap('level_8');
379     $role->add_cap('level_7');
380     $role->add_cap('level_6');
381     $role->add_cap('level_5');
382     $role->add_cap('level_4');
383     $role->add_cap('level_3');
384     $role->add_cap('level_2');
385     $role->add_cap('level_1');
386     $role->add_cap('level_0');
387     
388     // Add caps for Editor role
389     $role = get_role('editor');
390     $role->add_cap('moderate_comments');
391     $role->add_cap('manage_categories');
392     $role->add_cap('manage_links');
393     $role->add_cap('upload_files');
394     $role->add_cap('unfiltered_html');
395     $role->add_cap('edit_posts');
396     $role->add_cap('edit_others_posts');
397     $role->add_cap('edit_published_posts');
398     $role->add_cap('publish_posts');
399     $role->add_cap('edit_pages');
400     $role->add_cap('read');
401     $role->add_cap('level_7');
402     $role->add_cap('level_6');
403     $role->add_cap('level_5');
404     $role->add_cap('level_4');
405     $role->add_cap('level_3');
406     $role->add_cap('level_2');
407     $role->add_cap('level_1');
408     $role->add_cap('level_0');
409     
410     // Add caps for Author role
411     $role = get_role('author');
412     $role->add_cap('upload_files');
413     $role->add_cap('edit_posts');
414     $role->add_cap('edit_published_posts');
415     $role->add_cap('publish_posts');
416     $role->add_cap('read');
417     $role->add_cap('level_2');
418     $role->add_cap('level_1');
419     $role->add_cap('level_0');
420     
421     // Add caps for Contributor role
422     $role = get_role('contributor');
423     $role->add_cap('edit_posts');
424     $role->add_cap('read');
425     $role->add_cap('level_1');
426     $role->add_cap('level_0');
427     
428     // Add caps for Subscriber role
429     $role = get_role('subscriber');
430     $role->add_cap('read');
431     $role->add_cap('level_0');
432 }
433
434 ?>
435
Note: See TracBrowser for help on using the browser.
Log in with username/password: lyceum/lyceum