<?php
/**
 * Tafuta na tengeneza faili la wp-config.php.
 *
 * Ruhusa la dairektori ni lazima liruhusu kuandika ili faili la wp-config.php liweze kutengenezwa kwa kutumia nakala hii.
 *
 * @package WordPress
 * @subpackage Administration
 */

/**
 * We are installing.
 *
 * @package WordPress
 */
define('WP_INSTALLING', true);

/**
 * We are blissfully unaware of anything.
 */
define('WP_SETUP_CONFIG', true);

/**
 * Disable error reporting
 *
 * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
 */
error_reporting(0);

/**#@+
 * Hivi vitu vitatu vinahitajika kuturuhusu kutumia require_wp_db() ili tuweze kupatika klasi la datamakalio wakati kuwa inafahamu wp-content/db.php.
 * @ignore
 */
define('ABSPATH', dirname(dirname(__FILE__)).'/');
define('WPINC', 'wp-includes');
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
define('WP_DEBUG', false);
/**#@-*/

require_once(ABSPATH . WPINC . '/load.php');
require_once(ABSPATH . WPINC . '/compat.php');
require_once(ABSPATH . WPINC . '/functions.php');
require_once(ABSPATH . WPINC . '/classes.php');
require_once(ABSPATH . WPINC . '/version.php');

if (!file_exists(ABSPATH . 'wp-config-sample.php'))
	wp_die('Samahani,Nahitaji faili la wp-config-sample.php ili niweze kulifanyia kazi.Tafadhali pakia upya faili hilo kwenye sadinisho lako la WordPress.');

$configFile = file(ABSPATH . 'wp-config-sample.php');

// Check if wp-config.php has been created
if (file_exists(ABSPATH . 'wp-config.php'))
	wp_die("<p>Faili la 'wp-config.php' lipo tayari. Kama unataka kuseti upya konfigaresheni zozote ndani ya faili hili, tafadhali lifute kwanza. Unaweza kujaribu <a href='install.php'>sadinisha sasa</a>.</p>");

