Make WordPress Core

Changeset 3670


Ignore:
Timestamp:
03/31/2006 08:07:39 AM (19 years ago)
Author:
ryan
Message:

Pluggable install functions. fixes #2616

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/install.php

    r3604 r3670  
    66require_once('../wp-config.php');
    77require_once('./upgrade-functions.php');
    8 
    9 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
    10 $guessurl = str_replace('/wp-admin/install.php?step=2', '', $schema . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) );
    118
    129if (isset($_GET['step']))
     
    7875<?php
    7976// Let's check to make sure WP isn't already installed.
    80 $wpdb->hide_errors();
    81 $installed = $wpdb->get_results("SELECT * FROM $wpdb->users");
    82 if ($installed) die('<h1>'.__('Already Installed').'</h1><p>'.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'</p></body></html>');
    83 $wpdb->show_errors();
     77if ( is_blog_installed() ) die('<h1>'.__('Already Installed').'</h1><p>'.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'</p></body></html>');
    8478
    8579switch($step) {
     
    142136flush();
    143137
    144 // Set everything up
    145 wp_cache_flush();
    146 make_db_current_silent();
    147 populate_options();
    148 populate_roles();
    149 
    150 update_option('blogname', $weblog_title);
    151 update_option('admin_email', $admin_email);
    152 update_option('blog_public', $public);
    153 // If not a public blog, don't ping.
    154 if ( ! $public )
    155     update_option('default_pingback_flag', 0);
    156 
    157 // Default category
    158 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
    159 
    160 // Default link category
    161 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, link_count, category_description) VALUES ('0', '".$wpdb->escape(__('Blogroll'))."', '".sanitize_title(__('Blogroll'))."', '7', '')");
    162 
    163 // Now drop in some default links
    164 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://blogs.linux.ie/xeer/', 'Donncha', 0, 'http://blogs.linux.ie/xeer/feed/', '');");
    165 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (1, 2)" );
    166 
    167 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 0, 'http://zengun.org/weblog/feed/', '');");
    168 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (2, 2)" );
    169 
    170 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 0, 'http://boren.nu/feed/', '');");
    171 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (3, 2)" );
    172 
    173 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 0, 'http://xml.photomatt.net/feed/', '');");
    174 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (4, 2)" );
    175 
    176 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 0, 'http://zed1.com/journalized/feed/', '');");
    177 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (5, 2)" );
    178 
    179 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 0, 'http://www.alexking.org/blog/wp-rss2.php', '');");
    180 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (6, 2)" );
    181 
    182 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 0, 'http://dougal.gunters.org/feed/', '');");
    183 $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (7, 2)" );
    184 
    185 // First post
    186 $now = date('Y-m-d H:i:s');
    187 $now_gmt = gmdate('Y-m-d H:i:s');
    188 $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");
    189 
    190 $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
    191 
    192 // Default comment
    193 $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.'))."')");
    194 
    195 // First Page
    196 
    197 $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
    198 $wp_rewrite->flush_rules();
    199 
    200 // Set up admin user
    201 $random_password = substr(md5(uniqid(microtime())), 0, 6);
    202 $display_name_array = explode('@', $admin_email);
    203 $display_name = $display_name_array[0];
    204 $wpdb->query("INSERT INTO $wpdb->users (ID, user_login, user_pass, user_email, user_registered, display_name, user_nicename) VALUES ( '1', 'admin', MD5('$random_password'), '$admin_email', NOW(), '$display_name', 'admin')");
    205 $wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$wpdb->prefix}user_level', '10');");
    206 $admin_caps = serialize(array('administrator' => true));
    207 $wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$wpdb->prefix}capabilities', '{$admin_caps}');");
    208 
    209 $message_headers = 'From: ' . $weblog_title . ' <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
    210 $message = sprintf(__("Your new WordPress blog has been successfully set up at:
    211 
    212 %1\$s
    213 
    214 You can log in to the administrator account with the following information:
    215 
    216 Username: admin
    217 Password: %2\$s
    218 
    219 We hope you enjoy your new weblog. Thanks!
    220 
    221 --The WordPress Team
    222 http://wordpress.org/
    223 "), $guessurl, $random_password);
    224 
    225 @wp_mail($admin_email, __('New WordPress Blog'), $message, $message_headers);
    226 
    227 wp_cache_flush();
     138$result = wp_install($weblog_title, __('admin'), $admin_email, $public);
     139extract($result);
    228140?>
    229141
    230142<p><em><?php _e('Finished!'); ?></em></p>
    231143
    232 <p><?php printf(__('Now you can <a href="%1$s">log in</a> with the <strong>username</strong> "<code>admin</code>" and <strong>password</strong> "<code>%2$s</code>".'), '../wp-login.php', $random_password); ?></p>
     144<p><?php printf(__('Now you can <a href="%1$s">log in</a> with the <strong>username</strong> "<code>admin</code>" and <strong>password</strong> "<code>%2$s</code>".'), '../wp-login.php', $password); ?></p>
    233145<p><?php _e('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you. If you lose it, you will have to delete the tables from the database yourself, and re-install WordPress. So to review:'); ?>
    234146</p>
    235147<dl>
    236148<dt><?php _e('Username'); ?></dt>
    237 <dd><code>admin</code></dd>
     149<dd><code><?php _e('admin') ?></code></dd>
    238150<dt><?php _e('Password'); ?></dt>
    239 <dd><code><?php echo $random_password; ?></code></dd>
     151<dd><code><?php echo $password; ?></code></dd>
    240152    <dt><?php _e('Login address'); ?></dt>
    241153<dd><a href="../wp-login.php">wp-login.php</a></dd>
  • trunk/wp-admin/upgrade-functions.php

    r3635 r3670  
    11<?php
    22
     3if ( file_exists(ABSPATH . 'wp-content/install.php') )
     4    require (ABSPATH . 'wp-content/install.php');
    35require_once(ABSPATH . '/wp-admin/admin-functions.php');
    46require_once(ABSPATH . '/wp-admin/admin-db.php');
    57require_once(ABSPATH . '/wp-admin/upgrade-schema.php');
     8require_once(ABSPATH . '/wp-includes/registration-functions.php');
     9
     10if ( !function_exists('wp_install') ) :
     11function wp_install($blog_title, $user_name, $user_email, $public, $meta='') {
     12    global $wp_rewrite;
     13
     14    wp_cache_flush();
     15    make_db_current_silent();
     16    populate_options();
     17    populate_roles();
     18
     19    update_option('blogname', $blog_title);
     20    update_option('admin_email', $user_email);
     21    update_option('blog_public', $public);
     22    $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
     23    $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     24    update_option('siteurl', $guessurl);
     25
     26    // If not a public blog, don't ping.
     27    if ( ! $public )
     28        update_option('default_pingback_flag', 0);
     29
     30    // Create default user.
     31    $random_password = substr(md5(uniqid(microtime())), 0, 6);
     32    $user_id = wp_create_user($user_name, $random_password, $user_email);
     33    $user = new WP_User($user_id);
     34    $user->set_role('administrator');
     35
     36    wp_install_defaults($user_id);
     37
     38    $wp_rewrite->flush_rules();
     39
     40    wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
     41
     42    wp_cache_flush();
     43
     44    return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
     45}
     46endif;
     47
     48if ( !function_exists('wp_install_defaults') ) :
     49function wp_install_defaults($user_id) {
     50    global $wpdb;
     51
     52    // Default category
     53    $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
     54
     55    // Default link category
     56    $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, link_count, category_description) VALUES ('0', '".$wpdb->escape(__('Blogroll'))."', '".sanitize_title(__('Blogroll'))."', '7', '')");
     57
     58    // Now drop in some default links
     59    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://blogs.linux.ie/xeer/', 'Donncha', 0, 'http://blogs.linux.ie/xeer/feed/', '');");
     60    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (1, 2)" );
     61
     62    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 0, 'http://zengun.org/weblog/feed/', '');");
     63    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (2, 2)" );
     64
     65    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 0, 'http://boren.nu/feed/', '');");
     66    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (3, 2)" );
     67
     68    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 0, 'http://xml.photomatt.net/feed/', '');");
     69    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (4, 2)" );
     70
     71    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 0, 'http://zed1.com/journalized/feed/', '');");
     72    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (5, 2)" );
     73
     74    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 0, 'http://www.alexking.org/blog/wp-rss2.php', '');");
     75    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (6, 2)" );
     76
     77    $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 0, 'http://dougal.gunters.org/feed/', '');");
     78    $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (7, 2)" );
     79
     80    // First post
     81    $now = date('Y-m-d H:i:s');
     82    $now_gmt = gmdate('Y-m-d H:i:s');
     83    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");
     84
     85    $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
     86
     87    // Default comment
     88    $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.'))."')");
     89
     90    // First Page
     91
     92    $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
     93}
     94endif;
     95
     96if ( !function_exists('wp_new_blog_notification') ) :
     97function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
     98    $user = new WP_User($user_id);
     99    $email = $user->user_email;
     100    $name = $user->user_login;
     101    $message_headers = 'From: ' . $blog_title . ' <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
     102    $message = sprintf(__("Your new WordPress blog has been successfully set up at:
     103
     104%1\$s
     105
     106You can log in to the administrator account with the following information:
     107
     108Username: %2\$s
     109Password: %3\$s
     110
     111We hope you enjoy your new weblog. Thanks!
     112
     113--The WordPress Team
     114http://wordpress.org/
     115"), $blog_url, $name, $password);
     116
     117    @wp_mail($email, __('New WordPress Blog'), $message, $message_headers);
     118}
     119endif;
     120
     121if ( !function_exists('wp_upgrade') ) :
     122function wp_upgrade() {
     123    global $wp_current_db_version, $wp_db_version;
     124
     125    $wp_current_db_version = __get_option('db_version');
     126
     127    // We are up-to-date.  Nothing to do.
     128    if ( $wp_db_version == $wp_current_db_version )
     129        return;
     130
     131    wp_cache_flush();
     132    make_db_current_silent();
     133    upgrade_all();
     134    wp_cache_flush();   
     135}
     136endif;
     137
    6138// Functions to be called in install and upgrade scripts
    7139function upgrade_all() {
  • trunk/wp-admin/upgrade.php

    r3517 r3670  
    7676
    7777    case 1:
    78     wp_cache_flush();
    79     make_db_current_silent();
    80     upgrade_all();
    81     wp_cache_flush();
     78    wp_upgrade();
    8279
    8380    if ( empty( $_GET['backto'] ) )
  • trunk/wp-includes/functions.php

    r3666 r3670  
    22672267    load_template(ABSPATH . 'wp-atom.php');
    22682268}
     2269
     2270function is_blog_installed() {
     2271    global $wpdb;
     2272    $wpdb->hide_errors();
     2273    $installed = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
     2274    $wpdb->show_errors();
     2275    return $installed;
     2276}
    22692277?>
  • trunk/wp-settings.php

    r3639 r3670  
    120120require_once (ABSPATH . WPINC . '/wp-l10n.php');
    121121
    122 $wpdb->hide_errors();
    123 $db_check = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
    124 if ( !$db_check && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
     122if ( !is_blog_installed() && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
    125123    if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
    126124        $link = 'install.php';
Note: See TracChangeset for help on using the changeset viewer.