<commit_before><?php

/**
 * Install script that handles sanity checks and sets up the database
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  1997-Present <NAME>
 * @package    Wordcraft
 * @license    http://wordcraft.googlecode.com/files/license.txt
 * @link       http://wordcraft.googlecode.com/
 *
 */

define("WC_INSTALLING", true);

// do this so session check will not fail
ob_start();

include_once "../include/common.php";
include_once "./admin_functions.php";

$steps = array("", "check", "database", "account", "settings", "done");

$step = (empty($_POST["step"])) ? "" : $_POST["step"];

if(!in_array($step, $steps)){
    wc_admin_error("Invalid step $step for install program.");
}

$continue = true;

$WHEREAMI = "Install";

include_once "./header.php";
?>

<h1>Welcome to the Wordcraft installer!</h1>

<?php if(empty($step)){ ?>

    <p>Here is what we are going to do.</p>

    <ol>
        <li>Check for requirements</li>
        <li>Setup the database</li>
        <li>Install default settings</li>
        <li>Create your first account</li>
    </ol>

    <?php $step = "check"; ?>

<?php } elseif($step=="check") { ?>

    <?php

    if(ini_get("safe_mode")!=0 || ini_get("open_basedir")!=""){
        if(!defined("WC")){
            $show_stoppers[] = "Safe mode is enabled on this server.  This is includes the open_basedir option.  This will prevent Wordcraft from working.  Safe mode is no longer recommended by the PHP team.  You should disable it.";
        } else {
            $warning[] = "Safe mode is enabled on this server.  This may cause problems that prevent Wordcraft from working.  Safe mode is no longer recommended by the PHP team.  You should disable it.";
        }
    } else {
        $ok[] = "Safe mode check passed.";
    }

    if(!function_exists("mysqli_connect")){
        $show_stoppers[] = "The MySQL Improved (mysqli) extension is not available on this server.  You will need to have this installed to use Wordcraft.";
    } else {
        $ok[] = "MySQL check passed.";
    }

    if(!function_exists("session_start") || !session_start()){
        $show_stoppers[] = "PHP Sessions are not available on this server.  This is required by Wordcraft.";
    } else {
        $ok[] = "Sessions check passed.";
    }

    if(get_magic_quotes_runtime()){
        $show_stoppers[] = "Magic quotes runtime has been detected.  This is a horrible idea.  It is such a bad idea that PHP has removed it in PHP6. Wordcraft will not work with this feature on.";
    } else {
        $ok[] = "Magic quotes check passed.";
    }

    if (!defined("PHP_VERSION") || version_compare(PHP_VERSION, '5.0.5', '<')) {
        $show_stoppers[] = "PHP version 5.0.5 or higher is required for Wordcraft.  Your server is using PHP ".phpversion().".";
    } elseif(version_compare(PHP_VERSION, '5.2.2', '<')) {
        $warnings[] = "It is recommended to use PHP 5.2.2 or higher.  Your server is using PHP ".PHP_VERSION.".";
    }

    $message = "";

    if(isset($show_stoppers)){
        $message.= "Some major problems are preventing us from continuing.<br><span style=\"color: red;\">";
        $message.= implode("<br>", $show_stoppers);
        $message.= "</span>";
        $continue = false;
    } else {
        $step = "database";
    }

    if(isset($ok)){
        $message.= "Good news, these items are just fine.<br><span style=\"color: green;\">";
        $message.= implode("<br>", $ok);
        $message.= "</span>";
        if(empty($show_stoppers) && empty($warnings)){
            $message.="<br>Hit continue and we can keep going.";
        }
    }

    if(isset($warnings)){
        $message.= "Hmm, there are a few things that may be a problem for Wordcraft.<br><span style=\"color: orange;\">";
        $message.= implode("<br>", $warnings);
        $message.= "</span><br>If you think you can live with these problems, go ahead and continue.";
    }


    ?>

<?php } elseif($step=="database") { ?>

    <?php

        $WCDB->report_errors(false);

        $conn_check = $WCDB->check_connection();

        if($conn_check !== true){

            $message = "Oops!  The connection to your database failed.  Please check your database settings in config.php and try again.  The database server said: '$conn_check'.";
            $continue = false;

        } else {

            $schema = file_get_contents("../include/schema.sql");

            $schema = str_replace("{PREFIX}", $WC["db_prefix"], $schema);

            preg_match_all('!CREATE.+?;!ism', $schema, $matches);

            $WCDB->query("BEGIN");

            foreach($matches[0] as $sql){
                // trim off the ;
                $sql = substr($sql, 0, -1);

                $success = $WCDB->query($sql);

                if(!$success){
                    $message = "Oops! There was an error creating some of the tables for your database.  The server said: '".$WCDB->last_error."'.";
                    $continue = false;
                    $WCDB->query("ROLLBACK");
                    break;
                }

            }

            if($continue){
                $WCDB->query("COMMIT");
                $message = "Great!  The database was created without error.  Next we will create your first user account.  Go ahead, click continue.";
            }

        }

        if($continue) $step = "settings";
    ?>

<?php } elseif($step=="settings") { ?>

    <?php
        $default_settings = array(
           "use_akismet" => 0,<commit_msg>set spam score use to default to on for new installs<commit_after><?php

/**
 * Install script that handles sanity checks and sets up the database
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  1997-Present <NAME>
 * @package    Wordcraft
 * @license    http://wordcraft.googlecode.com/files/license.txt
 * @link       http://wordcraft.googlecode.com/
 *
 */

define("WC_INSTALLING", true);

// do this so session check will not fail
ob_start();

include_once "../include/common.php";
include_once "./admin_functions.php";

$steps = array("", "check", "database", "account", "settings", "done");

$step = (empty($_POST["step"])) ? "" : $_POST["step"];

if(!in_array($step, $steps)){
    wc_admin_error("Invalid step $step for install program.");
}

$continue = true;

$WHEREAMI = "Install";

include_once "./header.php";
?>

<h1>Welcome to the Wordcraft installer!</h1>

<?php if(empty($step)){ ?>

    <p>Here is what we are going to do.</p>

    <ol>
        <li>Check for requirements</li>
        <li>Setup the database</li>
        <li>Install default settings</li>
        <li>Create your first account</li>
    </ol>

    <?php $step = "check"; ?>

<?php } elseif($step=="check") { ?>

    <?php

    if(ini_get("safe_mode")!=0 || ini_get("open_basedir")!=""){
        if(!defined("WC")){
            $show_stoppers[] = "Safe mode is enabled on this server.  This is includes the open_basedir option.  This will prevent Wordcraft from working.  Safe mode is no longer recommended by the PHP team.  You should disable it.";
        } else {
            $warning[] = "Safe mode is enabled on this server.  This may cause problems that prevent Wordcraft from working.  Safe mode is no longer recommended by the PHP team.  You should disable it.";
        }
    } else {
        $ok[] = "Safe mode check passed.";
    }

    if(!function_exists("mysqli_connect")){
        $show_stoppers[] = "The MySQL Improved (mysqli) extension is not available on this server.  You will need to have this installed to use Wordcraft.";
    } else {
        $ok[] = "MySQL check passed.";
    }

    if(!function_exists("session_start") || !session_start()){
        $show_stoppers[] = "PHP Sessions are not available on this server.  This is required by Wordcraft.";
    } else {
        $ok[] = "Sessions check passed.";
    }

    if(get_magic_quotes_runtime()){
        $show_stoppers[] = "Magic quotes runtime has been detected.  This is a horrible idea.  It is such a bad idea that PHP has removed it in PHP6. Wordcraft will not work with this feature on.";
    } else {
        $ok[] = "Magic quotes check passed.";
    }

    if (!defined("PHP_VERSION") || version_compare(PHP_VERSION, '5.0.5', '<')) {
        $show_stoppers[] = "PHP version 5.0.5 or higher is required for Wordcraft.  Your server is using PHP ".phpversion().".";
    } elseif(version_compare(PHP_VERSION, '5.2.2', '<')) {
        $warnings[] = "It is recommended to use PHP 5.2.2 or higher.  Your server is using PHP ".PHP_VERSION.".";
    }

    $message = "";

    if(isset($show_stoppers)){
        $message.= "Some major problems are preventing us from continuing.<br><span style=\"color: red;\">";
        $message.= implode("<br>", $show_stoppers);
        $message.= "</span>";
        $continue = false;
    } else {
        $step = "database";
    }

    if(isset($ok)){
        $message.= "Good news, these items are just fine.<br><span style=\"color: green;\">";
        $message.= implode("<br>", $ok);
        $message.= "</span>";
        if(empty($show_stoppers) && empty($warnings)){
            $message.="<br>Hit continue and we can keep going.";
        }
    }

    if(isset($warnings)){
        $message.= "Hmm, there are a few things that may be a problem for Wordcraft.<br><span style=\"color: orange;\">";
        $message.= implode("<br>", $warnings);
        $message.= "</span><br>If you think you can live with these problems, go ahead and continue.";
    }


    ?>

<?php } elseif($step=="database") { ?>

    <?php

        $WCDB->report_errors(false);

        $conn_check = $WCDB->check_connection();

        if($conn_check !== true){

            $message = "Oops!  The connection to your database failed.  Please check your database settings in config.php and try again.  The database server said: '$conn_check'.";
            $continue = false;

        } else {

            $schema = file_get_contents("../include/schema.sql");

            $schema = str_replace("{PREFIX}", $WC["db_prefix"], $schema);

            preg_match_all('!CREATE.+?;!ism', $schema, $matches);

            $WCDB->query("BEGIN");

            foreach($matches[0] as $sql){
                // trim off the ;
                $sql = substr($sql, 0, -1);

                $success = $WCDB->query($sql);

                if(!$success){
                    $message = "Oops! There was an error creating some of the tables for your database.  The server said: '".$WCDB->last_error."'.";
                    $continue = false;
                    $WCDB->query("ROLLBACK");
                    break;
                }

            }

            if($continue){
                $WCDB->query("COMMIT");
                $message = "Great!  The database was created without error.  Next we will create your first user account.  Go ahead, click continue.";
            }

        }

        if($continue) $step = "settings";
    ?>

<?php } elseif($step=="settings") { ?>

    <?php
        $default_settings = array(
           "use_spam_score" => 1,
           "use_akismet" => 0,
{'fraction_non_alphanumeric': 0.1549270238419001, 'fraction_numerical': 0.004442027014776539, 'mean_word_length': 2.435689816256618, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5477097', 'n_tokens_mistral': 3335, 'n_tokens_neox': 3224, 'n_words': 999}