// Check if wp-config.php exists above the root directory but is not part of another install
if (file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php'))
	wp_die("<p>The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.</p>");

if ( version_compare( '4.3', phpversion(), '>' ) )
	wp_die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %s but WordPress requires at least 4.3.'/*/WP_I18N_OLD_PHP*/, phpversion() ) );

if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
	wp_die( /*WP_I18N_OLD_MYSQL*/'Sadinisho la PHP linaonekana kukosa ongezo la MySQL ambayo inahitajiwa na WordPress.'/*/WP_I18N_OLD_MYSQL*/ );

if (isset($_GET['step']))
	$step = $_GET['step'];
else
	$step = 0;

/**
 * Display setup wp-config.php file header.
 *
 * @ignore
 * @since 2.3.0
 * @package WordPress
 * @subpackage Installer_WP_Config
 */
function display_header() {
	header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WordPress &rsaquo; Setup Configuration File</title>
<link rel="stylesheet" href="css/install.css" type="text/css" />

</head>
<body>
<h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
<?php
}//end function display_header();

switch($step) {
	case 0:
		display_header();
?>

<p>Karibu WordPress. Kabla hujaanza, kwanza unahitaji habari za datamakalio. Utahitajika kujua vitu vifuatavyo kabla ya kuendelea.</p>
<ol>
	<li>Jina la Datamakalio</li>
	<li>Jina la mtumiaji wa db</li>
	<li>Neno la siri la db</li>
	<li>Jina la Hosti</li>
	<li>Kianzilishi cha Meza (kama unataka kutumia WordPress nyingi kwenye datamakalio moja) </li>
</ol>
<p><strong>Kama kwa sababu yoyote operesheni hii ya utengenezaji faili kiautomatiki itashindikana, usijali.Hii operesheni lengo lake ni kujaza habari za datamakalio, fungua faili la konfigaresheni <code>wp-config-sample.php</code> kwa kutumia edita ya maandishi, na ujaze habari hizo, halafu hifadhi kwa jina la <code>wp-config.php</code>. </strong></p>
<p>Kivyovyote vile vitu hivi umepewa na provaida wa mtandao wako. Kama huna habari hizo, utahitajika kuwasiliana nao kabla hujaendelea.Kama umemaliza&hellip;</p>

<p class="step"><a href="setup-config.php?step=1" class="button">Haya twende!</a></p>
<?php
	break;

	case 1:
		display_header();
	?>
<form method="post" action="setup-config.php?step=2">
	<p>Hapa chini ingiza habari za mawasiliano za datamakalio. Kama huna uhakika wasiliana na provaida wa wako. </p>
	<table class="form-table">
		<tr>
			<th scope="row"><label for="dbname">Database Name</label></th>
			<td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
			<td>Jina la datamakalio ambalo WP itatumia. </td>
		</tr>
		<tr>
			<th scope="row"><label for="uname">Jina la mtumiaji </label></th>
			<td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
			<td>Jina la utumiaji MySQL</td>
		</tr>
		<tr>
			<th scope="row"><label for="pwd">Password</label></th>
			<td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
			<td>...na neno la siri la MySQL.</td>
		</tr>
		<tr>
			<th scope="row"><label for="dbhost">Hosti wa Datamakalio</label></th>
			<td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
			<td>kuna 99% ya uwezekano kwamba huhitaji kubadilisha hii.</td>
		</tr>
		<tr>
			<th scope="row"><label for="prefix">Table Prefix</label></th>
			<td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
			<td>Kama unahitaji kutumia sadinisho nyingi za WordPress kwenye datamakalio moja, badilisha hii.</td>
		</tr>
	</table>
	<?php if ( isset( $_GET['noapi'] ) ) { ?><input name="noapi" type="hidden" value="true" /><?php } ?>
	<p class="step"><input name="submit" type="submit" value="Peleka" class="button" /></p>
</form>
<?php
	break;

	case 2:
	$dbname  = trim($_POST['dbname']);
	$uname   = trim($_POST['uname']);
	$passwrd = trim($_POST['pwd']);
	$dbhost  = trim($_POST['dbhost']);
	$prefix  = trim($_POST['prefix']);
	if ( empty($prefix) )
		$prefix = 'wp_';

	// Validate $prefix: it can only contain letters, numbers and underscores
	if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
		wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>HITILAFU</strong>: "Table Prefix" inaweza kuwa na namabari, herufi, na underscores.'/*/WP_I18N_BAD_PREFIX*/ );

	// Test the db connection.
	/**#@+
	 * @ignore
	 */
	define('DB_NAME', $dbname);
	define('DB_USER', $uname);
	define('DB_PASSWORD', $passwrd);
	define('DB_HOST', $dbhost);
	/**#@-*/

	// We'll fail here if the values are no good.
	require_wp_db();
	if ( !empty($wpdb->error) )
		wp_die($wpdb->error->get_error_message());

	// Fetch or generate keys and salts.
	$no_api = isset( $_POST['noapi'] );
	require_once( ABSPATH . WPINC . '/plugin.php' );
	require_once( ABSPATH . WPINC . '/l10n.php' );
	require_once( ABSPATH . WPINC . '/pomo/translations.php' );
	if ( ! $no_api ) {
		require_once( ABSPATH . WPINC . '/class-http.php' );
		require_once( ABSPATH . WPINC . '/http.php' );
		wp_fix_server_vars();
		/**#@+
		 * @ignore
		 */
		function get_bloginfo() {
			return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) );
		}
		/**#@-*/
		$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
	}

	if ( $no_api || is_wp_error( $secret_keys ) ) {
		$secret_keys = array();
		require_once( ABSPATH . WPINC . '/pluggable.php' );
		for ( $i = 0; $i < 8; $i++ ) {
			$secret_keys[] = wp_generate_password( 64, true, true );
		}
	} else {
		$secret_keys = explode( "\n", wp_remote_retrieve_body( $secret_keys ) );
		foreach ( $secret_keys as $k => $v ) {
			$secret_keys[$k] = substr( $v, 28, 64 );
		}
	}
	$key = 0;

	foreach ($configFile as $line_num => $line) {
		switch (substr($line,0,16)) {
			case "define('DB_NAME'":
				$configFile[$line_num] = str_replace('jina-la-datamakalio', $dbname, $line);
				break;
			case "define('DB_USER'":
				$configFile[$line_num] = str_replace('jina-la-mtumiaji', $uname, $line);
				break;
			case "define('DB_PASSW":
				$configFile[$line_num] = str_replace('neno-la-siri', $passwrd, $line);
				break;
			case "define('DB_HOST'":
				$configFile[$line_num] = str_replace('localhost', $dbhost, $line);
				break;
			case '$table_prefix  =':
				$configFile[$line_num] = str_replace('wp_', $prefix, $line);
				break;
			case "define('AUTH_KEY":
			case "define('SECURE_A":
			case "define('LOGGED_I":
			case "define('NONCE_KE":
			case "define('AUTH_SAL":
			case "define('SECURE_A":
			case "define('LOGGED_I":
			case "define('NONCE_SA":
				$configFile[$line_num] = str_replace('ingiza neno lako la siri hapa', $secret_keys[$key++], $line );
				break;
		}
	}
	if ( ! is_writable(ABSPATH) ) :
		display_header();
?>
<p>Samahani, imeshindikana kuandika kwenye faili <code>wp-config.php</code> .</p>
<p>Unaweza kulitengeneza mwenyewe <code>wp-config.php</code> kwa mkono na kupasti maandishi yafuatayo kwenye faili hilo.</p>
<textarea cols="98" rows="15" class="code"><?php
		foreach( $configFile as $line ) {
			echo htmlentities($line, ENT_COMPAT, 'UTF-8');
		}
?></textarea>
<p>Mara tuu baada ya kumaliza kufanya hivyo, bonyeza, "Endesha Instali".</p>
<p class="step"><a href="install.php" class="button">Endesha Instali</a></p>
<?php
	else :
		$handle = fopen(ABSPATH . 'wp-config.php', 'w');
		foreach( $configFile as $line ) {
			fwrite($handle, $line);
		}
		fclose($handle);
		chmod(ABSPATH . 'wp-config.php', 0666);
		display_header();
?>
<p>Kulaleki!Umefanikiwa hatua hii ya usadinishaji.WordPress inaweza kuwasiliana na datamakalio. Kama uko tayari, sasa nenda&hellip;</p>

<p class="step"><a href="install.php" class="button">Anza kusadinisha</a></p>
<?php
	endif;
	break;
}
?>
</body>
</html>
