PukiWiki ' . S_VERSION . '' .
' Copyright © 2001-2005' .
' PukiWiki Developers Team.' .
' License is GPL.
' .
' Based on "PukiWiki" 1.3 by yu-ji'
);
/////////////////////////////////////////////////
// Init server variables
foreach (array('SCRIPT_NAME', 'SERVER_ADMIN', 'SERVER_NAME',
'SERVER_PORT', 'SERVER_SOFTWARE') as $key) {
define($key, isset($_SERVER[$key]) ? $_SERVER[$key] : '');
unset(${$key}, $_SERVER[$key], $HTTP_SERVER_VARS[$key]);
}
/////////////////////////////////////////////////
// Init grobal variables
$foot_explain = array(); // Footnotes
$related = array(); // Related pages
$head_tags = array(); // XHTML tags in
/////////////////////////////////////////////////
// Time settings
define('LOCALZONE', date('Z'));
define('UTIME', time() - LOCALZONE);
define('MUTIME', getmicrotime());
/////////////////////////////////////////////////
// Require INI_FILE
define('INI_FILE', DATA_HOME . 'pukiwiki.ini.php');
$die = '';
if (! file_exists(INI_FILE) || ! is_readable(INI_FILE)) {
$die .= 'File is not found. (INI_FILE)' . "\n";
} else {
require(INI_FILE);
}
if ($die) die_message(nl2br("\n\n" . $die));
/////////////////////////////////////////////////
// INI_FILE: LANG に基づくエンコーディング設定
// CONTENT_CHARSET: Internal content encoding = Output content charset (for skin)
// 'UTF-8', 'iso-8859-1', 'EUC-JP' or ...
// MB_LANGUAGE: mb_language (for mbstring extension)
// 'uni'(means UTF-8), 'English', or 'Japanese'
// SOURCE_ENCODING: Internal content encoding (for mbstring extension)
// 'UTF-8', 'ASCII', or 'EUC-JP'
switch (LANG){
case 'en':
// ASCII
define('CONTENT_CHARSET', 'iso-8859-1');
define('MB_LANGUAGE', 'English');
define('SOURCE_ENCODING', 'ASCII');
// UTF-8
//define('CONTENT_CHARSET', 'UTF-8');
//define('MB_LANGUAGE', 'English');
//define('SOURCE_ENCODING', 'UTF-8');
break;
case 'ja':
// EUC-JP
define('CONTENT_CHARSET', 'EUC-JP');
define('MB_LANGUAGE', 'Japanese');
define('SOURCE_ENCODING', 'EUC-JP');
break;
case 'ko':
// UTF-8 (See BugTrack2/13 for all hack about Korean support, and give us your report!)
define('CONTENT_CHARSET', 'UTF-8');
define('MB_LANGUAGE', 'Korean');
define('SOURCE_ENCODING', 'UTF-8');
break;
default:
die_message('No such language "' . LANG . '"');
}
mb_language(MB_LANGUAGE);
mb_internal_encoding(SOURCE_ENCODING);
ini_set('mbstring.http_input', 'pass');
mb_http_output('pass');
mb_detect_order('auto');
/////////////////////////////////////////////////
// INI_FILE: Require LANG_FILE
define('LANG_FILE_HINT', DATA_HOME . LANG . '.lng.php'); // For encoding hint
define('LANG_FILE', DATA_HOME . UI_LANG . '.lng.php'); // For UI resource
$die = '';
foreach (array('LANG_FILE_HINT', 'LANG_FILE') as $langfile) {
if (! file_exists(constant($langfile)) || ! is_readable(constant($langfile))) {
$die .= 'File is not found or not readable. (' . $langfile . ')' . "\n";
} else {
require_once(constant($langfile));
}
}
if ($die) die_message(nl2br("\n\n" . $die));
/////////////////////////////////////////////////
// LANG_FILE: Init encoding hint
define('PKWK_ENCODING_HINT', isset($_LANG['encode_hint'][LANG]) ? $_LANG['encode_hint'][LANG] : '');
unset($_LANG['encode_hint']);
/////////////////////////////////////////////////
// LANG_FILE: Init severn days of the week
$weeklabels = $_msg_week;
/////////////////////////////////////////////////
// INI_FILE: Init $script
if (isset($script)) {
get_script_uri($script); // Init manually
} else {
$script = get_script_uri(); // Init automatically
}
/////////////////////////////////////////////////
// INI_FILE: $agents: UserAgentの識別
$ua = 'HTTP_USER_AGENT';
$user_agent = $matches = array();
$user_agent['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
unset(${$ua}, $_SERVER[$ua], $HTTP_SERVER_VARS[$ua], $ua); // safety
foreach ($agents as $agent) {
if (preg_match($agent['pattern'], $user_agent['agent'], $matches)) {
$user_agent['profile'] = isset($agent['profile']) ? $agent['profile'] : '';
$user_agent['name'] = isset($matches[1]) ? $matches[1] : ''; // device or browser name
$user_agent['vers'] = isset($matches[2]) ? $matches[2] : ''; // 's version
break;
}
}
unset($agents, $matches);
// Profile-related init and setting
define('UA_PROFILE', isset($user_agent['profile']) ? $user_agent['profile'] : '');
define('UA_INI_FILE', DATA_HOME . UA_PROFILE . '.ini.php');
if (! file_exists(UA_INI_FILE) || ! is_readable(UA_INI_FILE)) {
die_message('UA_INI_FILE for "' . UA_PROFILE . '" not found.');
} else {
require(UA_INI_FILE); // Also manually
}
define('UA_NAME', isset($user_agent['name']) ? $user_agent['name'] : '');
define('UA_VERS', isset($user_agent['vers']) ? $user_agent['vers'] : '');
unset($user_agent); // Unset after reading UA_INI_FILE
/////////////////////////////////////////////////
// ディレクトリのチェック
$die = '';
foreach(array('DATA_DIR', 'DIFF_DIR', 'BACKUP_DIR', 'CACHE_DIR') as $dir){
if (! is_writable(constant($dir)))
$die .= 'Directory is not found or not writable (' . $dir . ')' . "\n";
}
// 設定ファイルの変数チェック
$temp = '';
foreach(array('rss_max', 'page_title', 'note_hr', 'related_link', 'show_passage',
'rule_related_str', 'load_template_func') as $var){
if (! isset(${$var})) $temp .= '$' . $var . "\n";
}
if ($temp) {
if ($die) $die .= "\n"; // A breath
$die .= 'Variable(s) not found: (Maybe the old *.ini.php?)' . "\n" . $temp;
}
$temp = '';
foreach(array('LANG', 'PLUGIN_DIR') as $def){
if (! defined($def)) $temp .= $def . "\n";
}
if ($temp) {
if ($die) $die .= "\n"; // A breath
$die .= 'Define(s) not found: (Maybe the old *.ini.php?)' . "\n" . $temp;
}
if($die) die_message(nl2br("\n\n" . $die));
unset($die, $temp);
/////////////////////////////////////////////////
// 必須のページが存在しなければ、空のファイルを作成する
foreach(array($defaultpage, $whatsnew, $interwiki) as $page){
if (! is_page($page)) touch(get_filename($page));
}
/////////////////////////////////////////////////
// 外部からくる変数のチェック
// Prohibit $_GET attack
foreach (array('msg', 'pass') as $key) {
if (isset($_GET[$key])) die_message('Sorry, already reserved: ' . $key . '=');
}
// Expire risk
unset($HTTP_GET_VARS, $HTTP_POST_VARS); //, 'SERVER', 'ENV', 'SESSION', ...
unset($_REQUEST); // Considered harmful
// Remove null character etc.
$_GET = input_filter($_GET);
$_POST = input_filter($_POST);
$_COOKIE = input_filter($_COOKIE);
// 文字コード変換 ($_POST)
//