<?php
-/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
+// $Id: init.php,v 1.25 2005/01/31 15:04:21 henoheno Exp $
//
-// $Id: init.php,v 1.7 2004/09/04 03:01:39 henoheno Exp $
-//
-
-// ½é´üÀßÄê (¥¨¥é¡¼½ÐÎÏ¥ì¥Ù¥ë)
-error_reporting(E_ERROR | E_PARSE); // (E_WARNING | E_NOTICE)¤ò½ü³°¤·¤Æ¤¤¤Þ¤¹
-//error_reporting(E_ALL);
+// Init PukiWiki here
-/////////////////////////////////////////////////
-// ½é´üÀßÄê (ʸ»ú¥¨¥ó¥³¡¼¥É¡¢¸À¸ì)
-define('LANG', 'ja'); // Select 'ja' or 'en'
-define('SOURCE_ENCODING', 'EUC-JP');
-
-// mbstring extension ´ØÏ¢
-mb_language('Japanese');
-mb_internal_encoding(SOURCE_ENCODING);
-ini_set('mbstring.http_input', 'pass');
-mb_http_output('pass');
-mb_detect_order('auto');
-
-/////////////////////////////////////////////////
-// ½é´üÀßÄê(ÀßÄê¥Õ¥¡¥¤¥ë¤Î¾ì½ê)
-define('LANG_FILE', DATA_HOME . LANG . '.lng');
-define('INI_FILE', DATA_HOME . 'pukiwiki.ini.php');
+// PukiWiki version / Copyright / Licence
-/////////////////////////////////////////////////
-// ¥Ð¡¼¥¸¥ç¥ó / Ãøºî¸¢
-define('S_VERSION', '1.4.4');
+define('S_VERSION', '1.4.5');
define('S_COPYRIGHT',
'<strong>PukiWiki ' . S_VERSION . '</strong>' .
- ' Copyright © 2001-2004' .
- ' <a href="http://pukiwiki.org">PukiWiki Developers Team</a>.' .
+ ' Copyright © 2001-2005' .
+ ' <a href="http://pukiwiki.org/">PukiWiki Developers Team</a>.' .
' License is <a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.<br />' .
' Based on "PukiWiki" 1.3 by <a href="http://factage.com/yu-ji/">yu-ji</a>'
);
/////////////////////////////////////////////////
-// ½é´üÀßÄê (¥µ¡¼¥ÐÊÑ¿ô)
+// Init server variables
+
foreach (array('SCRIPT_NAME', 'SERVER_ADMIN', 'SERVER_NAME',
'SERVER_PORT', 'SERVER_SOFTWARE') as $key) {
define($key, isset($_SERVER[$key]) ? $_SERVER[$key] : '');
}
/////////////////////////////////////////////////
-// ½é´üÀßÄê (¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
+// Init grobal variables
-$foot_explain = array(); // µÓÃí
-$related = array(); // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
-$head_tags = array(); // <head>Æâ¤ËÄɲ乤륿¥°
+$foot_explain = array(); // Footnotes
+$related = array(); // Related pages
+$head_tags = array(); // XHTML tags in <head></head>
/////////////////////////////////////////////////
-// ½é´üÀßÄê(»þ´Ö)
+// 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 ¤Ë´ð¤Å¤¯¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÀßÄê
+
+switch (LANG){
+case 'en':
+ // Internal content encoding = Output content charset (for skin)
+ define('CONTENT_CHARSET', 'iso-8859-1'); // 'UTF-8', 'iso-8859-1', 'EUC-JP' or ...
+ // mb_language (for mbstring extension)
+ define('MB_LANGUAGE', 'English'); // 'uni'(means UTF-8), 'English', or 'Japanese'
+ // Internal content encoding (for mbstring extension)
+ define('SOURCE_ENCODING', 'ASCII'); // 'UTF-8', 'ASCII', or 'EUC-JP'
+ break;
+
+case 'ja': // EUC-JP
+ define('CONTENT_CHARSET', 'EUC-JP');
+ define('MB_LANGUAGE', 'Japanese');
+ define('SOURCE_ENCODING', 'EUC-JP');
+ 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', 'INI_FILE') as $file){
- if (! file_exists(constant($file)) || ! is_readable(constant($file))) {
- $die = "${die}File is not found. ($file)\n";
+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(constant($file));
+ require_once(constant($langfile));
}
}
-if ($die) { die_message(nl2br("\n\n" . $die)); }
+if ($die) die_message(nl2br("\n\n" . $die));
/////////////////////////////////////////////////
-// INI_FILE: $script: ½é´üÀßÄê
-if (! isset($script) or $script == '') {
- $script = get_script_uri();
- if ($script === FALSE or (php_sapi_name() == 'cgi' and ! is_url($script, TRUE))) {
- die_message('get_script_uri() failed: Please set $script at INI_FILE manually.');
- }
+// 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
}
/////////////////////////////////////////////////
$die = '';
foreach(array('DATA_DIR', 'DIFF_DIR', 'BACKUP_DIR', 'CACHE_DIR') as $dir){
- if (! is_writable(constant($dir))) {
- $die = "${die}Directory is not found or not writable ($dir)\n";
- }
+ 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 (! isset(${$var})) $temp .= '$' . $var . "\n";
}
if ($temp) {
- if ($die) { $die .= "\n"; } // A breath
- $die = "${die}Variable(s) not found: (Maybe the old *.ini.php?)\n" . $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 (! defined($def)) $temp .= $def . "\n";
}
if ($temp) {
- if ($die) { $die .= "\n"; } // A breath
- $die = "${die}Define(s) not found: (Maybe the old *.ini.php?)\n" . $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)); }
+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)); }
+ 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=");
+ if (isset($_GET[$key])) die_message('Sorry, already reserved: ' . $key . '=');
}
// Expire risk
// POST method ¤Ï¾ï¤Ë form ·Ðͳ¤Ê¤Î¤Ç¡¢É¬¤ºÊÑ´¹¤¹¤ë
//
if (isset($_POST['encode_hint']) && $_POST['encode_hint'] != '') {
- // html.php ¤ÎÃæ¤Ç¡¢<form> ¤Ë encode_hint ¤ò»Å¹þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢
+ // do_plugin_xxx() ¤ÎÃæ¤Ç¡¢<form> ¤Ë encode_hint ¤ò»Å¹þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢
// encode_hint ¤òÍѤ¤¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¡£
// Á´ÂΤò¸«¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¤È¡¢µ¡¼ï°Í¸ʸ»ú¤ä¡¢Ì¯¤Ê¥Ð¥¤¥Ê¥ê
// ¥³¡¼¥É¤¬º®Æþ¤·¤¿¾ì¹ç¤Ë¡¢¥³¡¼¥É¸¡½Ð¤Ë¼ºÇÔ¤¹¤ë¶²¤ì¤¬¤¢¤ë¡£
// ¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
$arg = '';
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
- $arg = $_SERVER['QUERY_STRING'];
-} else if (isset($_SERVER['argv']) && count($_SERVER['argv'])) {
- $arg = $_SERVER['argv'][0];
+ $arg = & $_SERVER['QUERY_STRING'];
+} else if (isset($_SERVER['argv']) && ! empty($_SERVER['argv'])) {
+ $arg = & $_SERVER['argv'][0];
+}
+if (PKWK_QUERY_STRING_MAX && strlen($arg) > PKWK_QUERY_STRING_MAX) {
+ // Something nasty attack?
+ pkwk_common_headers();
+ sleep(1); // Fake processing, and/or process other threads
+ echo('Query string too long');
+ exit;
}
$arg = input_filter($arg); // \0 ½üµî
// ÆþÎÏ¥Á¥§¥Ã¥¯: cmd, plugin ¤Îʸ»úÎó¤Ï±Ñ¿ô»ú°Ê³°¤¢¤ê¤¨¤Ê¤¤
foreach(array('cmd', 'plugin') as $var) {
- if (array_key_exists($var, $vars) &&
- ! preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $vars[$var])) {
+ if (isset($vars[$var]) && ! preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $vars[$var]))
unset($get[$var], $post[$var], $vars[$var]);
- }
}
// À°·Á: page, strip_bracket()
$BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)';
// InterWiki
-$InterWikiName = "(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])";
+$InterWikiName = '(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])';
// Ãí¼á
$NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
// ¸½ºß»þ¹ï
$now = format_date(UTIME);
-// skinÆâ¤ÇDTDÀë¸À¤òÀÚ¤êÂؤ¨¤ë¤Î¤Ë»ÈÍÑ¡£paint.inc.phpÂкö
-$html_transitional = FALSE;
-// FALSE:XHTML 1.1
-// TRUE :XHTML 1.0 Transitional
-
// ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
-if ($usefacemark) { $line_rules += $facemark_rules; }
+if ($usefacemark) $line_rules += $facemark_rules;
unset($facemark_rules);
// ¼ÂÂλ²¾È¥Ñ¥¿¡¼¥ó¤ª¤è¤Ó¥·¥¹¥Æ¥à¤Ç»ÈÍѤ¹¤ë¥Ñ¥¿¡¼¥ó¤ò$line_rules¤Ë²Ã¤¨¤ë
$line_rules = array_merge(array(
'&(#[0-9]+|#x[0-9a-f]+|' . $entity_pattern . ');' => '&$1;',
- "\r" => "<br />\n", /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
+ "\r" => '<br />' . "\n", /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
'#related$' => '<del>#related</del>',
'^#contents$' => '<del>#contents</del>'
), $line_rules);