<commit_before><?php

//xdebug_start_profiling();

#error_reporting(E_ALL);

class TikiSetup {
	function os() {
		static $os;
		
		if (!isset($os)) {
			if (substr(PHP_OS, 0, 3) == 'WIN') {
				$os = 'windows';
			} else {
				$os = 'unix';
			}
		}
		
		return $os;
	}

	function isWindows() {
		static $windows;
		
		if (!isset($windows)) {
			$windows = substr(PHP_OS, 0, 3) == 'WIN';
		}
		
		return $windows;
	}
	
	function tempdir() {
		static $tempdir;
		
		if (!$tempdir) {
			$tempdir = dirname(tempnam(false, ''));
		}
		
		return $tempdir;
	}
	
	function check() {
		static $checked;
		
		if ($checked) {
			return;
		}
			
		$checked = true;
		
		$errors = '';

		$docroot = dirname($_SERVER['SCRIPT_FILENAME']);

		if (ini_get('session.save_handler') == 'files') {
			$save_path = ini_get('session.save_path');

			if (!is_dir($save_path)) {
				$errors .= "The directory '$save_path' does not exist or PHP is not allowed to access it (check open_basedir entry in php.ini).\n";
			} else 
			if (!is_writeable($save_path)) {
				$errors .= "The directory '$save_path' is not writeable.\n";
			}

			if ($errors) {
				$save_path = TikiSetup::tempdir();
				if (is_dir($save_path) && is_writeable($save_path)) {
					ini_set('session.save_path', $save_path);
					$errors = '';
				}
			}
		}

		$wwwuser	= '';
		$wwwgroup	= '';
		
		if (TikiSetup::isWindows()) {
			$wwwuser	= 'SYSTEM';
			$wwwgroup	= 'SYSTEM';
		}

		if (function_exists('posix_getuid')) {
			$user		= @posix_getpwuid(@posix_getuid());
			$group		= @posix_getpwuid(@posix_getgid());
			$wwwuser	= $user ? $user['name'] : false;
			$wwwgroup	= $group ? $group['name'] : false;
		}

		if (!$wwwuser) {
			$wwwuser = 'nobody (or the user account the web server is running under)';
		}
		if (!$wwwgroup) {
			$wwwgroup = 'nobody (or the group account the web server is running under)';
		}
     
		static $dirs = array(
			'backups',
			'dump',
			'img/wiki',
			'img/wiki_up',
			'modules/cache',
			'temp',
			'templates_c', 
		);
		
		foreach ($dirs as $dir) {
			if (!is_dir($dir)) {
				$errors .= "The directory '$docroot/$dir' does not exist.\n";
			} else 
			if (!is_writeable($dir)) {
				$errors .= "The directory '$docroot/$dir' is not writeable by $wwwuser.\n";
			}
		}
		
		if ($errors) {
			print "
<pre>
Your tiki is not properly set up:

$errors
";

		if (!TikiSetup::isWindows()) {
			print "
To set up your tiki, log in to the system running tiki,
and type the following commands:

\$ bash
\$ cd $docroot
\$ chmod +x setup.sh
\$ su -c './setup.sh $wwwuser'

or if you can't become root, but are a member of the group $wwwgroup:

\$ bash
\$ cd $docroot
\$ chmod +x setup.sh
\$ ./setup.sh mylogin $wwwgroup

If you have problems accessing a directory, check open_basedir entry in php.ini or apache.conf.

Once you have executed these commands, this message will disappear!

	";
		}
		
		}
	}
}

TikiSetup::check();

$tmpDir = TikiSetup::tempdir();

