OSDN Git Service

Convert character code of the source code to UTF-8 from EUC-JP
[pukiwiki/pukiwiki.git] / lib / init.php
index 1856be3..8642573 100644 (file)
@@ -58,7 +58,7 @@ if (! file_exists(INI_FILE) || ! is_readable(INI_FILE)) {
 if ($die) die_message(nl2br("\n\n" . $die));
 
 /////////////////////////////////////////////////
-// INI_FILE: LANG ¤Ë´ð¤Å¤¯¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°ÀßÄê
+// INI_FILE: LANG に基づくエンコーディング設定
 
 // MB_LANGUAGE: mb_language (for mbstring extension)
 //   'uni'(means UTF-8), 'English', or 'Japanese'
@@ -71,13 +71,13 @@ if ($die) die_message(nl2br("\n\n" . $die));
 switch (LANG){
 case 'en': define('MB_LANGUAGE', 'English' ); break;
 case 'ja': define('MB_LANGUAGE', 'Japanese'); break;
-//UTF-8:case 'ko': define('MB_LANGUAGE', 'Korean'  ); break;
-//UTF-8:       // See BugTrack2/13 for all hack about Korean support,
-//UTF-8:       // and give us your report!
+case 'ko': define('MB_LANGUAGE', 'Korean'  ); break;
+       // See BugTrack2/13 for all hack about Korean support,
+       // and give us your report!
 default: die_message('No such language "' . LANG . '"'); break;
 }
 
-//UTF-8:define('PKWK_UTF8_ENABLE', 1);
+define('PKWK_UTF8_ENABLE', 1);
 if (defined('PKWK_UTF8_ENABLE')) {
        define('SOURCE_ENCODING', 'UTF-8');
        define('CONTENT_CHARSET', 'UTF-8');
@@ -136,7 +136,7 @@ if (isset($script)) {
 }
 
 /////////////////////////////////////////////////
-// INI_FILE: $agents:  UserAgent¤Î¼±ÊÌ
+// INI_FILE: $agents:  UserAgentの識別
 
 $ua = 'HTTP_USER_AGENT';
 $user_agent = $matches = array();
@@ -169,7 +169,7 @@ define('UA_VERS', isset($user_agent['vers']) ? $user_agent['vers'] : '');
 unset($user_agent);    // Unset after reading UA_INI_FILE
 
 /////////////////////////////////////////////////
-// ¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Á¥§¥Ã¥¯
+// ã\83\87ã\82£ã\83¬ã\82¯ã\83\88ã\83ªã\81®ã\83\81ã\82§ã\83\83ã\82¯
 
 $die = '';
 foreach(array('DATA_DIR', 'DIFF_DIR', 'BACKUP_DIR', 'CACHE_DIR') as $dir){
@@ -177,7 +177,7 @@ foreach(array('DATA_DIR', 'DIFF_DIR', 'BACKUP_DIR', 'CACHE_DIR') as $dir){
                $die .= 'Directory is not found or not writable (' . $dir . ')' . "\n";
 }
 
-// ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÊÑ¿ô¥Á¥§¥Ã¥¯
+// è¨­å®\9aã\83\95ã\82¡ã\82¤ã\83«ã\81®å¤\89æ\95°ã\83\81ã\82§ã\83\83ã\82¯
 $temp = '';
 foreach(array('rss_max', 'page_title', 'note_hr', 'related_link', 'show_passage',
        'rule_related_str', 'load_template_func') as $var){
@@ -201,14 +201,14 @@ if($die) die_message(nl2br("\n\n" . $die));
 unset($die, $temp);
 
 /////////////////////////////////////////////////
-// É¬¿Ü¤Î¥Ú¡¼¥¸¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð¡¢¶õ¤Î¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë
+// 必須のページが存在しなければ、空のファイルを作成する
 
 foreach(array($defaultpage, $whatsnew, $interwiki) as $page){
        if (! is_page($page)) pkwk_touch_file(get_filename($page));
 }
 
 /////////////////////////////////////////////////
-// ³°Éô¤«¤é¤¯¤ëÊÑ¿ô¤Î¥Á¥§¥Ã¥¯
+// å¤\96é\83¨ã\81\8bã\82\89ã\81\8fã\82\8bå¤\89æ\95°ã\81®ã\83\81ã\82§ã\83\83ã\82¯
 
 // Prohibit $_GET attack
 foreach (array('msg', 'pass') as $key) {
@@ -224,49 +224,49 @@ $_GET    = input_filter($_GET);
 $_POST   = input_filter($_POST);
 $_COOKIE = input_filter($_COOKIE);
 
-// Ê¸»ú¥³¡¼¥ÉÊÑ´¹ ($_POST)
-// <form> ¤ÇÁ÷¿®¤µ¤ì¤¿Ê¸»ú (¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤¿¥Ç¡¼¥¿) ¤Î¥³¡¼¥É¤òÊÑ´¹
-// POST method ¤Ï¾ï¤Ë form ·Ðͳ¤Ê¤Î¤Ç¡¢É¬¤ºÊÑ´¹¤¹¤ë
+// 文字コード変換 ($_POST)
+// <form> で送信された文字 (ブラウザがエンコードしたデータ) のコードを変換
+// POST method は常に form 経由なので、必ず変換する
 //
 if (isset($_POST['encode_hint']) && $_POST['encode_hint'] != '') {
-       // do_plugin_xxx() ¤ÎÃæ¤Ç¡¢<form> ¤Ë encode_hint ¤ò»Å¹þ¤ó¤Ç¤¤¤ë¤Î¤Ç¡¢
-       // encode_hint ¤òÍѤ¤¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¡£
-       // Á´ÂΤò¸«¤Æ¥³¡¼¥É¸¡½Ð¤¹¤ë¤È¡¢µ¡¼ï°Í¸ʸ»ú¤ä¡¢Ì¯¤Ê¥Ð¥¤¥Ê¥ê
-       // ¥³¡¼¥É¤¬º®Æþ¤·¤¿¾ì¹ç¤Ë¡¢¥³¡¼¥É¸¡½Ð¤Ë¼ºÇÔ¤¹¤ë¶²¤ì¤¬¤¢¤ë¡£
+       // do_plugin_xxx() の中で、<form> に encode_hint を仕込んでいるので、
+       // encode_hint を用いてコード検出する。
+       // 全体を見てコード検出すると、機種依存文字や、妙なバイナリ
+       // コードが混入した場合に、コード検出に失敗する恐れがある。
        $encode = mb_detect_encoding($_POST['encode_hint']);
        mb_convert_variables(SOURCE_ENCODING, $encode, $_POST);
 
 } else if (isset($_POST['charset']) && $_POST['charset'] != '') {
-       // TrackBack Ping ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¤³¤È¤¬¤¢¤ë
-       // ¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¾ì¹ç¤Ï¼«Æ°¸¡½Ð¤ËÀÚ¤êÂؤ¨
+       // TrackBack Ping で指定されていることがある
+       // うまくいかない場合は自動検出に切り替え
        if (mb_convert_variables(SOURCE_ENCODING,
            $_POST['charset'], $_POST) !== $_POST['charset']) {
                mb_convert_variables(SOURCE_ENCODING, 'auto', $_POST);
        }
 
 } else if (! empty($_POST)) {
-       // Á´Éô¤Þ¤È¤á¤Æ¡¢¼«Æ°¸¡½Ð¡¿ÊÑ´¹
+       // 全部まとめて、自動検出/変換
        mb_convert_variables(SOURCE_ENCODING, 'auto', $_POST);
 }
 
-// Ê¸»ú¥³¡¼¥ÉÊÑ´¹ ($_GET)
-// GET method ¤Ï form ¤«¤é¤Î¾ì¹ç¤È¡¢<a href="http://script/?key=value> ¤Î¾ì¹ç¤¬¤¢¤ë
-// <a href...> ¤Î¾ì¹ç¤Ï¡¢¥µ¡¼¥Ð¡¼¤¬ rawurlencode ¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥ÉÊÑ´¹¤ÏÉÔÍ×
+// 文字コード変換 ($_GET)
+// GET method は form からの場合と、<a href="http://script/?key=value> の場合がある
+// <a href...> の場合は、サーバーが rawurlencode しているので、コード変換は不要
 if (isset($_GET['encode_hint']) && $_GET['encode_hint'] != '')
 {
-       // form ·Ðͳ¤Î¾ì¹ç¤Ï¡¢¥Ö¥é¥¦¥¶¤¬¥¨¥ó¥³¡¼¥É¤·¤Æ¤¤¤ë¤Î¤Ç¡¢¥³¡¼¥É¸¡½Ð¡¦ÊÑ´¹¤¬É¬Íס£
-       // encode_hint ¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤Ï¤º¤Ê¤Î¤Ç¡¢¤½¤ì¤ò¸«¤Æ¡¢¥³¡¼¥É¸¡½Ð¤·¤¿¸å¡¢ÊÑ´¹¤¹¤ë¡£
-       // Íýͳ¤Ï¡¢post ¤ÈƱÍÍ
+       // form 経由の場合は、ブラウザがエンコードしているので、コード検出・変換が必要。
+       // encode_hint が含まれているはずなので、それを見て、コード検出した後、変換する。
+       // 理由は、post と同様
        $encode = mb_detect_encoding($_GET['encode_hint']);
        mb_convert_variables(SOURCE_ENCODING, $encode, $_GET);
 }
 
 
 /////////////////////////////////////////////////
-// QUERY_STRING¤ò¼èÆÀ
+// QUERY_STRINGを取得
 
-// cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò
-// ¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
+// cmdもpluginも指定されていない場合は、QUERY_STRINGを
+// ページ名かInterWikiNameであるとみなす
 $arg = '';
 if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
        $arg = & $_SERVER['QUERY_STRING'];
@@ -280,7 +280,7 @@ if (PKWK_QUERY_STRING_MAX && strlen($arg) > PKWK_QUERY_STRING_MAX) {
        echo('Query string too long');
        exit;
 }
-$arg = input_filter($arg); // \0 ½üµî
+$arg = input_filter($arg); // \0 除去
 
 // unset QUERY_STRINGs
 foreach (array('QUERY_STRING', 'argv', 'argc') as $key) {
@@ -289,15 +289,15 @@ foreach (array('QUERY_STRING', 'argv', 'argc') as $key) {
 // $_SERVER['REQUEST_URI'] is used at func.php NOW
 unset($REQUEST_URI, $HTTP_SERVER_VARS['REQUEST_URI']);
 
-// mb_convert_variables¤Î¥Ð¥°(?)Âкö: ÇÛÎó¤ÇÅϤµ¤Ê¤¤¤ÈÍî¤Á¤ë
+// mb_convert_variablesのバグ(?)対策: 配列で渡さないと落ちる
 $arg = array($arg);
 mb_convert_variables(SOURCE_ENCODING, 'auto', $arg);
 $arg = $arg[0];
 
 /////////////////////////////////////////////////
-// QUERY_STRING¤òʬ²ò¤·¤Æ¥³¡¼¥ÉÊÑ´¹¤·¡¢$_GET ¤Ë¾å½ñ¤­
+// QUERY_STRINGを分解してコード変換し、$_GET に上書き
 
-// URI ¤ò urlencode ¤»¤º¤ËÆþÎϤ·¤¿¾ì¹ç¤ËÂн褹¤ë
+// URI を urlencode せずに入力した場合に対処する
 $matches = array();
 foreach (explode('&', $arg) as $key_and_value) {
        if (preg_match('/^([^=]+)=(.+)/', $key_and_value, $matches) &&
@@ -323,35 +323,35 @@ if (empty($_POST)) {
        $vars = array_merge($_GET, $_POST); // Considered reliable than $_REQUEST
 }
 
-// ÆþÎÏ¥Á¥§¥Ã¥¯: 'cmd=' and 'plugin=' can't live together
+// å\85¥å\8a\9bã\83\81ã\82§ã\83\83ã\82¯: 'cmd=' and 'plugin=' can't live together
 if (isset($vars['cmd']) && isset($vars['plugin']))
        die('Using both cmd= and plugin= is not allowed');
 
-// ÆþÎÏ¥Á¥§¥Ã¥¯: cmd, plugin ¤Îʸ»úÎó¤Ï±Ñ¿ô»ú°Ê³°¤¢¤ê¤¨¤Ê¤¤
+// 入力チェック: cmd, plugin の文字列は英数字以外ありえない
 foreach(array('cmd', 'plugin') as $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()
+// 整形: page, strip_bracket()
 if (isset($vars['page'])) {
        $get['page'] = $post['page'] = $vars['page']  = strip_bracket($vars['page']);
 } else {
        $get['page'] = $post['page'] = $vars['page'] = '';
 }
 
-// À°·Á: msg, ²þ¹Ô¤ò¼è¤ê½ü¤¯
+// 整形: msg, 改行を取り除く
 if (isset($vars['msg'])) {
        $get['msg'] = $post['msg'] = $vars['msg'] = str_replace("\r", '', $vars['msg']);
 }
 
-// ¸åÊý¸ß´¹À­ (?md5=...)
+// 後方互換性 (?md5=...)
 if (isset($get['md5']) && $get['md5'] != '' &&
     ! isset($vars['cmd']) && ! isset($vars['plugin'])) {
        $get['cmd'] = $post['cmd'] = $vars['cmd'] = 'md5';
 }
 
-// cmd¤âplugin¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢QUERY_STRING¤ò¥Ú¡¼¥¸Ì¾¤«InterWikiName¤Ç¤¢¤ë¤È¤ß¤Ê¤¹
+// cmdもpluginも指定されていない場合は、QUERY_STRINGをページ名かInterWikiNameであるとみなす
 if (! isset($vars['cmd']) && ! isset($vars['plugin'])) {
 
        $get['cmd']  = $post['cmd']  = $vars['cmd']  = 'read';
@@ -364,13 +364,13 @@ if (! isset($vars['cmd']) && ! isset($vars['plugin'])) {
 }
 
 /////////////////////////////////////////////////
-// ½é´üÀßÄê($WikiName,$BracketName¤Ê¤É)
+// 初期設定($WikiName,$BracketNameなど)
 // $WikiName = '[A-Z][a-z]+(?:[A-Z][a-z]+)+';
 // $WikiName = '\b[A-Z][a-z]+(?:[A-Z][a-z]+)+\b';
 // $WikiName = '(?<![[:alnum:]])(?:[[:upper:]][[:lower:]]+){2,}(?![[:alnum:]])';
 // $WikiName = '(?<!\w)(?:[A-Z][a-z]+){2,}(?!\w)';
 
-// BugTrack/304»ÃÄêÂнè
+// BugTrack/304暫定対処
 $WikiName = '(?:[A-Z][a-z]+){2,}(?!\w)';
 
 // $BracketName = ':?[^\s\]#&<>":]+:?';
@@ -379,34 +379,34 @@ $BracketName = '(?!\s):?[^\r\n\t\f\[\]<>#&":]+:?(?<!\s)';
 // InterWiki
 $InterWikiName = '(\[\[)?((?:(?!\s|:|\]\]).)+):(.+)(?(1)\]\])';
 
-// Ãí¼á
+// 注釈
 $NotePattern = '/\(\(((?:(?>(?:(?!\(\()(?!\)\)(?:[^\)]|$)).)+)|(?R))*)\)\)/ex';
 
 /////////////////////////////////////////////////
-// ½é´üÀßÄê(¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ëÆɤ߹þ¤ß)
+// 初期設定(ユーザ定義ルール読み込み)
 require(DATA_HOME . 'rules.ini.php');
 
 /////////////////////////////////////////////////
-// ½é´üÀßÄê(¤½¤Î¾¤Î¥°¥í¡¼¥Ð¥ëÊÑ¿ô)
+// 初期設定(その他のグローバル変数)
 
-// ¸½ºß»þ¹ï
+// 現在時刻
 $now = format_date(UTIME);
 
-// Æü»þÃÖ´¹¥ë¡¼¥ë¤ò$line_rules¤Ë²Ã¤¨¤ë
+// 日時置換ルールを$line_rulesに加える
 if ($usedatetime) $line_rules += $datetime_rules;
 unset($datetime_rules);
 
-// ¥Õ¥§¥¤¥¹¥Þ¡¼¥¯¤ò$line_rules¤Ë²Ã¤¨¤ë
+// フェイスマークを$line_rulesに加える
 if ($usefacemark) $line_rules += $facemark_rules;
 unset($facemark_rules);
 
-// ¼ÂÂλ²¾È¥Ñ¥¿¡¼¥ó¤ª¤è¤Ó¥·¥¹¥Æ¥à¤Ç»ÈÍѤ¹¤ë¥Ñ¥¿¡¼¥ó¤ò$line_rules¤Ë²Ã¤¨¤ë
+// 実体参照パターンおよびシステムで使用するパターンを$line_rulesに加える
 //$entity_pattern = '[a-zA-Z0-9]{2,8}';
 $entity_pattern = trim(join('', file(CACHE_DIR . 'entities.dat')));
 
 $line_rules = array_merge(array(
        '&amp;(#[0-9]+|#x[0-9a-f]+|' . $entity_pattern . ');' => '&$1;',
-       "\r"          => '<br />' . "\n",       /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
+       "\r"          => '<br />' . "\n",       /* 行末にチルダは改行 */
 ), $line_rules);
 
 ?>