OSDN Git Service

BugTrack/2392 Fix encoding: die_message() outputs suitable charset
[pukiwiki/pukiwiki.git] / lib / func.php
index a0937f3..bcfe2e3 100644 (file)
@@ -293,6 +293,16 @@ function arg_check($str)
        return isset($vars['cmd']) && (strpos($vars['cmd'], $str) === 0);
 }
 
+function _pagename_urlencode_callback($matches)
+{
+       return rawurlencode($matches[0]);
+}
+
+function pagename_urlencode($page)
+{
+       return preg_replace_callback('|[^/:]+|', '_pagename_urlencode_callback', $page);
+}
+
 // Encode page-name
 function encode($str)
 {
@@ -335,7 +345,7 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
        global $_msg_symbol, $_msg_other;
        global $pagereading_enable;
 
-       // ¥½¡¼¥È¥­¡¼¤ò·èÄꤹ¤ë¡£ ' ' < '[a-zA-Z]' < 'zz'¤È¤¤¤¦Á°Äó¡£
+       // ソートキーを決定する。 ' ' < '[a-zA-Z]' < 'zz'という前提。
        $symbol = ' ';
        $other = 'zz';
 
@@ -356,7 +366,7 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
        }
 
        foreach($pages as $file=>$page) {
-               $r_page  = rawurlencode($page);
+               $r_page  = pagename_urlencode($page);
                $s_page  = htmlsc($page, ENT_QUOTES);
                $passage = get_pg_passage($page);
 
@@ -374,9 +384,9 @@ function page_list($pages, $cmd = 'read', $withfilename = FALSE)
                if($pagereading_enable) {
                        if(mb_ereg('^([A-Za-z])', mb_convert_kana($page, 'a'), $matches)) {
                                $head = $matches[1];
-                       } elseif (isset($readings[$page]) && mb_ereg('^([¥¡-¥ö])', $readings[$page], $matches)) { // here
+                       } elseif (isset($readings[$page]) && mb_ereg('^([ァ-ヶ])', $readings[$page], $matches)) { // here
                                $head = $matches[1];
-                       } elseif (mb_ereg('^[ -~]|[^¤¡-¤ó°¡-ô¦]', $page)) { // and here
+                       } elseif (mb_ereg('^[ -~]|[^ぁ-ん亜-熙]', $page)) { // and here
                                $head = $symbol;
                        } else {
                                $head = $other;
@@ -452,13 +462,17 @@ EOD;
        if(defined('SKIN_FILE') && file_exists(SKIN_FILE) && is_readable(SKIN_FILE)) {
                catbody($title, $page, $body);
        } else {
-               header('Content-Type: text/html; charset=euc-jp');
+               $charset = 'utf-8';
+               if(defined('CONTENT_CHARSET')) {
+                       $charset = CONTENT_CHARSET;
+               }
+               header("Content-Type: text/html; charset=$charset");
                print <<<EOD
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!DOCTYPE html>
 <html>
  <head>
+  <meta http-equiv="content-type" content="text/html; charset=$charset">
   <title>$title</title>
-  <meta http-equiv="content-type" content="text/html; charset=euc-jp">
  </head>
  <body>
  $body
@@ -537,7 +551,7 @@ function get_autolink_pattern(& $pages)
 {
        global $WikiName, $autolink, $nowikiname;
 
-       $config = &new Config('AutoLink');
+       $config = new Config('AutoLink');
        $config->read();
        $ignorepages      = $config->get('IgnoreList');
        $forceignorepages = $config->get('ForceIgnoreList');
@@ -610,13 +624,13 @@ function get_script_uri($init_uri = '')
                $script .= SERVER_NAME; // host
                $script .= (SERVER_PORT == 80 ? '' : ':' . SERVER_PORT);  // port
 
-               // SCRIPT_NAME ¤¬'/'¤Ç»Ï¤Þ¤Ã¤Æ¤¤¤Ê¤¤¾ì¹ç(cgi¤Ê¤É) REQUEST_URI¤ò»È¤Ã¤Æ¤ß¤ë
+               // SCRIPT_NAME が'/'で始まっていない場合(cgiなど) REQUEST_URIを使ってみる
                $path    = SCRIPT_NAME;
                if ($path{0} != '/') {
                        if (! isset($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI']{0} != '/')
                                die_message($msg);
 
-                       // REQUEST_URI¤ò¥Ñ¡¼¥¹¤·¡¢pathÉôʬ¤À¤±¤ò¼è¤ê½Ð¤¹
+                       // REQUEST_URIをパースし、path部分だけを取り出す
                        $parse_url = parse_url($script . $_SERVER['REQUEST_URI']);
                        if (! isset($parse_url['path']) || $parse_url['path']{0} != '/')
                                die_message($msg);
@@ -655,8 +669,8 @@ function get_script_uri($init_uri = '')
 // [PHP-users 12736] null byte attack
 // http://ns1.php.gr.jp/pipermail/php-users/2003-January/012742.html
 //
-// 2003-05-16: magic quotes gpc¤ÎÉü¸µ½èÍý¤òÅý¹ç
-// 2003-05-21: Ï¢ÁÛÇÛÎó¤Î¥­¡¼¤Ïbinary safe
+// 2003-05-16: magic quotes gpcの復元処理を統合
+// 2003-05-21: 連想配列のキーはbinary safe
 //
 function input_filter($param)
 {
@@ -703,7 +717,7 @@ function csv_implode($glue, $pieces)
        $_glue = ($glue != '') ? '\\' . $glue{0} : '';
        $arr = array();
        foreach ($pieces as $str) {
-               if (ereg('[' . $_glue . '"' . "\n\r" . ']', $str))
+               if (preg_match('/[' . '"' . "\n\r" . $_glue . ']/', $str))
                        $str = '"' . str_replace('"', '""', $str) . '"';
                $arr[] = $str;
        }
@@ -774,4 +788,4 @@ if (! function_exists('sha1')) {
                }
        }
 }
-?>
+