class timer
        {
        function parseMicro($micro)
                {list($micro,$sec)=explode(' ',microtime()); return $sec+$micro;}
        function start($timer='default')
                {$this->timer[$timer]=$this->parseMicro(microtime());}
        function stop($timer='default')
                {return $this->current($timer);}<commit_msg>if setup prerequisites not met, don't continue past outputting error message<commit_after><?php

//xdebug_start_profiling();

#error_reporting(E_ALL);

class TikiSetup {
	function os() {
		static $os;
		
		if (!isset($os)) {
			if (substr(PHP_OS, 0, 3) == 'WIN') {
				$os = 'windows';
			} else {
				$os = 'unix';
			}
		}
		
		return $os;
	}

	function isWindows() {
		static $windows;
		
		if (!isset($windows)) {
			$windows = substr(PHP_OS, 0, 3) == 'WIN';
		}
		
		return $windows;
	}
	
	function tempdir() {
		static $tempdir;
		
		if (!$tempdir) {
			$tempdir = dirname(tempnam(false, ''));
		}
		
		return $tempdir;
	}
	
	function check() {
		static $checked;
		
		if ($checked) {
			return;
		}
			
		$checked = true;
		
		$errors = '';

		$docroot = dirname($_SERVER['SCRIPT_FILENAME']);

		if (ini_get('session.save_handler') == 'files') {
			$save_path = ini_get('session.save_path');

			if (!is_dir($save_path)) {
				$errors .= "The directory '$save_path' does not exist or PHP is not allowed to access it (check open_basedir entry in php.ini).\n";
			} else 
			if (!is_writeable($save_path)) {
				$errors .= "The directory '$save_path' is not writeable.\n";
			}

			if ($errors) {
				$save_path = TikiSetup::tempdir();
				if (is_dir($save_path) && is_writeable($save_path)) {
					ini_set('session.save_path', $save_path);
					$errors = '';
				}
			}
		}

		$wwwuser	= '';
		$wwwgroup	= '';
		
		if (TikiSetup::isWindows()) {
			$wwwuser	= 'SYSTEM';
			$wwwgroup	= 'SYSTEM';
		}

		if (function_exists('posix_getuid')) {
			$user		= @posix_getpwuid(@posix_getuid());
			$group		= @posix_getpwuid(@posix_getgid());
			$wwwuser	= $user ? $user['name'] : false;
			$wwwgroup	= $group ? $group['name'] : false;
		}

		if (!$wwwuser) {
			$wwwuser = 'nobody (or the user account the web server is running under)';
		}
		if (!$wwwgroup) {
			$wwwgroup = 'nobody (or the group account the web server is running under)';
		}
     
		static $dirs = array(
			'backups',
			'dump',
			'img/wiki',
			'img/wiki_up',
			'modules/cache',
			'temp',
			'templates_c', 
		);
		
		foreach ($dirs as $dir) {
			if (!is_dir($dir)) {
				$errors .= "The directory '$docroot/$dir' does not exist.\n";
			} else 
			if (!is_writeable($dir)) {
				$errors .= "The directory '$docroot/$dir' is not writeable by $wwwuser.\n";
			}
		}
		
		if ($errors) {
			print "
<pre>
Your tiki is not properly set up:

$errors
";

                        if (!TikiSetup::isWindows()) {
                          print "
To set up your tiki, log in to the system running tiki,
and type the following commands:

\$ bash
\$ cd $docroot
\$ chmod +x setup.sh
\$ su -c './setup.sh $wwwuser'

or if you can't become root, but are a member of the group $wwwgroup:

\$ bash
\$ cd $docroot
\$ chmod +x setup.sh
\$ ./setup.sh mylogin $wwwgroup

If you have problems accessing a directory, check open_basedir entry in php.ini or apache.conf.

Once you have executed these commands, this message will disappear!

	";
                        }
                        exit;
		}
	}
}

TikiSetup::check();

$tmpDir = TikiSetup::tempdir();

class timer
        {
        function parseMicro($micro)
                {list($micro,$sec)=explode(' ',microtime()); return $sec+$micro;}
        function start($timer='default')
                {$this->timer[$timer]=$this->parseMicro(microtime());}
        function stop($timer='default')
                {return $this->current($timer);}
{'fraction_non_alphanumeric': 0.1663950214846644, 'fraction_numerical': 0.001185360794191732, 'mean_word_length': 2.8135593220338984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 28, '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': '454752', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2346, 'n_words': 604}